2012-10-12 40 views
1

使用VBScript試圖將「粘滯便箋」或「截取工具」快捷方式固定到任務欄,我收到錯誤消息「The當我調用DoIt方法時,系統找不到指定的文件。但是,如果我插入任何其他快捷方式(例如Caclulator,記事本,Internet Explorer,MS Word),那麼該腳本完美無缺。FolderItemVerb.DoIt在粘滯便箋或截取工具中導致「無法找到指定的文件」

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"路徑,然後它拋出錯誤,以及計算器快捷方式成功地固定到任務欄。

我找不到任何理由,爲什麼這隻會失敗這兩個快捷方式。我嘗試重新創建快捷方式,將它們移動到不同的位置,並且我已驗證快捷方式在雙擊時可以正常工作。有誰知道爲什麼會發生這種情況,或者有沒有嘗試過的想法?


**編輯* *

這現在已經在兩個額外的64位Windows 7 PC的測試,Windows 7的32位PC。所有這些都成功地固定了粘滯便箋應用程序。至少有一臺Windows 7 64位個人電腦和32位個人電腦與受影響的個人電腦具有相同的設置,軟件和環境。然而,這個問題仍然存在於原來的PC上。

回答

0

您的代碼適用於我的Windows7 x64系統。但是,試試這個(也適用於我的)。

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 

如果這不起作用,請嘗試以管理員身份運行它。

+0

如果我使用'%windir%\ system32 \ stikynot.exe',這不起作用。相反,它會在「Set Shortcut ...」行中拋出錯誤。但是,我可以將相同的路徑複製並粘貼到「運行」對話框中,並且粘滯便箋可以毫無問題地啓動。它可以工作,但如果我使用'%windir%\ system32 \ notepad.exe'。它看起來像這是一個機器特定的問題。 –

+0

你是以管理員身份運行(或者你有沒有試過)? – RLH

+0

我有UAC設置爲「從不通知...」,我只是在另一臺具有相同設置的Windows 7 64位計算機上嘗試了此操作,並且對其進行了處理。 –

相關問題