New to Scripting, Need help with VBScript shutting down before prompt.

It is very hard to read a script with no formatting.  See if you can fix it so we can read it.

You also need to ask a question.

May 29th, 2015 2:26am

Ok so here it is, I need to create a shortcut in which I can be prompted if I would like to shut down windows (Action to shutdown when clicking ok). Any ideas?

So far the working shutdown shortcut that I have does not issue the prompt a message asking if I truly want to shutdown or cancel the shortcut request.

Helpful suggestions are very much needed, as I mentioned I am new to scripting.

It does not work, won't help what I already know ;)

Here it is:

Dim shellApp, answer

REM Creates Shortcut with a Path to the desktop.
Set Shell = CreateObject("WScript.Shell")
  DesktopPath = Shell.SpecialFolders("Desktop")

REM Establishes and names the shortcut Shutdown.
Set linkShutdown = Shell.CreateShortcut(DesktopPath & "\Shutdown.lnk")
 
REM Adds shutdown code to the shortcut.
linkShutdown.Arguments = "-s -t 01"

REM Adds Description to shortcut that displays message on link over.
linkShutdown.Description = "Shutdown this Computer"
 
REM Creates Icon for shortcut using system shutdown icon.
linkShutdown.IconLocation = ("%SystemRoot%\system32\SHELL32.dll,27") 
 
REM Retrieves shutdown target path for shortcut.
linkShutdown.TargetPath = "shutdown"

REM Saves the Script.
linkShutdown.Save

REM Prompts the user if they want to shutdown their computer, 
REM displays ok and cancel buttons for the user to choose.
Set shellApp = CreateObject("Shell.Application")
answer = MsgBox("Do you really want to shut down the computer?", 1,"Turn off Computer 

Script!")

If answer = 1 then
Initiate_Logoff()
End if

REM Function that shuts computer down.
Function Initiate_Logoff()
REM Adds shutdown code to the shortcut.

End Function

Free Windows Admin Tool Kit Click here and download it now
May 29th, 2015 3:46am

No idea what you are asking.  A shortcut does not have code. It points to a program or script.
May 29th, 2015 6:32am

Your code can never run.  It has too many syntax errors.  Fix the errors first.\

Why is there an "End Function" in the middle of the code.

If you earned too format code properly you would see where your errors are very quickly.

Free Windows Admin Tool Kit Click here and download it now
May 29th, 2015 6:36am

Why create a shortcut if you can execute the shutdown command directly? This simplified script will shut down Windows after 120 seconds, to give you a chance to cancel the command while testing.

Set oShell = CreateObject("WScript.Shell")
If MsgBox("Do you really want to shut down the computer?", 1,"Turn off Computer Script!") = 1 _
Then oShell.Run "shutdown.exe /s /f /t 120", 1, True

May 29th, 2015 7:15am

Frederik,

 I wish it were that easy but I attempt to follow guidance to the T when possible. I know a script is capable of a great many things but what I cannot figure out is how to initiate the shutdown with a pop-up message asking me to confirm the shutdown. I feel like I am really close to the result but cannot fathom where I am going wrong.

Free Windows Admin Tool Kit Click here and download it now
May 29th, 2015 8:18am

I wish it were that easy but I attempt to follow guidance to the T when possible. I know a script is capable of a great many things but what I cannot figure out is how to initiate the shutdown with a pop-up message asking me to confirm the shutdown.


The script I posted does exactly what you want. Did you test it?
May 29th, 2015 9:34am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics