I can't get a batch file to display

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
JBL1954
Posts: 6
Joined: 09 Nov 2011 10:23

I can't get a batch file to display

#1 Post by JBL1954 » 09 Nov 2011 10:33

Hopefully this makes sense. I've created a batch file that works fine. Basically it shuts down the computer but also prompts you to stop it if you wish. When I run it from Windows Explorer I can see the echoed statements and dos prompt and the shutdown screen. So I can via the the dos prompt stop the shutdown from happening. When I run it via the Task Scheduler (Windows XP) I get the shutdown screen but, not the echoed statements or the dos prompt. I have to bring up the command prompt manually and stop it from there. Is there any reason it would run differently.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: I can't get a batch file to display

#2 Post by Ed Dyreen » 09 Nov 2011 15:47

'
You may want to check out the AT /? command, it allows batches to run under system account, so you'll always see the CMD window !

JBL1954
Posts: 6
Joined: 09 Nov 2011 10:23

Re: I can't get a batch file to display

#3 Post by JBL1954 » 09 Nov 2011 17:09

The AT command. I've googled it and it said - Enables users to schedule tasks to be performed at a specified time and date. I guess I probably didn't word my question correctly. The task is running fine. I don't know in-depth programming to figure out why I can't see the dos-part of the batch file running. I figured I was just missing something simple. I'm sure it is a simple fix. I wish I could post a picture of what I'm talking about. I can only assume that since it is a batch file running DOS, I won't see it when I bring it up via the Task Scheduler. But, it just tickles me that I can run the file by clicking on it and see the Shutdown dialogue box (Shutting down in xx minutes) and also see the DOS dialogue box (enter 'y' to abort shutdown).

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: I can't get a batch file to display

#4 Post by Ed Dyreen » 10 Nov 2011 00:30

'
I believe the reason you see it running when clicked is because it runs under your account, schtasks runs either under user account or administrator but is not always visible and may need runas command. You can see in task manager whether process is running under what account. Schtasks also provides info on run succes/failures...

I think you have a user privilege issue :o

Here's an example of a code batch that will definitely be visible:

The sheduler code:
DO_AT.CMD

Code: Select all

   set "?=1sthMonth.CMD"    &set /p "?=  :/ !?!    "<nul
   ::(
      at 00:00 /interactive /every:1 "!FullPath.SOURCE!\!?!"
   ::)

   set "?=Saturday.CMD"    &set /p "?=  :/ !?!    "<nul
   ::(
      at 00:00 /interactive /every:za "!FullPath.SOURCE!\!?!"
   ::)
The batch that is sheduled to run (my configuration):
Saturday.CMD

Code: Select all

set "FullPath=!Drive.PRGM3TH!\SYS\CFG\SchTasks\Saturday"
::
Pushd "!FullPath!\" &&(
   ::
   for /f "tokens=*" %%! in (

      '2^>nul dir /a:-d /b "*.CMD"'

   ) do (
      set "File=%%!"
      set "FullPathFile=!FullPath!\!File!"
      ::
      echo. &set /p "?=  :/ !File!..." <nul
      ::^(
         start "!File!" /low /wait "!FullPathFile!"
      ::
      set /p "?= [OK]" <nul &echo.
      ::^)
      echo.>nul
   )
::
popd
)
1sthMonth.CMD

Code: Select all

set "FullPath=!Drive.PRGM3TH!\SYS\CFG\SchTasks\1sthMonth"
::
Pushd "!FullPath!\" &&(
   ::
   for /f "tokens=*" %%! in (

      '2^>nul dir /a:-d /b "*.CMD"'

   ) do (
      set "File=%%!"
      set "FullPathFile=!FullPath!\!File!"
      ::
      echo. &set /p "?=  :/ !File!..." <nul
      ::^(
         start "!File!" /low /wait "!FullPathFile!"
      ::
      set /p "?= [OK]" <nul &echo.
      ::^)
      echo.>nul
   )
::
popd
)

The AT command can do things schtasks won't do AND vice versa !
This batch will run visible, even when you are logged off or hibernated !
I still think you are describing a very well known phenomenon :?

JBL1954
Posts: 6
Joined: 09 Nov 2011 10:23

Re: I can't get a batch file to display

#5 Post by JBL1954 » 10 Nov 2011 08:39

Thanks for the input but, everyone is pretty much talking over my head. First it is not a user issue. I am doing everything from the admin login so I don't think that is the issue. There are a lot of ways to do things and I was just trying to do it the easy way. I usually pick up bits and pieces from doing searches on the internet so I am not a programmer in any sense of the word. Let me try again to explain it a different way. Here is the batch file.

@echo off
echo.
echo Shut down commencing.....
shutdown -s -t 600
echo.
echo.
echo If you wish you can stop the shut down.
echo.
echo Do you want to stop the shut down?
set /p choice=y/n
:pick
if %choice% == y Goto Shutdown
if %choice% == n Goto end
goto pick
:Shutdown
shutdown -a
:end

When I run this batch file from windows explorer I can see the System Shutdown dialogue box (The system is shutting down. Please save all work.......) and I also see the C:\Windows\system32\cmd.exe dialogue box with the echoed statements and the prompt for the y/n from the batch file.

When I run it as a task (Start>Control Panel>Scheduled Task), all I see is the System Shutdown dialogue box and that is it. At this point it is not a big issue because I'm in bed so I wouldn't need to shut it down anyway. And also I gave myself enough time (10 minutes) I can stop the shutdown manually from the command prompt if I happened to be working at the time.

JBL1954
Posts: 6
Joined: 09 Nov 2011 10:23

Re: I can't get a batch file to display

#6 Post by JBL1954 » 10 Nov 2011 15:00

I guess I may have to get a 'Programming for Dummies' book and play around with it. I've tried in the past but, it is like learning another language. Most books were way to simplistic and others were way to advanced so I got overwhelmed and gave up.

JBL1954
Posts: 6
Joined: 09 Nov 2011 10:23

Re: I can't get a batch file to display

#7 Post by JBL1954 » 10 Nov 2011 20:52

Many thanks Ed :o I realized what you were telling me and actually got the thing to work the way I needed it to.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: I can't get a batch file to display

#8 Post by Ed Dyreen » 11 Nov 2011 04:34

'
That's good, now you'll probably believe me when I tell you MS did this on purpose, and for good reasons.

JBL1954
Posts: 6
Joined: 09 Nov 2011 10:23

Re: I can't get a batch file to display

#9 Post by JBL1954 » 11 Nov 2011 08:23

Thanks again. It's not that I didn't believe you it just took awhile for the light to go on in my head :lol: But, I'm sure there is probably some truth in what you are saying about MS.

Post Reply