Remove the Google Chrome pinned icon on the taskbar

我的梦境 提交于 2020-01-30 08:30:28

问题


I want to remove the Google Chrome pinned icon on the taskbar. The uninstall does NOT remove the icon. I modified code to remove just the Google Chrome.lnk. What I want to do (knowing about VBS) is to loop through all the user folders not just the current user which is I believe defined as strCurrentUserAppData. The other desire I would like to do with this code is to use it with SCCM to do a clean install of Chrome. I installed the x64 version and need to replace it with the x86 version. When I do the uninstall using the enterprise MSI it leaves the pinned icon. If I use a bat to remove the icon from the directory, the lnk is deleted but there is left a white paper icon on the task bar. So far this is the only code that works on removing the pinned icon.

Option Explicit

Const CSIDL_APPDATA = &H1A

Dim objShell
Dim objFolder
Dim objFolderItem
Dim objVerb
Dim objCurrentUserAppData
Dim strCurrentUserAppData
Set objShell = CreateObject("Shell.Application")
Set objCurrentUserAppData = objShell.NameSpace(CSIDL_APPDATA)
strCurrentUserAppData = objCurrentUserAppData.Self.Path



'===================''==================='
' - Remove All Pinned Items -
'===================''==================='


Set objFolder = objShell.Namespace(strCurrentUserAppData & "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar")


For Each objFolderItem in objFolder.Items
    'WScript.Echo objFolderItem
    If objFolderItem = "Google Chrome" then
        For Each objVerb in objFolderItem.Verbs
            If Replace(objVerb.name, "&", "") = "Unpin from Taskbar" Then objVerb.DoIt
        Next
    End if
Next

The BATCH Code I have run still will not remove the icon even after rebooting.

taskkill /im chrome.exe /f /t
taskkill /im GoogleUpdate.exe /f /t
taskkill /im GoogleCrashHandler.exe /f /t
taskkill /im GoogleCrashHandler64.exe /f /t
taskkill /im GoogleUpdateBroker.exe /f /t
taskkill /im GoogleUpdateHelper.msi /f /t
taskkill /im GoogleUpdateOnDemand.exe /f /t
taskkill /im GoogleUpdateSetup.exe /f /t
taskkill /im chrmstp.exe /f /t

MsiExec.exe /X{3EDA268B-C905-37D1-89DF-7049B39FB069} /q/n

MsiExec.exe /X{6A21C1E8-DAC1-3C18-BCDC-2DBB4B352AD8} /q/n

rem app files
rd "%userprofile%\AppData\Local\Google" /s/q
rd "C:\Users\Default\AppData\Local\Google" /s/q
rd "\Google" /s/q
rd "%PROGRAMFILES%\Google" /s/q
rd "%PROGRAMFILES(X86)%\Google" /s/q

rem desktop shorcuts
del "%PUBLIC%\Desktop\Google Chrome.lnk" /q
del "%userprofile%\Desktop\Google Chrome.lnk" /q

rem start menu folders
rd "%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Google Chrome" /s/q
rd "%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Google Chrome" /s/q

rem pinned items
del "%userprofile%\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\Google Chrome*.lnk" /q
del "%userprofile%\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Google Chrome*.lnk" /q

taskkill /f /im explorer.exe
start explorer.exe

回答1:


Try this hybrid code (Vbscript/PowerShell):

Option Explicit
Dim Title,Ws,ByPassPSFile,AppPath,Example,PSFile,MyCmd,Result,MyArray,MyApp,FolderPath,fso
Title = "UnPin application from Taskbar on Windows 7 by Hackoo"
Set Ws = CreateObject("wscript.Shell")
Set fso = Createobject("Scripting.FileSystemObject")
PSFile = Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & "ps1"
ByPassPSFile = "cmd /k PowerShell.exe -ExecutionPolicy bypass -noprofile -file "
Example = "C:\Program Files\Google\Chrome\Application\Chrome.exe "
AppPath = InputBox("Enter the path of your application in order to unpin it from the taskbar " & vbcr & "Example : " & vbcr & Dblquote(Example) & "",Title,Example)
If AppPath = "" or IsEmpty(AppPath) Then Wscript.Quit()
MyArray = Split(AppPath,"\")
MyApp = MyArray(UBound(MyArray))
FolderPath = fso.GetParentFolderName(AppPath)
MyCmd = "$sa = new-object -c shell.application" & VbCrlF
MyCmd = MyCmd & "$FolderPath = "& DblQuote(FolderPath) & VbCrlF
MyCmd = MyCmd & "$pn = $sa.namespace($FolderPath).parsename('"& MyApp &"')" & VbCrlF
MyCmd = MyCmd & "$pn.invokeverb('taskbarunpin')"
Call WriteMyPSFile(MyCmd)
Result = Ws.run(ByPassPSFile & PSFile,1,True)
'**********************************************************************************************
Sub WriteMyPSFile(strText)
Dim fs,ts,PSFile
Const ForWriting = 2
    PSFile = Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & "ps1"
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set ts = fs.OpenTextFile(PSFile,ForWriting,True)
    ts.WriteLine strText
    ts.Close
End Sub
'**********************************************************************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'**********************************************************************************************

EDIT : 22/06/2015 : UnPinfromTaskBarHiddenConsole.vbs

Option Explicit
Dim Title,Ws,ByPassPSFile,AppPath,Example,PSFile,MyCmd,Result,MyArray,MyApp,FolderPath,fso
Title = "UnPin application from Taskbar on Windows 7 by Hackoo"
Set Ws = CreateObject("wscript.Shell")
Set fso = Createobject("Scripting.FileSystemObject")
PSFile = Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & "ps1"
ByPassPSFile = "cmd /c PowerShell.exe -ExecutionPolicy bypass -noprofile -file "
Example = "C:\Program Files\Google\Chrome\Application\Chrome.exe "
AppPath = InputBox("Enter the path of your application in order to unpin it from the taskbar " & vbcr & "Example : " & vbcr & Dblquote(Example) & "",Title,Example)
If AppPath = "" or IsEmpty(AppPath) Then Wscript.Quit()
MyArray = Split(AppPath,"\")
MyApp = MyArray(UBound(MyArray))
FolderPath = fso.GetParentFolderName(AppPath)
MyCmd = "$sa = new-object -c shell.application" & VbCrlF
MyCmd = MyCmd & "$FolderPath = "& DblQuote(FolderPath) & VbCrlF
MyCmd = MyCmd & "$pn = $sa.namespace($FolderPath).parsename('"& MyApp &"')" & VbCrlF
MyCmd = MyCmd & "$pn.invokeverb('taskbarunpin')"
Call WriteMyPSFile(MyCmd)
Result = Ws.run(ByPassPSFile & PSFile,0,True)
MsgBox "The Unpin of " & DblQuote(MyApp) & " from the taskbar is done !",VbInformation,Title
'**********************************************************************************************
Sub WriteMyPSFile(strText)
Dim fs,ts,PSFile
Const ForWriting = 2
    PSFile = Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & "ps1"
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set ts = fs.OpenTextFile(PSFile,ForWriting,True)
    ts.WriteLine strText
    ts.Close
End Sub
'**********************************************************************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'**********************************************************************************************


来源:https://stackoverflow.com/questions/30920546/remove-the-google-chrome-pinned-icon-on-the-taskbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!