我在第6行得到一个错误,即带有lnk的错误。TargetPath,该参数无效。我希望在桌面上的"开始"菜单下创建一个指向该程序的链接。有人知道它为什么这么做吗?
Set objShell = WScript.CreateObject("WScript.Shell")
Set lnk = objShell.CreateShortcut("C:Users%USERDATA%DesktopShutdown.LNK")
Dim strUserProfile
strUserProfile = objShell.ExpandEnvironmentStrings("%USERPROFILE%")
lnk.TargetPath = "C:Users" & strUserProfile & "AppDataRoamingMicrosoftWindowsStart MenuProgramsshutdown.bat"
lnk.Arguments = ""
lnk.Description = "Shutdown"
'lnk.HotKey = "ALT+CTRL+F"
lnk.IconLocation = "C:Users" & strUserProfile & "AppDataRoamingMicrosoftWindowsStart MenuProgramsshutdown.bat, 2"
lnk.WindowStyle = "1"
lnk.WorkingDirectory = "C:Users" & strUserProfile &"AppDataRoamingMicrosoftWindowsStart MenuPrograms"
lnk.Save
Set lnk = Nothing
我认为这是因为strUserProfiles保存了用户目录的完整路径。试试这个稍微修改过的代码:
Set objShell = WScript.CreateObject("WScript.Shell")
Dim strUserProfile
strUserProfile = objShell.ExpandEnvironmentStrings("%USERPROFILE%")
Set lnk = objShell.CreateShortcut(strUserProfile & "DesktopShutdown.LNK")
lnk.TargetPath = strUserProfile & "AppDataRoamingMicrosoftWindowsStart MenuProgramsshutdown.bat"
lnk.Arguments = ""
lnk.Description = "Shutdown"
'lnk.HotKey = "ALT+CTRL+F"
lnk.IconLocation = strUserProfile & "AppDataRoamingMicrosoftWindowsStart MenuProgramsshutdown.bat, 2"
lnk.WindowStyle = "1"
lnk.WorkingDirectory = strUserProfile &"AppDataRoamingMicrosoftWindowsStart MenuPrograms"
lnk.Save
Set lnk = Nothing