【发布时间】:2014-04-08 10:02:42
【问题描述】:
我从一个网站上获取了这个脚本。我正在尝试在 Windows 8 上添加任务栏和开始菜单的快捷方式。我的 VBScript 知识很薄弱。我很确定我只是在某处遗漏了一个“,但我不确定在哪里。Else WScript.Echo 之后的第一个“字符串”在我的文本编辑器中没有显示为蓝色,因为它应该是这样的那里也有东西。任何帮助将不胜感激。(错误声称在 5、60)
'Pin an application to a start menu or task bar
If WScript.Arguments.Count = 3 then
Call PinApplicationToTaskBar(WScript.Arguments(0), WScript.Arguments(1), WScript.Arguments(2))
Else
WScript.Echo "Missing parameters. String AppPathAndName _
String ShortcutName Boolean OnStartMenu." & vbCr & vbCr & " _
Example cmd.exe CMD false" & vbCr & vbCr & _
" Example %windir%\system32\SnippingTool.exe SnipIt false"
End If
Public Sub PinApplicationToTaskBar(AppPathAndName, ShortcutName, OnStartMenu)
'This is on for a soft failure.
'Uncomment this if error checking for a hard failure is needed for debugging.
On Error Resume Next
Dim FileSystemObj, ObjShell, ObjShellApp
Set ObjShell = WScript.CreateObject("WScript.Shell")
Set FileSystemObj = CreateObject("Scripting.FileSystemObject")
'Create a temp location for the short-cut to exist
TempShortcutLocation = FileSystemObj.GetFolder_
(ObjShell.ExpandEnvironmentStrings("%TEMP%"))
'Where is it being pinned too? Determine the location where the pinned item will reside.
If(trim(lcase(OnStartMenu)) = "true") then ' pinned to start menu
HasItAlreadyBeenPinnedShortCut = ObjShell.ExpandEnvironmentStrings_
("%APPDATA%") & _
"\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu"
Else
HasItAlreadyBeenPinnedShortCut = ObjShell.ExpandEnvironmentStrings_
("%APPDATA%") & _
"\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"
End If
'Temporary location for the application short-cut
TempShortcut = TempShortcutLocation & "\" & ShortcutName & ".lnk"
'Possible location of a pinned item
HasItAlreadyBeenPinnedShortCut = HasItAlreadyBeenPinnedShortCut & "\" & ShortcutName & ".lnk"
'If this already exists, than exit this procedure. The application has already been pinned.
If(FileSystemObj.FileExists(HasItAlreadyBeenPinnedShortCut)) Then
'MsgBox(HasItAlreadyBeenPinnedShortCut & " Already Pinned")
Set ObjShell = Nothing
Set FileSystemObj = Nothing
Exit Sub
End If
'Create a short-cut using the shell
Set lnk = ObjShell.CreateShortcut(TempShortcut)
lnk.TargetPath = AppPathAndName ' Full application path and name
lnk.Arguments = ""
lnk.Description = ShortcutName 'The name that appears on the start menu.
lnk.Save
Set ObjShellApp = CreateObject("Shell.Application")
'Get the newly created short-cut full path
Set ShortCutToPin = ObjShellApp.NameSpace(TempShortcutLocation)
If(FileSystemObj.FileExists(TempShortcut)) Then
Dim ShortCutToPinItem, verb
'Set the location to pin the item to do based on the passed OnStartMenu argument
If(trim(lcase(OnStartMenu)) = "true") then
verbToDo = "Pin to Start Men&u"
Else
verbToDo = "Pin to Tas&kbar"
End If
For Each ShortCutToPinItem in ShortCutToPin.Items()
'Look for the pinning verb when the temporary short-cut name matches the passed ShortcutName argument
If (ShortCutToPinItem.Name = ShortcutName) Then
'Loop through the shell object's (the short-cut) commands looking for the pinning method.
For Each verb in ShortCutToPinItem.Verbs
'The verb matches the verbToDo so pin it to verb's defined location
If (verb.Name = verbToDo) Then verb.DoIt
Next
End If
Next
'Delete the temporary short-cut used to pin the application
FileSystemObj.DeleteFile(TempShortcut)
End If
'clean up
Set ObjShell = Nothing
Set FileSystemObj = Nothing
Set ObjShellApp = Nothing
End Sub
为了参考和信用,代码来自这里。 http://www.codeproject.com/Tips/713824/Pin-a-shortcut-onto-the-Taskbar-or-Start-Menu
【问题讨论】: