首页 > 解决方案 > VBscript 无法在 Windows Insider 版本中将项目固定到任务栏

问题描述

我有一个脚本,它将一个项目固定到除 Windows Insider 构建之外的所有操作系统中的任务栏。我将它转换为 Powershell 脚本,它也适用于除 Windows Insider 构建之外的所有操作系统。当我运行它时,我没有收到任何错误消息,在事件查看器中什么也没有。MS 一直在锁定以编程方式将项目固定到“开始”菜单和任务栏的能力。看起来他们在即将发布的版本中走得更远。有没有其他人遇到过这个?这是我正在使用的代码。

Function PinItem(strFolder, strFile)

    Dim ShortcutPath 
    Dim sKey1
    Dim sKey2
    Dim KeyValue

      '----------------------------------------------------------------------
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    ShortcutPath = strFolder & "\" & strFile
    sKey1      = "HKCU\Software\Classes\*\shell\{:}\\"
    sKey2      = Replace(sKey1, "\\", "\ExplorerCommandHandler")
    '----------------------------------------------------------------------
    With WScript.CreateObject("WScript.Shell")
        KeyValue = .RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer" & _
            "\CommandStore\shell\Windows.taskbarpin\ExplorerCommandHandler")

        .RegWrite sKey2, KeyValue, "REG_SZ"

        With WScript.CreateObject("Shell.Application")
            With .Namespace(objFSO.GetParentFolderName(ShortcutPath))
                With .ParseName(objFSO.GetFileName(ShortcutPath))
                    .InvokeVerb("{:}")
                End With
            End With
        End With

        .Run("Reg.exe delete """ & Replace(sKey1, "\\", "") & """ /F"), 0, True
    End With
End Function

标签: powershellvbscript

解决方案


推荐阅读