Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pc shudown script

Status
Not open for further replies.

n3tw0rkadm1n1strat0r

IS-IT--Management
Aug 29, 2006
119
US
I can't figure out why this isn't working...I'm bad with the quotes...It gives me an error saying that the system cannot find the specified file, but I know that it is there.

Code:
Set objShell = CreateObject("Wscript.Shell")

strComputer = InputBox("Enter the PC name to shutdown:")
strMessage = InputBox("Enter the message to display:")
strTime = InputBox("Enter the time in seconds to shutdown:")

objShell.Run("""%comspec% /K C: | cd WINDOWS\system32 | shutdown.exe -r -m \\""strComputer"" -t ""strTime"" -c ""strMessage"" """), 0, True

Set objShell = Nothing
 
maybe this...
objShell.Run "shutdown.exe -r -m \\" & strComputer & " -t " & strTime & " - """ & strMessage & """", 0, True

I would suggest using WScript.Echo to test your string.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Actualy I foudn this to work....

"shutdown -r -t " & strTime & " -c " & strMessage & " -m \\" & strComputer

But what I'm trying to with the ("""%comspec% /K) is to hide the command prompt window.
 
%comspec% /k shutdown -r -t " & strTime & " -c " & strMessage & " -m \\" & strComputer

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
From the code you provided, I don't see how it would loop.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
I tried this and it worked just fine.

Code:
Set objShell = CreateObject("Wscript.Shell")

strComputer = InputBox("Enter the PC name to shutdown:")
strMessage = InputBox("Enter the message to display:")
strTime = InputBox("Enter the time in seconds to shutdown:")

objShell.Run "%comspec% /K shutdown -r -t " & strTime & " -c " & Chr(34) & strMessage & Chr(34) & " -m \\" & strComputer, 0, True

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
And what about this ?
objShell.Run "%comspec% /K shutdown -r [!]-f [/!]-t " & strTime & " -c " & Chr(34) & strMessage & Chr(34) & " -m \\" & strComputer, 0, True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
As dm4ever pointed out, the code you provided should not loop. How are you calling the script? From within a batch file? command line "cscript myscript.vbs"?
 
I know your saying it should but it does...maybe I'm missing something in mine, this is exactly what I have right now:

Code:
Set objShell = CreateObject("Wscript.Shell")

strComputer = InputBox("Enter the PC name to shutdown:")
strMessage = InputBox("Enter the message to display:")
strTime = InputBox("Enter the time in seconds to shutdown:")

objShell.Run "%comspec% /K shutdown -r -f -t " & strTime & " -c " & Chr(34) & strMessage & Chr(34) & " -m \\" & strComputer, 0, True 

Set objShell = Nothing
 
this is exactly what I have right now
Where ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Where is the script located ? in a .vbs ? .htm ? .hta ? ...
How is this script launched ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
What happens if you Right-click the .vbs and choose either Open or Open with command prompt ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
And to confirm the behavior... it shows you "Enter the PC name?", then "Enter the message?", then "Enter the time?" ... and then "Enter the PC name?" again?

Script works fine for me, double clicking a .vbs file.
 
The same thing happens...the problem isn't how the script is ran. I think there has to be parentheses around the command like how I have in my first post. That is how I've seen it in other scripts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top