Categories
Welcome Center
Education & Development
Cyber Security
Virtualization
General
Certification Preparation
Project Management
Posts
Groups
Training Resources
Infosec
IT & Security Bootcamps
Practice Exams
Security Awareness Training
About Us
Home
General
Off-Topic
batch file help
SephStorm
I have a batch file that is supposed to shut down a remote server. The command is shutdown /s /f /t 0 /m \\SERVERNAME
Now if I post this in a cmd window it functions properly, but I cant get the batch file containing only this string to execute by clicking on it. It repeats on the screen and never shuts off the server. Any idea how to get this to work properly? I'm thinking I need to have some sort of stop command to end the script without running again, but i'm not sure.
Find more posts tagged with
Comments
techfiend
@echo
off
shutdown /s /f /t 0 /m \\SERVERNAME
exit
Works fine here, does it work there?
@echo
off shouldn't be needed in this case but it's pretty much the header of all batch scripts, to quiet it down a bit. Exit should automatically be invoked at EOF, it also shouldn't be needed.
SephStorm
No dice, with echo on this is what I get.
https://imgur.com/7xS6D9y
Echo off doesn't help much.
tecke
What did you name the bat file?
Adam B
The file is probably not executable. I'm guessing it's maybe a .txt? Change the file type to .bat.
SephStorm
its shutdown.bat
tecke
I believe that this^ is your problem. Shutdown.bat is calling itself over and over again and not calling the expected shutdown command... Try renaming the bat file.
SephStorm
Strangely enough that works, however now it causes what I can only assume is an unexpected shutdown. The PC reboots when it shutsdown. Thoughts?
PJ_Sneakers
The batch file was calling itself. You weren't specifying shutdown.EXE (or a path to the executable), so shutdown.bat was launching itself over and over again. When you call a command it will look first in the current folder and execute what's there before it looks for it in the PATH variable.
Are you saying that the PC you're running the BAT on is rebooting? Or the server?
SephStorm
Sorry, the server.
PJ_Sneakers
That's weird. Double check to make sure there's not a /R in the batch file. Check the server's BIOS settings and see if it has a section related to power loss (like power on, stay powered off). Sounds like a weird hardware/BIOS thing. Check for an updated BIOS that possibly fixes power issues maybe?
olaHalo
I remember having this same issue lol.
Really frustrating
You cant name the bat the same name as a command.
SephStorm
FYI, the reboot must have been a random event, it does shutdown properly since then.
Quick Links
All Categories
Recent Posts
Activity
Unanswered
Groups
Best Of