我尝试使用批处理文件将Microsoft Edge固定/取消固定到我的任务栏。我有几百台计算机要这样做,所以我试图制作一个批处理/ powershell / vbscript,它将从任务栏取消所有Edge的实例,然后将一个单个实例固定回任务栏,我可以肯定它仅固定一次。有人能指出我正确的方向吗?
答案 0 :(得分:0)
这个答案来自: https://azure.microsoft.com/en-us/documentation/articles/storage-table-design-guide/#overview
我测试了针脚IE,它可以工作:
# The apps array holds hash tables with information about each app that should be pinned.
# Each hash table has the name of the app, two byte arrays and some strings with various settings
# for the app's shortcut. The registryEntry byte array contains all the bytes that need to be
# inserted into the Favorites registry key, while the matchString byte array is used to check
# if the app is already pinned. # # If you accidentally end up pinning an app that was already pinned, the existing taskbar
# entry will likely break. For that reason, matchString should be a subset of registryEntry # that you are certain will not change between computers or versions of the app.
Cls
$apps = @( @{ "appName" = "Microsoft Internet Explorer"
"registryEntry" = @(0,170,1,0,0,58,0,31,128,200,39,52,31,16,92,16,66,170,3,46,228,82,135,214,104,38,0,1,0,37,0,239,190,18,0,0,0,118,241,189,129,21,120,209,1,16,214,92,131,21,120,209,1,16,214,92,131,21,120,209,1,20,0,86,0,49,0,0,0,0,0,182,72,114,151,17,0,84,97,115,107,66,97,114,0,64,0,9,0,4,0,239,190,103,72,105,16,182,72,114,151,46,0,0,0,147,77,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,154,101,231,0,84,0,97,0,115,0,107,0,66,0,97,0,114,0,0,0,22,0,24,1,50,0,43,5,0,0,103,72,103,16,32,0,73,78,84,69,82,78,126,49,46,76,78,75,0,0,170,0,9,0,4,0,239,190,176,72,131,85,182,72,114,151,46,0,0,0,143,221,1,0,0,0,7,0,0,0,0,0,0,0,0,0,90,0,0,0,0,0,156,250,31,0,73,0,110,0,116,0,101,0,114,0,110,0,101,0,116,0,32,0,69,0,120,0,112,0,108,0,111,0,114,0,101,0,114,0,46,0,108,0,110,0,107,0,0,0,64,0,67,0,58,0,92,0,87,0,105,0,110,0,100,0,111,0,119,0,115,0,92,0,83,0,121,0,115,0,116,0,101,0,109,0,51,0,50,0,92,0,105,0,101,0,52,0,117,0,105,0,110,0,105,0,116,0,46,0,101,0,120,0,101,0,44,0,45,0,55,0,51,0,49,0,0,0,28,0,82,0,0,0,29,0,239,190,2,0,77,0,105,0,99,0,114,0,111,0,115,0,111,0,102,0,116,0,46,0,73,0,110,0,116,0,101,0,114,0,110,0,101,0,116,0,69,0,120,0,112,0,108,0,111,0,114,0,101,0,114,0,46,0,68,0,101,0,102,0,97,0,117,0,108,0,116,0,0,0,28,0,0,0)
"matchString" = @(77,0,105,0,99,0,114,0,111,0,115,0,111,0,102,0,116,0,46,0,73,0,110,0,116,0,101,0,114,0,110,0,101,0,116,0,69,0,120,0,112,0,108,0,111,0,114,0,101,0,114,0,46,0,68,0,101,0,102,0,97,0,117,0,108,0,116)
"shortcutPath" = "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Internet Explorer.lnk"
"shortcutWildcardPath" = "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Internet Explorer*.lnk"
"shortcutTargetPath" = "C:\Program Files\Internet Explorer\iexplore.exe"
"shortcutWorkingDirectory" = "%HOMEDRIVE%%HOMEPATH%"
} )
# Start with the assumption that no apps are pinned.
$atLeastOneAppWasNotPinned = $false
foreach ($app in $apps)
{
$currentAppWasNotPinned = $true
# Save the current value of the taskbar registry key as a byte array
$currentTaskBar = (Get-ItemProperty -Path "hkcu:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -Name "Favorites").Favorites # Save the last index for the current taskbar array and the matchString array.
$currentTaskBarLastIndex = ($currentTaskBar.Length - 1)
$matchStringLastIndex = ($app["matchString"].Length - 1)
# Used to keep track of the current location in the byte arrays
$matchStringCurrentIndex = 0
$currentTaskBarCurrentIndex = 0
# Loop through the current taskbar array
while ($currentTaskBarCurrentIndex -lt $currentTaskBarLastIndex)
{
if ($currentTaskBar[$currentTaskBarCurrentIndex] -eq $app["matchString"][$matchStringCurrentIndex])
{
# If the current value of the registry byte array matches the first value of the app byte array,
# we save the current registry byte array index.
$startIndex = $currentTaskBarCurrentIndex
# We then proceed to compare the next item in the registry byte array with the next value in the
# matchString byte array until we no longer get a match, like a greedy regex.
while ($currentTaskBar[$currentTaskBarCurrentIndex] -eq $app["matchString"][$matchStringCurrentIndex])
{
# If we got a match on the entire matchString, the current app is pinned.
if ($matchStringCurrentIndex -eq $matchStringLastIndex)
{
$currentAppWasNotPinned = $false
}
$matchStringCurrentIndex += 1
$currentTaskBarCurrentIndex += 1
}
# Reset the app byte array index counter
$matchStringCurrentIndex = 0
# Move the registry byte array index back to the location of the match that caused us to enter this # if block.
$currentTaskBarCurrentIndex = $startIndex
}
# Step to the next byte in the registry array
$currentTaskBarCurrentIndex += 1
}
if ($currentAppWasNotPinned -or ($currentTaskBarLastIndex -eq 0))
{
$atLeastOneAppWasNotPinned = $true
# For various reasons you could end up having a shortcut in the taskbar directory even if the app # the shortcut points to isn't pinned.
#To make sure that any such shortcuts won't cause us any # issues, remove them.
Remove-Item ((Get-ChildItem Env:APPDATA).Value + $app["shortcutWildcardPath"]) # Create the app's shortcut in the taskbar directory.
$taskbarShortcutPath = (Get-ChildItem Env:APPDATA).Value + $app["shortcutPath"]
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($taskbarShortcutPath)
$Shortcut.TargetPath = $app["shortcutTargetPath"]
$Shortcut.WorkingDirectory = $app["shortcutWildcardPath"]
$Shortcut.Save()
# Add the app's byte array to the current taskbar registry entry.
$taskBar = $app["registryEntry"] + $currentTaskBar
# Overwrite the existing taskbar registry key with the version that has the current app pinned.
New-ItemProperty -Path "hkcu:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Taskband" -Name "Favorites" -Value $taskBar -PropertyType Binary -Force | Out-Null
}
}
if ($atLeastOneAppWasNotPinned)
{
Write-Output "At least one app was not pinned, pinning and restarting explorer.exe to refresh taskbar."
# Restart Explorer to refresh the taskbar
Invoke-Expression "taskkill /f /im explorer.exe"
Invoke-Expression "start explorer.exe"
}
else
{
Write-Output "All apps are pinned."
}