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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shut down a computer remotely via Batch script?

Status
Not open for further replies.

captaincrunch00

IS-IT--Management
Mar 8, 2004
582
US
Hi there,

I've got an XP Pro computer, my roommate who has completely different hours than me has a 2000 computer. I share the internet through my computer, it's simply easier than using a router.

Is there a way he can shut down my computer remotely? I'm looking for the easiest possible solution like "Double click this icon" because he's not exactly computer literate.

Our sleeping schedules are drastically different, it would be a lot easier if he could just shut mine down, shut his down, then go to bed rather than come into my room, stumble around, flick on a light, shut mine down.... you know the drill.

I was thinking about allowing mine to be remotely controlled, but I really dont want him having access to that because I KNOW something will get screwed up or changed or formatted, or something like that.

Any ideas?
Thanks
 
I must disagree that using internet connection sharing is easier than using a router!

You have already given one reason why it is not, that your friend needs to come into your room to turn off your PC. What happens if your friend wants to go online when your PC is off? You can get a router with built in switch very cheaply these days (especially when the price is shared) and this would make both machines independent. This is certainly what I would reccommend you do.

However, In response to your actual question, if your machines are on the same work group, there is a command in DOS, that brings up a window to which you can select which machines to shut down.

In XP Pro (unsure about 2000 i must admit), at the command prompt, you can use the shutdown command.

Type shutdown -i. When the box opens, click browse, select the appropriate machine, then shut it down.

You could make a batch file, yes, using the same command with a different switch. The syntax for the command is:

shutdown -m \\COMPUTER_NAME -s

(the -s means shut down. you could use -r to reboot.)

This is certainly the case in XP Pro, as I say I am unsure about 2000. It should imagine it to be possible however, so check the dos help if you need to.

Hope this helps.


'When all else fails.......read the manual'
 
Yeah, I have 2 Linksys cable routers with the switches... Twice I've had them for no reason whatsoever just slow down to a crawl. I plug the modem directly into my PC, it runs at normal speed.
If I use the router it slows me down so that I am on par with dialup.
I've upgraded the firmware, I've reset it to factory settings, I have no idea what is going on.

I got sick of playing with that at home when it's also my job, so I shared them this way.

Thanks a lot for the info, I will try that on his computer with a little batch script that hopefully can run like a dream.

Thanks!
 
Ah, that makes sense in that case! My apologies. What connection do you have?

I tried the shutdown command on the Windows 2000 server here and it was not recognised. I can't say for certain wether or not the PC version will be the same.

This link is worth a look and will probably answer any other questions you have, it seems you need the Windows 2000 Resource Kit:


More Resource Kit Info:




'When all else fails.......read the manual'
 
As far as the linksys problem. How old are your linksys routers? I had the exact same problem with an older linksys I had used for several years. I upgraded firmware and that made no difference. Then I went and bought a new D-link and my speed is back to broadband rates! =D

"Once you can accept the universe as matter expanding into nothing that is something, wearing stripes with plaid comes easy"
Albert Einstein
 
I bought the routers about a year apart, it took about 9 months for the speed to slow down and never be able to break the 3k/sec barrier. I bought a new one a few months ago because I got sick of this shutdown problem, and it took about a 2 months for it to crash and burn.

I tried a Netgear as well, but right from the start the speeds werent anywhere close to what they should be. If I plug in the router I get speeds of like 1500kb/sec on toast.net, but without the router I get my normal speeds of 2700-3200k/sec.

No more routers for me unless they say "Cisco" on them and they cost an arm and a leg.
 
I haven't got a W2K box here to test it on but the following VBS script (using WMI) should do it:

Copy/paste the code and save it as something like 'shutdown.vbs' on the W2K box somewhere then create a desktop shortcut to it.

Code:
ComputerName = InputBox("Enter the name or IP address of the computer you wish to shut down.", "Shutdown Remote PC")
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,(Shutdown)}!\\" & ComputerName & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
    ObjOperatingSystem.Win32Shutdown(1)
Next

If you want it even easier, replace the first line. For example, if your PC is called 'capncrunch' (and the PC's are in the same workgroup) then replace the first line with:

Code:
ComputerName = "capncrunch"

If the PC's are not in the same workgroup then use the IP address instead of the computername.

Note: This script is taken from an example by the MS Scripting Guys. I wondered whether to post it as, obviously, the script can be used irresponsibly. As it does a shutdown without any warning there is a risk of loss of data on the remote PC. Please use wisely!

For a more elegant solution that lets you vary the time and send a warning message (and which can be cancelled by the rmote user), see Remote Shutdown 1.0 (
Hope this helps...
 
No more routers for me unless they say "Cisco" on them and they cost an arm and a leg.
Cisco owns the company that makes linksys.

"Once you can accept the universe as matter expanding into nothing that is something, wearing stripes with plaid comes easy"
Albert Einstein
 
Yep, but they still say "Linksys" on them and are made much more cheaply than Cisco routers and switches.

Thanks for the advice Rick88, I'll be putting that into play tonight and let you know how it works tomorrow!
 
Well, that was a failure.
Oh, when I ran the VBS or either of those programs on my computer from my computer it shut it down with no problems.
I think I have a permission issue because I was trying to get into computer management (of my computer through his) using MMC because I could shut my PC down from his that way as well, but it says I dont have permission to do that.

Great.

Both of our usernames/passwords are "Administrator" with no password. I've doing a "run as" thing using X\Administrator as the username where X is my PC name, but that didnt work either.

Any ideas to get around this issue?
 
You need Windows Script Host (WSH) 5.6 or later installed on both the PC's to run the script successfully.

You can check the version of WSH on your friend's W2K PC using the following script. Copy/paste the code into Notepad and save it as something like wsh-ver.vbs.

Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Wscript.Echo objFSO.GetFileVersion("c:\winnt\system32\scrrun.dll")

If you need WSH5.6, it can be downloaded from
WSH 5.6 is installed by default in XP Pro but, according to an article in the Scripting area of "Unfortunately, XP Pro shipped with a configuration bug in which WSH 5.6 fails to set up properly. Based on my testing, the problem appears to be limited to the WshController object. To resolve the problem, you need to run the command wscript -regserver"

The article also includes the info, "Another possibility is that you haven't enabled the WshController object, which is disabled by default. To enable this object, you must add a value entry to the HKEY_LOCAL_ MACHINE\SOFTWARE\Microsoft\Windows Script Host\Settings registry subkey on the target computer. Open this subkey and click New, String Value on the Edit menu. Enter the value name Remote and a data value of 1. You don't need to restart the target computer for the new setting to take effect..."

This information on how to set up remote scripting is confirmed in the Windows Script Host area on MSDN (see
To save you doing this registry tweak manually, just copy/paste the following into Notepad and save it to the remote PC (i.e. your PC) as remote-wsh.reg. Double-click on the REG file and click on the Yes button to import it imto the registry.

Code:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Script Host\Settings]
"Remote"="1"

I have a local XP PC running from a account called 'admin' (with administrative privileges) and a remote XP PC also running from a account called 'admin' (with administrative privileges), including the remote scripting modification noted above made to the registry. I can assure you that the shutdown.vbs script works perfectly providing WSH 5.6 is set up correctly.

Hope this helps...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top