删除任务栏上的Google Chrome固定图标

时间:2015-06-18 16:10:21

标签: batch-file vbscript taskbar

我想删除任务栏上的Google Chrome固定图标。卸载不会删除图标。我修改了代码以仅删除Google Chrome.lnk。我想做的事情(了解VBS)是遍历所有用户文件夹而不仅仅是我认为定义为strCurrentUserAppData的当前用户。我想用这个代码做的另一个愿望就是和SCCM一起使用它来干净安装Chrome。我安装了x64版本,需要将其替换为x86版本。当我使用企业MSI进行卸载时,它会保留固定图标。如果我使用蝙蝠从目录中删除图标,则lnk将被删除,但任务栏上会留下一个白皮书图标。到目前为止,这是唯一可以删除固定图标的代码。

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

即使重启后,我运行的BATCH代码仍然不会删除图标。

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 个答案:

答案 0 :(得分:3)

尝试使用此混合代码(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
'**********************************************************************************************

编辑:2015年6月22日: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
'**********************************************************************************************
相关问题