Windows – Unpin File Explorer from the taskbar in Windows 10 via script or batch file

taskbarvbscriptwindows 10

The corporate image being used on my laptop keeps forcing File Explorer to be pinned to my taskbar. I have gone round and round with them about this problem (and others I have had) but am giving up on that front since the other problems are fixed. What I want to try to accomplish as a work around is to create a script that I can run when I log in that will unpin File Explorer from the taskbar for me. I have been all over the internet with various powershell, vbscript and batch files. Most of the scripts work great for any thing pinned to the taskbar EXCEPT File Explorer. Most pinned items are in %AppData%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar and I can see File Explorer there. However all the scripts I see use the verbs of the object and look for an unpin from taskbar command and run it. File Explorer does not have that. I have searched my entire hard drive and cannot file a file with the unpin command for file explorer. If I delete the file and remove the taskband registr in HKCU the item is not longer pinned, but still shows on the taskbar. If I click it, it will crash and the remove itself. If I refresh explorer.exe, the item is pinned to the taskbar again. Any ideas on how to do this?

Best Answer

It should still work with the method used by PinTo10 which is based on this kinda crazy method where you basically rename your own executable to explorer.exe to get the privileges windows has for pinning.

It also seems you have to use a special link and not the normal one but in my tests if you use the one from "C:\ProgramData\Microsoft\Windows\Start Menu Places" it still works.

So that would be:

PinTo10v2.exe /unpintb "C:\ProgramData\Microsoft\Windows\Start Menu Places\01 - File Explorer.lnk"

If you prefer a purely scripted method (should be enough for unpinning just not for pinning) this would be something like

Set wso = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set sho = CreateObject("Shell.Application")

sourcedir = fso.GetFile(WScript.ScriptFullName).ParentFolder
Set folder = sho.Namespace("C:\ProgramData\Microsoft\Windows\Start Menu Places")

For Each item In folder.Items
    If contains(item.Name,"Explorer") Then
        item.InvokeVerb("taskbarunpin")
    End If
Next

' Funktion um zu prüfen ob ein string einen anderen enthält
Function contains(sourceStr, checkStr)  
    contains=InStr(1, sourceStr, checkStr, vbTextCompare) > 0
End Function

(I could not test it with the newest Win 10 builds but so far they did never touch this part since they made it completely intransparent with windows 10)

Related Question