# Remote shutdown over CMD



## jackdw (Jul 1, 2005)

I am trying to shutdown a computer on my network. Usually I Remote Desktop to it (XP pro) but I installed a wireless card the other day which stops that. I have a fix tool which I can run to stop that.

I don't want to just pull the plug on it so I heard about a CMD command:
shutdown -m \\K-nex -s

K-nex being the name of the computer.

When I type that into CMD I get:
Access is denied.


The computer does not have a screen nearby, that's why I want to shut it down over network so I can move it to a screen. Plus it will come in handy.

Any idea what's wrong?
Thanks
- Jack

EDIT: The computer is on a different workgroup to the one I want to use to initiate the shutdown. I guess that shouldn't matter, or does it?


----------



## gurutech (Apr 23, 2004)

Put the -s in front of the -m. You will also need admin rights on your PC (and possibly on the remote PC as well).

You can also check out www.sysinternals.com and download an app called "psexec", which can be used to run the shutdown command as if you were on the PC that you need to shut down.


----------



## draceplace (Jun 8, 2001)

I use this script to 'Reboot' computers that I can't remote desktop to..

LTprompt = "Enter the MACHINE NAME on which you would like to Reboot:" & VbCrLf 
LTtitle = "Remote Reboot Script"

strComputer=InputBox(LTprompt, LTtitle)

If strComputer = "" Then
ErrorTxt01 = "You did not enter a MACHINE NAME!"
File_Err1 'Call Error Echo
WScript.Quit
End If
On Error Resume Next

LTprompt = strComputer & VbCrLf & _
"You are about to attempt to reboot machine- " & strComputer & VbCrLf & _
"This could take 20 to 40 seconds." & VbCrLf & "Click Yes to Continue"
LTanswer=MsgBox(LTprompt, vbYesNo, LTtitle)
If LTanswer = vbYes Then

'************Go reboot the machine already*******************
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Reboot()

Next 
Else
ErrorTxt01 = "User Aborted the Reboot Script"
File_Err1 'Call Error Echo
WScript.Quit
End If

'********Kinda hard coded Error Check for Reboot Routine********************
If Err.Number <> 0 Then
ErrorTxt01 = "Probably Machine doesnt exist or is not available 1C3"
File_Err1 'Call Error Echo
Else 
File_Success
End If

'Close the file

Set WshNetwork = Nothing
Set objWMIService = Nothing
Set colOperatingSystems = Nothing
'End If

'**********************************************
'Echo Error subroutine
'**************************************
Sub File_Err1
' ErrorTxt01 = "File Error"
' EndTxt = EndTxt & "Error #" & hex(Err.Number) & " " & _
' Err.Description & ". " & ErrorTxt01 & VbCrLf

WScript.Echo "Error #" & hex(Err.Number) & " " & _
Err.Description & ". " & VbCrLf & ErrorTxt01

ErrorCnt01 = ErrorCnt01 + 1
Err.Clear
End Sub

'**********************************************
'Echo Success subroutine
'**************************************
Sub File_Success
SuccessTxt = "Computer Restarted!" & "-" & strComputer & vbCrLf
WScript.Echo SuccessTxt 
SuccessCnt01 = SuccessCnt01 + 1
End Sub

'***********************************************
'End of Code
'*************************************


----------



## draceplace (Jun 8, 2001)

I haven't tried it as shutdown only but it looks like you could comment or delete the 'reboot' part of the script


----------



## jackdw (Jul 1, 2005)

gurutech said:


> Put the -s in front of the -m. You will also need admin rights on your PC (and possibly on the remote PC as well).
> 
> You can also check out www.sysinternals.com and download an app called "psexec", which can be used to run the shutdown command as if you were on the PC that you need to shut down.


The account name is no the same but both are logged on with accounts with Admin rights. I'll visit your link and have a look.

As for the script


----------



## jackdw (Jul 1, 2005)

Downloaded psexec, put it into C:/docs and settings/user folder and ran it from CMD.

