• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 673
  • Last Modified:

Running .Bat and .cmd files from network shares

Dear All,

I have a problem whic I'm sure should be easy to clear up. I have written a very simple batch file to launch a program at login. When I test the batch file locally on the machine it runs perfect, runs once, does what it is supposed to do and finishes, simple... so I thought. I then copied the batch file to a network share to make it available to all users. When I run the batch file from a network share it just keeps looping. The dos box opens as it should and the command just keeps looping, never stopping. The command being issued just updates the schedule on a poweroff program we use to shutdown all client machines every evening. Checkout http://users.telenet.be/jbosman/poweroff/poweroff.htm

Has anyone ever seen this happen before with a batch file?? Any help would be greatly appreciated.

Regards,

Kevin
poweroff -warn -warntime 180 -msg "WORKING NOW" -playsound -soundfile "c:\windows\media\ringin.wav" -force -scheduled -time 10:08 -days m,t,w,th,f -save_svc_set

Open in new window

0
DUB_IT
Asked:
DUB_IT
  • 3
  • 3
  • 2
  • +1
1 Solution
 
theras2000Commented:
I know that batch file commands sometimes have trouble running from a UNC share path.  In fact I think they're officially nto supposed to, but sometimes they do.
Perhaps if you just change to the c: prompt in the 1st line of the batch file.  I'm going to go test and confirm this for you now.
0
 
theras2000Commented:
Well this is what happened to me...  Normally when you run a batch file, it tries to make the working directory the path of the batch file e.g. \\pcname\sharename in your case.  However, as a UNC path can't be your prompt in DOS, it reverts you to your local profile instead e.g. C:\Documents and Settings\johndoe.  And of course, your poweroff program doesn't live in that folder, so it doesn't get run.
The easiest way to check this for yourself is to use the command 'pause' on line 2.  Then the DOS screen will pause and you can see if any errors are on the screen (on mine it showed the problem with changing to the UNC path name).
0
 
KOTiSCommented:
Try to run it with START

start "poweroff -warn -warntime 180 -msg "WORKING NOW" -playsound -soundfile "c:\windows\media\ringin.wav" -force -scheduled -time 10:08 -days m,t,w,th,f -save_svc_set"

Open in new window

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
theras2000Commented:
Now if that is true for you, then you should be able to just modify your command to this:
\\pcname\share\poweroff -warn -warntime 180 -msg "WORKING NOW" -playsound -soundfile "c:\windows\media\ringin.wav" -force -scheduled -time 10:08 -days m,t,w,th,f -save_svc_set 

Open in new window

0
 
Steve KnightIT ConsultancyCommented:
Is your batch file called poweroff.cmd or poweroff.bat.... sounds like it is getting to the point when it runs poweroff.exe and you are re-running your batch file?!

Steve
0
 
Steve KnightIT ConsultancyCommented:
i.e. call your batch file something else if so...
0
 
DUB_ITAuthor Commented:
Hi Guys, thanks for all the suggestions, I'm going to look at it now and see what I can find
0
 
DUB_ITAuthor Commented:
Oh I called it poweroff.cmd AND poweroff.bat to see if either or the extensions made a difference and it did not. I am going to try and rename it to something like test.cmd and also try the option of changing to the c:\ before it runs
0
 
DUB_ITAuthor Commented:
Hi Guys, thanks for your input. I think I have it sorted. I need to cd to the directory poweroff.exe is in before the command initiates. This worked straight away. Thaks for your thoughts, they steered me in the right direction.

Very much appreciated.

Regards,

Kevin
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now