Search code examples
batch-filewindows-xpremote-desktopshutdown

Batch file to shutdown computer through remote desktop in Windows XP


I have a Windows Vista workstation that I use the majority of the time, but I occasionally need to remote desktop into a Windows XP workstation. Because of the differences in resolution, the start menu in my remote desktop session is not visible unless I either full-screen (which I like to avoid so I can still see the start menu and notification tray on my vista workstation) or scroll to the bottom (but I'm lazy!).

I decided to create a batch file to shutdown the Windows XP machine while using Remote Desktop into it. It's important that it have a prompt of some kind in case I were to somehow accidentally click it from the desktop.

Here's the batch file source:

pause

echo 1
shutdown /s /f
echo 2

Yet the file seems to loop at the shutdown command. Here's the output from the batch file:

C:\Documents and Settings\Kiley\Desktop>pause
Press any key to continue . . .

C:\Documents and Settings\Kiley\Desktop>echo 1
1

C:\Documents and Settings\Kiley\Desktop>shutdown /s /f

C:\Documents and Settings\Kiley\Desktop>pause
Press any key to continue . . .

It seems to loop like this over and over. I've googled the issue in hopes that this is a common problem with a workaround, but I cannot seem to find an explanation. I've tried using the /t switch as well (to specify time), as well as doing an exit command immediately after the shutdown, and it always seems to produce the same behavior as above.

I also tried creating a similar but different batch file like so...

@ECHO OFF

:choice
set /P c=SHUTDOWN[Y/N]?
if /I "%c%" EQU "Y" goto :do_shutdown
goto :choice


:somewhere

shutdown -s -f

But as soon as I type "y" and press enter, the batch file exits and the machine does not shutdown.

Does anyone have any thoughts, advice, or suggestions? The problem is of little importance, but now I'm just curious...

EDIT: It was suggested that I try using the "-" character to denote a switch instead of "/". This produces the same behavior. However, what's interesting is that I am able to run the following command in a command prompt from the XP workstation to correctly commence shutdown from a command prompt:

shutdown -s

I tried using the /m switch from my vista workstation, and the command prompt that pops up when double-clicking the batch file exits as soon as the shutdown command is issued. When I try running the shutdown command with the /m switch from the command prompt by itself, I get the following output:

C:\Windows\system32>shutdown /s /f /m \\WORKSTATION-V5
WORKSTATION-V5: Access is denied.(5)

Solution

  • In your first code snippet you used / for switches instead of - . Since you are remotely connected to the machine, all you would need to do is specify the code as follows:

    shutdown -s -f
    

    If you are allowed to send remote commands to the computer, instead of using remote desktop to manually access the machine, you can type the following command in YOUR command line and not the remote computer:

    shutdown -s -f -m \\computername
    

    EDIT:

    To create a DOS prompt for a shutdown via BATCH SCRIPT:

    :START
    SET /p sd=Would you like to shutdown? [ Y ] or [ N ]     :
    IF "%sd%"=="Y" GOTO:SHUTDOWN
    IF "%sd%"=="y" GOTO:SHUTDOWN
    IF "%sd%"=="n" GOTO:EOF
    IF "%sd%"=="N" GOTO:EOF
    ECHO Incorrect Answer... Please Try Again
    PAUSE
    GOTO:START
    :SHUTDOWN
    shutdown -s