0

私のコードについて助けが必要です。2 つのことを行うスクリプトを作成しようとしています。まず、ユーザーのデスクトップにショートカット アイコンを作成します。次に、ユーザーがアイコンをダブルクリックすると、コンピューターを再起動するかどうかを尋ねるボックスが表示され、[OK] をクリックして再起動し、[キャンセル] をクリックしてコマンドをキャンセルするオプションが表示されます。コマンドプロンプトにスクリプトを入力すると、コンピューターの再起動オプションが実行されます。どんな助けでも大歓迎です。これが私のスクリプトです:

    Dim answer


' ********* Main processing section **********

' Verify that the user wants to open the Turn Off Computer dialog
    Set wshObject = WScript.CreateObject("WScript.Shell")
    desktopFolder = wshObject.SpecialFolders("Desktop")
    Set myShortcut = wshObject.CreateShortcut(desktopFolder & "\\Shortcut.lnk")
    myShortcut.TargetPath = "%windir%\Shortcut.exe"
    myShortcut.Save()

    answer = MsgBox("The Turn Off Computer dialog will be opened.", 1, "Turn off Computer Script!")
    If answer = 1 then  ' User clicked on OK
    Initiate_Logoff()
    End if

' *********** Procedures go here *************

' Open the Windows Turn Off Computer dialog
    Function Initiate_Logoff()
    shellApp.ShutdownWindows
    End Function
4

1 に答える 1

0

これはどう:

Option Explicit

'create a desktop shortcut
Dim shl : Set shl = CreateObject("WScript.Shell")
Dim scut : Set scut = shl.CreateShortcut(shl.ExpandEnvironmentStrings("%USERPROFILE%") & "\Desktop\Shortcut.lnk")
scut.TargetPath = "%windir%\shortcut.exe"
scut.Save

Dim cmd : cmd = "shutdown.exe /r /t 1" 'this command restarts the machine

'if the script is being run by cscript (command line)
If InStr(WScript.FullName, "cscript") > 0 Then
  shl.Exec cmd
Else
  'else ask the user
  If MsgBox("Restart Now?", vbQuestion + vbOKCancel, "Title") = vbOK Then
    shl.Exec cmd
  End If
End If

WScript.Quit
于 2014-11-26T14:23:37.910 に答える