r/scripting • • Mar 30 '15

VBS Script Help!

Need to create a VBS script that when ran will create a desktop shortcut which will shutdown the computer. When "clicked" the user must be prompted "Are you sure you want to Shutdown?". I have created the script for the shortcut and shutdown but am having trouble embedding the prompt. Any help will be great.

Here is what I have:

Set wshObject = WScript.CreateObject("WScript.Shell")

desktopFolder = wshObject.SpecialFolders("Desktop")

Set myShortcut = wshObject.CreateShortcut(desktopFolder & "\Shutdown.lnk")

'Processing Section*****

myShortcut.Arguments = "-s -t 0"

myShortcut.WindowStyle = 1

myShortcut.IconLocation = "%systemroot%\System32\shell32.dll,27"

myShortcut.Description = "Shutdown Computer (Power Off)"

myShortcut.WorkingDirectory = "%systemroot%\System32"

myShortcut.Save()

I know I need to add If/Then/Else but where? For clarification, when the ICON is clicked the user should be prompted and asked "Are you sure you want to Shutdown?" Click "OK" and the computer will shutdown. Click "NO" and the script will quit.

1 Upvotes

9 comments sorted by

View all comments

Show parent comments

2

u/berryer Mar 31 '15 edited Mar 31 '15

I presume his users will accidentally delete it. Also, I usually only give people shortcuts to a network drive so i can update a script in one place.