How do I define a login etc to shut it down?

EDIT: What I am trying:


> C:\Documents and Settings\Jack>psshutdown -k -u USERNAME -p PASSWORD \\k-nex
> 
> PsShutdown v2.52 - Shutdown, logoff and power manage local and remote systems
> Copyright (C) 1999-2006 Mark Russinovich
> ...


----------



## draceplace (Jun 8, 2001)

Copy and paste the script into notepad and save it as .vbs starting at ltprompt=. Double click and it runs. A window will pop and and ask for the machine name. Test on a pc nearby and you can watch it shutdown/ reboot. This script could be simplified to about 10 lines but I tried to make it somewhat idiot proof. 

To get rid of the reboot...comment or delete this part

Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Reboot()


----------



## draceplace (Jun 8, 2001)

Re-reading the post ...the script may have problems if you're not a system admin.


----------



## Squashman (Apr 4, 2003)

Would probably help to know what operating system is running on each computer and if their are any Firewalls running. Might try just using the IP address as well. You also have the syntax wrong for Psshutdown.
http://www.microsoft.com/technet/sysinternals/utilities/psshutdown.mspx


----------



## jackdw (Jul 1, 2005)

All machines run windows XP Pro. My main one (this one) uses XP Pro media center edition.
This PC and one other (not the one I'm trying to turn off) run norton 2006.


----------



## jackdw (Jul 1, 2005)

draceplace:
I did it but it said machine cannot be found or something.

Squashman:
What am I supposed to type in? All that looks double greek to me...


----------



## draceplace (Jun 8, 2001)

You can use the ip address in the script as well. Usually if you can ping the machine you can get it with the script. I assume it use local dns cache for name resolution. The other side is I've never used this in a 'workgroup'. The error routine is hard coded because 99% of our problems are the machine isn't there, or the name is wrong. A 1c3 error is 'cant find the machine' if the error is something other than 1C3 you have to look it up to find out the problem.


----------



## Squashman (Apr 4, 2003)

usage: psshutdown [[\\computer[,computer[,..] | @file [-u user [-p psswd]]] -s|-r|-h|-d|-k|-a|-l|-o [-f] [-c] [-t nn|h:m] [-n s] [-v nn] [-e [u|p]:xx:yy] [-m "message"]

You don't have your stuff in the correct order.

pssshutdown \\computer -u username - p password -k

I would make sure that the XP firewall is not turned on. I would also disable Simple File Sharing. I have seen this cause issues with psexec.

I don't use pstools much anymore for shutdown control. I mostly use PowerOFF.
http://users.pandora.be/jbosman/applications.html


----------



## jackdw (Jul 1, 2005)

powerOFF seems to have the same access is denied problem. I'll just unplug it at the wall and hook it up to a screen.

I won't mark as solved as I want to get this working. I guess that I'm getting the wrong password...


----------



## Squashman (Apr 4, 2003)

You sure the computer isn't hibernated?

I don't always recommend it but I have safely plugged in Monitors, keyboards and mice on the fly. It is not recommended but it sometimes works. I know it is scary to just power it down but it may be fine that way. Don't just unplug it. Push the power button. I actually have my power button configured to shutdown when pressed.


----------



## jackdw (Jul 1, 2005)

The computer wasn't hibernated because it has a LED fan which was on and working.
The computer itself is on the floor by my router, sometimes acting as a counter strike server. It hasn't got a case as such:
http://img156.imageshack.us/img156/2863/dscf4459md9.jpg

I turn it on by lickingt he end of my finger and running it across the front panel pins. Works....
The screen mouse and keyboard I was going to nick from a computer more than a power cable's length away. Anyway, it's off now, I'll go eat and try figure what password is on there..


----------



## wisdum (Dec 1, 2005)

If all else fails, you can use OfflineNT to reset the admin password so you know what it is...

then, next time you want to shut it down you won't have the authentication issues!

Also, one thing i dont think i saw in there was that you can bring up the little shutdown GUI and remotely select computers to shutdown and give a reason and the whole works. Sorry, can't remember the switch, lol


----------



## jackdw (Jul 1, 2005)

I reset the password on the computer by logging into Administrator which has no password.

Using new, known password:


> C:\Documents and Settings\Jack>psshutdown -k -u TDSQ \\k-nex
> 
> PsShutdown v2.52 - Shutdown, logoff and power manage local and remote systems
> Copyright (C) 1999-2006 Mark Russinovich
> ...


Hidden password so it doesn't show.

Also, I assume I don't need to install or put anything on the target computer?


----------



## Squashman (Apr 4, 2003)

Nope, nothing on the target computer. I guess the order of the syntax doesn't make a difference. I figured it would but since it is telling you it couldn't access the computer the syntax doesn't make a difference. Is this user an administrator? Did you disable simple file sharing?


----------



## jackdw (Jul 1, 2005)

It's the user specified in the XP setup so yes, admin rights.

How do I disable file sharing after I have ran network setup wizard? Just run it again and choose turn off file and printer sharing?


----------



## Squashman (Apr 4, 2003)

I did not say Turn off File and Printer Sharing. I said disable Simple File Sharing.
http://compnetworking.about.com/cs/winxpnetworking/ht/winxpsfs.htm

We may have to make a Policy setting as well, but I think this will fix it. If not the policy setting will. But both have to be set for Pstools to work.


----------



## jackdw (Jul 1, 2005)

Well, I used remote desktop connection to view it as it shut down. The little timer saying shutdown in 20secs popped up, as it reached 0 it said "If you shut down this remote computer, no one can use it until someone at the remote location manually restarts it. Do you wish to continue shutting down?" Then two buttons, yes or no. First time I pressed no, closed remote desktop and told it to shutdown over psshutdown again. Left it for 5 minutes, it was still on. Logged back on by remote desktop and that box had come back up again with Yes or No.

Is there anyway I can stop it from saying it but still be able to log on with remote desktop before hand?


----------



## Squashman (Apr 4, 2003)

Did you get psshutdown to work or not after disable Simple File Sharing?


----------



## jackdw (Jul 1, 2005)

Squashman said:


> Did you get psshutdown to work or not after disable Simple File Sharing?


It initiated a shutdown but got stopped by remote desktop connection. I'll fiddle around..

And thu3w, this is a computer on my own network that doesn't have a mouse, screen or keyboard as it is used purely as a server which loads all software needed on startup.
Also, check this thread. I do not mind at all with you asking for help in this thread as it is about exactly the same thing but replies to both should be posted here for the benefit of us and anybody who runs a search at a later data can see the entire process.


----------



## wisdum (Dec 1, 2005)

So why does remotely shutting down the pc with command line shutdown.exe command not work? Is it still giving you authentication errors? 

You should be able to with the shutdown command remotely shutdown a computer and provide it a username and password to do so.

If your DNS is working correctly, you can use the shutdown -i command to bring up the remote shutdown dialog box and then Add... the computer you want to shutdown and just do it. If that doesn't work then you have an authentication error. Which means you don't have matching username/password on both machines (easiest way to do it).

I would recommend you place a local administrator account on both machines (i like to use hal or skynet, lol) that has the same password on both machines. Then you don't have to authenticate, it will do it for you.

I dont see how simple file sharing has much to do with it...but i don't have much experience with non-domain remote shutdowns and simple file sharing turned on, lol

oh, and one more thought, get a kvm


----------



## wisdum (Dec 1, 2005)

jackdw said:


> I reset the password on the computer by logging into Administrator which has no password.
> 
> Using new, known password:
> 
> ...


Is that still true? You can not schedule tasks or remotely shutdown or do anything over a network unless you have passwords on the accounts. You MUST have a password


----------



## jackdw (Jul 1, 2005)

The account I was using, not the root admin account, had a password. No, the account named Administrator does not have a password but I wasn't using that.


----------

