批处理文件 - 生成的脚本不创建快捷方式



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

我试图使用批处理创建一个临时的VBScript,我得到的输出是:

C: 用户艾伯特~ 1 AppData 当地 Temp 11338-3520-31784-27073。根据(1)WshShortcut。拯救策略:快捷方式"C:UsersAlbertMøllerDownloadsDesktop askontrolpanel . link"失败得救。

这是我的VBScript代码:
set SCRIPT="%TEMP%%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"
echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo sLinkFile = "DesktopASKontrolpanel.lnk" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = "%ProgramData%AutoShutdownAutomaticShutdown.bat" >> %SCRIPT%
echo oLink.Save >> %SCRIPT%
cscript /nologo %SCRIPT%
del %SCRIPT%

它似乎在我测试过的所有其他计算机上都能工作,这是3。我尝试以管理员权限打开它,但它仍然不工作

这个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%system32SHELL32.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
'**********************************************************************************************

在这个例子中,你应该替换"e:Tempt.bat"为你的批处理文件的路径,并替换"Hackoo"为快捷方式的名称。

Call Shortcut("e:Tempt.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%system32SHELL32.dll,-25"
    objShortCut.Save
End Sub
'*********************************************************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'*********************************************************************************

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

@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%system32calc.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

相关内容

  • 没有找到相关文章

最新更新