Vbscript 便签上的FolderItemVerb.DoIt或剪贴工具会导致;找不到指定的文件";

Vbscript 便签上的FolderItemVerb.DoIt或剪贴工具会导致;找不到指定的文件";,vbscript,windows-7-x64,taskbar,Vbscript,Windows 7 X64,Taskbar,使用VBScript尝试将“便笺”或“剪贴工具”快捷方式固定到任务栏,在调用DoIt方法时,我会收到错误消息“系统找不到指定的文件”。但是,如果我锁定了任何其他快捷方式(例如,Caclulator、记事本、Internet Explorer、MS Word),则脚本工作正常 Dim Application, FileSystem, Shell, PinnedFolder, PinnedItem, Verb, Shortcut Set Application = CreateObject("She

使用VBScript尝试将“便笺”或“剪贴工具”快捷方式固定到任务栏,在调用
DoIt
方法时,我会收到错误消息“系统找不到指定的文件”。但是,如果我锁定了任何其他快捷方式(例如,Caclulator、记事本、Internet Explorer、MS Word),则脚本工作正常

Dim Application, FileSystem, Shell, PinnedFolder, PinnedItem, Verb, Shortcut
Set Application = CreateObject("Shell.Application")
Set FileSystem = CreateObject("Scripting.FileSystemObject")
Set Shell = CreateObject("WScript.Shell")
Set Shortcut = FileSystem.GetFile(Shell.ExpandEnvironmentStrings("%ProgramData%\Microsoft\Windows\Start Menu\Programs\Accessories\Sticky Notes.lnk"))
Set PinnedFolder = Application.Namespace(Shortcut.ParentFolder.Path)
Set PinnedItem = PinnedFolder.ParseName(Shortcut.Name)

For Each Verb In PinnedItem.Verbs
    If "Pin to Tas&kbar" = Verb.Name Then
        Verb.DoIt
    End If
Next

例如,如果我将路径更改为
“%ProgramData%\Microsoft\Windows\Start Menu\Programs\Accessories\Calculator.lnk”
,则它不会抛出错误,并且计算器的快捷方式已成功固定到任务栏

我找不到任何理由来解释为什么这只会在这两条捷径上失败。我尝试过重新创建快捷方式,将它们移动到不同的位置,并且我已经验证了双击快捷方式本身是否有效。有没有人知道为什么会发生这种情况,或者有什么我没有尝试过的想法


**编辑**


这已经在另外两台Windows 7 64位PC和一台Windows 7 32位PC上进行了测试。所有这些都成功地固定了便笺应用程序。至少有一台Windows 7 64位电脑和32位电脑的设置、软件和环境与受影响的电脑相同。但问题仍然存在于原始电脑上。

您的代码在我的Windows 7 x64系统上有效。不过,试试这个(对我的也有效)


如果这不起作用,请尝试以管理员身份运行它。

如果我使用
%windir%\system32\stikynot.exe
,则这不起作用。相反,它会在
设置快捷方式…
行中抛出错误。但是,我可以将相同的路径复制并粘贴到“运行”对话框中,并且可以毫无问题地启动便笺。不过,如果我使用
%windir%\system32\notepad.exe
,它仍然可以工作。这似乎是一个特定于计算机的问题。您是否以管理员身份运行(或尝试过)此操作?我已将UAC设置为“从不通知…”,我刚刚在另一台具有相同设置的Windows 7 64位计算机上尝试过此操作,并已成功运行。权限不仅仅针对UAC。。。文件、文件夹、注册表设置。。。这里可能有很多事情在起作用。在完全管理帐户下进行测试排除了很多问题。
Dim Application, FileSystem, Shell, PinnedFolder, PinnedItem, Verb, Shortcut
Set Application = CreateObject("Shell.Application")
Set FileSystem = CreateObject("Scripting.FileSystemObject")
Set Shell = CreateObject("WScript.Shell")
Set Shortcut = FileSystem.GetFile(Shell.ExpandEnvironmentStrings("%windir%\system32\StikyNot.exe"))
Set PinnedFolder = Application.Namespace(Shortcut.ParentFolder.Path)
Set PinnedItem = PinnedFolder.ParseName(Shortcut.Name)

For Each Verb In PinnedItem.Verbs
    If "Pin to Tas&kbar" = Verb.Name Then
        Verb.DoIt
    End If
Next