1

我的 Windows 8 PC 似乎不想使用 VBScript 创建快捷方式。问题是,它以某种方式无法保存。这似乎是只有我的电脑才有的问题。

我正在尝试使用 Batch 创建一个临时 VBScript,我得到的输出是:

C:\Users\ALBERT~1\AppData\Local\Temp\11338-3520-31784-27073.vbs(5, 1) WshShortcut.Save:快捷方式“C:\Users\AlbertMøller\Downloads\Desktop\ASKontrolpanel.lnk”无法保存。

这是我的 VBScript 代码:

set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"
echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo sLinkFile = "Desktop\ASKontrolpanel.lnk" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = "%ProgramData%\AutoShutdown\AutomaticShutdown.bat" >> %SCRIPT%
echo oLink.Save >> %SCRIPT%
cscript /nologo %SCRIPT%
del %SCRIPT%

它似乎适用于我测试过的所有其他计算机,即 3。我尝试使用管理员权限打开它,但它仍然无法正常工作。

4

2 回答 2

2

这个 Vbscript 可以在您的桌面上创建一个快捷方式,询问您是否要关闭计算机。

Option Explicit
Dim MyScriptPath 
MyScriptPath = WScript.ScriptFullName
Call Shortcut(MyScriptPath,"Shutdown the computer")
Call AskQuestion()
'**********************************************************************************************
Sub Shortcut(PathApplication,Name)
    Dim objShell,DesktopPath,objShortCut,MyTab
    Set objShell = CreateObject("WScript.Shell")
    MyTab = Split(PathApplication,"\")
    If Name = "" Then
        Name = MyTab(UBound(MyTab))
    End if
    DesktopPath = objShell.SpecialFolders("Desktop")
    Set objShortCut = objShell.CreateShortcut(DesktopPath & "\" & Name & ".lnk")
    objShortCut.TargetPath = Dblquote(PathApplication)
    ObjShortCut.IconLocation = "%SystemRoot%\system32\SHELL32.dll,-28"
    objShortCut.Save
End Sub
'**********************************************************************************************
Sub AskQuestion()
    Dim Question,Msg,Title
    Title = "Shutdown the computer"
    Msg = "Are you sure to shutdown the computer now ?"& Vbcr &_
    "If yes, then click [YES] button "& Vbcr &_
    "If not, then click [NO] button"
    Question = MsgBox (Msg,VbYesNo+VbQuestion,Title)
    If Question = VbYes then
        Call Run_Shutdown(30)
    else
        WScript.Quit()
    End if
End Sub
'**********************************************************************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'**********************************************************************************************
Sub Run_Shutdown(N)
    Dim ws,Command,Execution
    Set ws = CreateObject("wscript.Shell")
    Command = "Cmd /c Shutdown -s -t "& N &" -c "& DblQuote("Save your work because your PC will shut down in "& N &" seconds")
    Execution = ws.run(Command,0,True)
End sub
'**********************************************************************************************

编辑:2015 年 4 月 6 日

在此示例中,您应该将“e:\Temp\t.bat”替换为批处理文件的路径,并将“Hackoo”替换为快捷方式的名称。

Call Shortcut("e:\Temp\t.bat","Hackoo")
'*********************************************************************************
Sub Shortcut(PathApplication,Name)
    Dim objShell,DesktopPath,objShortCut,MyTab
    Set objShell = CreateObject("WScript.Shell")
    MyTab = Split(PathApplication,"\")
    If Name = "" Then
        Name = MyTab(UBound(MyTab))
    End if
    DesktopPath = objShell.SpecialFolders("Desktop")
    Set objShortCut = objShell.CreateShortcut(DesktopPath & "\" & Name & ".lnk")
    objShortCut.TargetPath = Dblquote(PathApplication)
    ObjShortCut.IconLocation = "%SystemRoot%\system32\SHELL32.dll,-25"
    objShortCut.Save
End Sub
'*********************************************************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'*********************************************************************************
于 2015-06-03T17:26:37.113 回答
1

试试这个代码,告诉我它是否适合你?

@echo off
mode con cols=87 lines=5 & color 9B
Title Generer le vbscript pour la creation du raccourci sur le bureau by Hackoo
echo Generer le vbscript pour la creation du raccourci
Timeout /T 2 > Nul
(
echo Call Shortcut("%windir%\system32\calc.exe","Calculatrice"^)
echo ^'**********************************************************************************************^)
echo Sub Shortcut(CheminApplication,Nom^)
echo    Dim objShell,DesktopPath,objShortCut,MyTab
echo    Set objShell = CreateObject("WScript.Shell"^)
echo    MyTab = Split^(CheminApplication,"\"^)
echo    If Nom = "" Then
echo    Nom = MyTab(UBound^(MyTab^)^)
echo    End if
echo    DesktopPath = objShell.SpecialFolders("Desktop"^)
echo    Set objShortCut = objShell.CreateShortcut(DesktopPath ^& "\" ^& Nom ^& ".lnk"^)
echo    objShortCut.TargetPath = Dblquote^(CheminApplication^)
echo    ObjShortCut.IconLocation = "Winver.exe,0"
echo    objShortCut.Save
echo End Sub
echo ^'**********************************************************************************************
echo ^'Fonction pour ajouter les doubles quotes dans une variable
echo Function DblQuote(Str^)
echo    DblQuote = Chr(34^) ^& Str ^& Chr^(34^)
echo End Function
echo ^'**********************************************************************************************
) > Shortcutme.vbs
echo Execution du vbscript pour la creation du raccourci de la calculatrice sur le bureau
Start /Wait Shortcutme.vbs
echo Suppression du Vbscript
Del Shortcutme.vbs
echo Termine
Pause > Nul
于 2015-06-02T21:10:04.807 回答