8

I'd like to know if it is possible to shut down a Windows Server 2003 box, without have to log into the machine via remote desktop.

The server is on my network, I know the IP address and host name, as well the Administrator password.

I want to shutdown by simply double clicking a shortcut or executing a script.

How do I do this?

4 Answers 4

16

Remote shutdown...

  • Using your domain account credentials (if your user account has local admin rights on the target machine):
    shutdown /s /f /t 30 /m \\SERVER-NAME
  • Using the remote machine's local administrator account (psexec will prompt you for the password):
    psexec \\SERVER-NAME -e -h -u SERVER-NAME\administrator shutdown /s /f /t 30
  • Using a different domain account:
    psexec \\SERVER-NAME -e -h -u DOMAIN-NAME\username shutdown /s /f /t 30

Shutdown parameters explained...

  • /s = shutdown (substitute /r if you want to reboot)
  • /f = force (don't let running programs or active user sessions interfere with the reboot)
  • /t 30 = give logged in users a 30-second warning (substitute any integer, 0 is an acceptable value)
  • /m \\SERVER-NAME = specify name of remote machine to reboot

PsExec parameters explained...

  • -e = do not load user profile (user profile is unnecessary for shutdown command)
  • -h = run task with elevated privileges (only makes a difference on Vista/Win7/Server2008)
  • -u SERVER-NAME\administrator = log in as local administrator on SERVER-NAME
  • shutdown /s /f /t 30 = i

Batch file example, using local admin account... (paste into Notepad as rsla.bat)

  • @echo off
    REM rsla.bat - remote shutdown as local administrator
    REM This script is freeware authored by Miles Erickson, 7/2010.
    REM Requires PsExec.exe to be available in %PATH% (c:\windows\system32 is one option)
    REM Cannot be used to restart a domain controller (domain controllers do not have local admin accounts)
    IF (%1)==() GOTO instructions
    IF (%1)==(/?) GOTO instructions
    psexec \\\\%1 -e -h -u %1\\administrator shutdown /s /f /t 30
    GOTO end
    :instructions
    ECHO Usage: rsla SERVER-NAME    (you will be prompted for a password)
    :end
    

Links...

1
9

If you didn't need to specify credentials, you could use the SHUTDOWN command. If you do need to specify credentials (your login doesn't have permissions, or the computer isn't on the domain), you can use the PSSHUTDOWN utility to do this.

3

Local account:

cmd /k wmic /node:"targetcomputerhostname" /user:"AdministratororWhatever" os where primary=true call reboot

AD account with local admin privileges:

cmd /k wmic /node:"targetcomputerhostname" /user:"DomainAccountWithAdminPrivs@fqdn" os where primary=true call reboot

This is easily portable as a batch file. Keep in mind you will need the proper remote exceptioins. If psshutdown works, this ought to work as well without installing any external software (not to dis SysInternals tools, the one thing Windows I swear by).

6
  • Hmmm... You do like WMIC! ;)
    – joeqwerty
    Jul 21, 2010 at 16:59
  • In some cases, WMIC is very valuable. In this case - not so much.
    – MDMarra
    Jul 21, 2010 at 20:47
  • Extremely ugly, unintuitive and hard to remember. Doesn't really have a lot going for it, does it? Jul 21, 2010 at 21:44
  • Say what you want, but is a) pre-installed on XP and b) allows me to avoid using UAC and/or runas when one of my domain accounts is different from the logon session on my computer. Judging by the fact that I got 0 votes, I guess beauty is more important than pragmatism for some. If I had my guess, judging by parameters available, shutdown and things like PsShutdown use the same API calls as WMIC to accomplish it anyway. But hey, I digress.
    – songei2f
    Jul 21, 2010 at 23:30
  • +1. One man's trash is another man's treasure. Your method gets the job done, which was the point of the question "How can I do this".
    – joeqwerty
    Jul 22, 2010 at 0:56
1

Powershell:

$cred = get-credential Domain\AdminAccount
(gwmi -co %Computername% Win32_OperatingSystem -cr $cred).Shutdown()

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .