Solved

Batch file shutdown while still at login screen

Posted on 2004-03-28
4
1,204 Views
Last Modified: 2011-10-03
I have a scheduled backup file that runs everynight as an unattended program that starts whithout loging into the system.  My problem is that after the backup I wish to shutdown the computer but the command below will not log off unless I am totally logged on as an account.  

Is there a way to add a shutdown command to a batch file that will shut down the computer without being logged on?

What I have that does not work is:

if %DayofWeek%==Sun   (
      echo Sunday Backup
c:
cd "c:\Program Files\stomp\backup MyPC"
start /wait bewin32.exe /Start SundayDiff
start /wait bewin32.exe /Start Sunday_EFGFull
c:
cd c:\windows\system32
call shutdown.exe -s -t 00 -c "Shutting Down NOW"
)

0
Comment
Question by:rronne
  • 2
4 Comments
 
LVL 59

Accepted Solution

by:
LeeTutor earned 50 total points
ID: 10705788
>call shutdown.exe -s -t 00 -c "Shutting Down NOW"

I use shutdown.exe in a shortcut that I can click on my Desktop when I want to shut down the computer.  I wonder if that "call" is necessary in the batch statement?  I seem to recall that "call" is supposed to be used in batch files to call batch subroutines... Try removing the "call" in the last statement and see what happens.
0
 
LVL 17

Expert Comment

by:Eagle6990
ID: 10707377
Also, what is the point of doing echos if no user is logged in to see it?

I can't find any proof right now because I can't run a sample script on my system here, but try removing call as Lee stated, but also remove .exe on shutdown.  I've seen this cause problem.
0
 

Author Comment

by:rronne
ID: 10710280
LeeTutor,
   I had in fact thought of that myself and have also now tried  -

if %DayofWeek%==Mon (
      echo Monday Backup
c:
cd "c:\Program Files\stomp\backup MyPC"
REM start /wait bewin32.exe /Start MondayDiff
c:
cd c:\windows\system32
shutdown -s -t 00 -c "Shuting Down NOW"

)

but still the shutdown will not perform if I run this while at the loggin.

PS  The echo command is only there so that I can see it for testing when I was actually logged on,  My batch file actually has and entry for each day of the week and I wanted to make sure it was going to the correct date.

0
 

Author Comment

by:rronne
ID: 10714321
LeeTutor,
   I don't know why my tests last night did not seem to do the shutdown, but today when I came down to my computer to check on the backup it was properly shutdown and since I did not do that I have to assume that the batch file ran correctly early this morning (1am).

  I had taken the Call out of the original shutdown line before I was trying your suggestion on a test file.  Anyway I will keep my fingers crossed that the following code seems to be working (at least it did early this morning)

@echo off
REM ***********************
REM extract current date
REM ***********************
cls
echo ---------------------
for /F "tokens=1-4 delims=/ " %%i in ('date /t') do (
set DayOfWeek=%%i
set Month=%%j
set Day=%%k
set Year=%%l
set Date=%%i   %%j/%%k/%%l
)

echo %Date%
echo ---------------------
echo %DayofWeek%
echo *********************
::****************************************************
:::::::::::::::   SUNDAY   :::::::::::::::::::::::::::
if %DayofWeek%==Sun   (
      echo Sunday Backup
c:
cd "c:\Program Files\stomp\backup MyPC"
start /wait bewin32.exe /Start SundayDiff
start /wait bewin32.exe /Start Sunday_EFGFull
c:
cd c:\windows\system32
shutdown.exe -s -t 00 -c "Shutting Down NOW"

)
::****************************************************
:::::::::::::::   MONDAY   :::::::::::::::::::::::::::
if %DayofWeek%==Mon (
      echo Monday Backup
c:
cd "c:\Program Files\stomp\backup MyPC"
start /wait bewin32.exe /Start MondayDiff
c:
cd c:\windows\system32
shutdown.exe -s -t 00 -c "Shutting Down NOW"


)
::****************************************************
:::::::::::::::   TUESDAY  :::::::::::::::::::::::::::
if %DayofWeek%==Tue (
      echo Tuesday Backup
c:
cd "c:\Program Files\stomp\backup MyPC"
Start /wait bewin32.exe /Start TuesdayDiff
c:
cd c:\windows\system32
shutdown.exe -s -t 00 -c "Shutting Down NOW"

)
::****************************************************
::::::::::::::: WEDNESDAY  :::::::::::::::::::::::::::
if %DayofWeek%==Wed   (
      echo Wednesday Backup
c:
cd "c:\Program Files\stomp\backup MyPC"
Start /wait bewin32.exe /Start WednesdayDiff
Start /wait bewin32.exe /Start WednesdayFull
c:
cd c:\windows\system32
shutdown.exe -s -t 00 -c "Shutting Down NOW"
)
::****************************************************
::::::::::::::      THURSDAY    :::::::::::::::::::::::
if %DayofWeek%==Thu   (
      echo Thursday Backup
c:
cd "c:\Program Files\stomp\backup MyPC"
Start /wait bewin32.exe /Start ThursdayDiff
c:
cd c:\windows\system32
shutdown.exe -s -t 00 -c "Shutting Down NOW"
)
::****************************************************
::::::::::::::      FRIDAY    :::::::::::::::::::::::
if %DayofWeek%==Fri   (
      echo Friday Backup
c:
cd "c:\Program Files\stomp\backup MyPC"
Start /wait bewin32.exe /Start FridayDiff
c:
cd c:\windows\system32
shutdown.exe -s -t 00 -c "Shutting Down NOW"
)
::****************************************************
:::::::::::::::   SATURDAY :::::::::::::::::::::::::::
if %DayofWeek%==Sat   (
      echo Saturday Backup
c:
cd "c:\Program Files\stomp\backup MyPC"
Start /wait bewin32.exe /Start SaturdayDiff
Start /wait bewin32.exe /Start Saturday_CDFull
c:
cd c:\windows\system32
shutdown.exe -s -t 00 -c "Shutting Down NOW"
)
::****************************************************
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

We have adopted the strategy to use Computers in Student Labs as the bulletin boards. The same target can be achieved by using a Login Notice feature in Group policy but it’s not as attractive as graphical wallpapers with message which grabs the att…
It is only natural that we all want our PCs to be in good working order, improved system performance, so that is exactly how programs are advertised to entice. They say things like:            •      PC crashes? Get registry cleaner to repair it!    …
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now