1.

Solve : Problem with %%parameter with script that was just working?

Answer»

I feel like I'm going crazy. This script just worked a few minutes ago and now its not. Here is my script, the purpose is to shutdown computers that are named in a list

FOR /F "tokens=1" %%i IN (list.txt) DO SHUTDOWN /m \\%%i /s /t 001

here is the contents of list.txt

CHE1Q8HRD1
CHE329LGD1
CHE3Q8HRD1
CHE3T8HRD1
CHE55BGRD1
CHE5PRQRD1
CHE5R8HRD1
CHE629LGD1

If I try to run the batch file it scrolls like crazy until it force closes. If I type it into CMD from the folder I get ' %%i was unexpected at this time'. I've tried a few different variables to no avail.

EDIT: If I right click the batch file and Run as Administrator I get a 'The system cannot find file" error, but the path is c:\Windows\SYSTEM32 so I guess thats why that errors out

EDIT Again: I put the list.txt in the c:\Windows\System32 folder and the script worked finally. I guess its a permissions problem and I can work around that. Not sure why it worked a few minutes ago and not now though.You have a null value. During the run of the batch some item or device got changed.
You are using showdown to turn off other computers? That can cause unelected problems.What if the target machine is already off?
Yes, I work for a school and at the end of the week I want to remotely turn off all computers in my labs with the script. If the computer is off or unreachable, it shows a 'name is not valid...' error and just skips it so thats not a big deal.

Still unsure how to FIX my problem but I think its something with my 8.1 installation. Even though I'm administrator sometimes I have to run as or am prompted for administrator rights and I have to click continue. If I run the script with the list.txt in same folder, it doesn't work. If I still that same exact list.txt in the system32 folder and Run As Administrator on the script, then it WORKS perfectly. So again, same script, same list.txt so I dont know what value is null. Thanks for your help though.What did you name the batch file?shutdown.bat and also i have one for restart.bat.Quote from: indigoataxia on February 12, 2014, 07:43:13 PM

shutdown.bat

There you go.
So it's as simple as commands can not be the name of the script? No, it does not hurt the command. The command will work
But the script or batch must not be the name of any program or built-in command.
Example:
In the same directory I have:
ring.exe
ring.bat

Preferences is to the EXE.Quote from: indigoataxia on February 13, 2014, 02:04:39 PM
So it's as simple as commands can not be the name of the script?

You are trying to call shutdown.exe from a script called shutdown.bat.

You are not using extensions. Just "shutdown".

The command interpreter works like this when running a script - when it finds something that might be a command, it first of all looks in the current directory for a file or script with that name, If there are more than one, extensions take priority in this order listed in the %pathext% system variable, default value: .com; .exe; .bat; .cmd (even in 64 bit Windows .com is first!). If none are found, then the command interpreter looks, in turn, in all the folders listed in the %path% environment variable, using the %pathext% order.

So if you don't use extensions, shutdown.bat in the same folder is going to take priority over shutdown.exe on the %path%. Shutdown.bat is going to call itself. The real Shutdown.exe will never get executed.

Solution: In your batch, use shutdown.exe or even better C:\Windows\system32\shutdown.exe or better still, don't name your batch the same as a Windows command. It makes life easier.





I 100% understand now. It was looping and erroring out because it kept calling itself endlessly. I will rename the script. Thanks a lot guys!


Discussion

No Comment Found