Windows shutdown not working as expected - windows

I'm trying to remotely shutdown computers in my lab with the commands:
shutdown /s /m 192.168.1.57
shutdown /s /m 192.168.1.56
Shutdown occurs properly when I run each command separately. But when I combine them via:
shutdown /s /m 192.168.1.57 & shutdown /s /m 192.168.1.56
only one machine shuts down, then Windows gives an error:
The entered computer name is not valid or remote shutdown is not supported on the target computer. Check the name and then try again or contact your system administrator.(53)
Any ideas how to troubleshoot/resolve?
same issue occurs when I combine the commands in a batch file.
systems all running Win 7, connected to the same workgroup.
bear in mind that I am not an IT professional.
Thanks in advance.

Another forum pointed me to a workaround/correct implementation. I just need to put a "cmd /k" between the & and the 2nd command. Still not sure why my ampersand combination didn't work.

there is nothing like (&) to combined the command.. I don't think you can do it like this.
You have to write the address with separate shutdown command. CMD doesn;t provide such a way to concatenate or pass array or arguments..

Related

Stuck in cmd script loop

I'm using a script that, upon logging in, loads Remote Desktop Protocol (RDP) and pushes the user to a Virtual Desktop Environment (VDI), along with their credentials. The script does not allow the next command 'Shutdown /l' to run until it is finished running.
The problem I'm having is that once in the VDI, RDP tries to load up again. How do I prevent this from happening? Thank you in advanced.
start /wait \\ph-vda\C$\VDI_Users_RDP\%username%.rdp /multimon /noConsentPrompt
Shutdown /l
I think what you're describing is that the same script is running when the user logs in, even when they log into the VDI. You don't want the script to run in the VDI. If that's right, here's one idea.
#echo off
if exist "%userprofile%\in_vdi" goto :eof
type nul >"%userprofile%\in_vdi"
start /wait \\ph-vda\C$\VDI_Users_RDP\%username%.rdp /multimon /noConsentPrompt
del "%userprofile%\in_vdi"
Shutdown /l

application loader / window builder

Long time reader of posts first time posting, firstly thanks for a great site I couldn’t do my job without this site half the time.
My question is I currently have a batch file that I run on our clients that maps network drives copy files from the server to a Ram drive
And then runs the application code below. What I need to do is replace this with a nice looking GUI window. I have looked at some task automation apps (vtask studio, winautomation, visual cron) but none have the ability to create a window.
Ideally the start up would go something like, welcome to loader ping the server if it gets a reply then continues with the file copy a progress bar would be great.
Essentially build a nice looking application loader I’m running window 7 pro on the clients Windows server 2008 R2 for the server.
Any and all suggestions gratefully received thanks in advance !
Code:
:START
#echo off
TIMEOUT /T 15
NET USE m: /delete
NET USE n: /delete
NET USE n: \\SERVER\Apps
NET USE m: \\SERVER\Media
NET USE l: \\SERVER\Logs
MD d:\Apps
XCOPY n:\*.* d:\Apps\ /Y /H /E /B
TIMEOUT /T 5
mklink /D C:\Apps D:\Apps
TIMEOUT /T 5
START /MIN /WAIT "Launcher" "C:\Apps\shortcuts\Launcher.Lnk"
START /MIN E:\PY.BAT
TIMEOUT /T 10
START /MIN "reader" "C:\Apps\shortcuts\Reader.Lnk"
TIMEOUT /T 5
:LAUNCH
ECHO %Time% %Date% "Launching Application" >>"%MyLogFile%"
START /MIN /WAIT "Launcher" "C:\Apps\applications\Launch.lnk"
GOTO LAUNCH
You can do ALL of these steps in a single vTask script.
Mounting / unmounting network drives, copying files, and even displaying simple GUIs that you control.
Certainly there is a progress bar command and it works well.
vTask is probably the easiest way to build a simple GUI, put actual code behind it (including SQL etc.) and even call .DLLs if needed.
Paul
I know that VisualCron (that you mentioned) has the Popup Task which can ask questions or provide information in a window before doing somethign (like starting a Task) with any parameters you supply in that window.

Windows shutdown-script: unexpected behavior

I wrote a little script which would prompt me for an input, save that input to a text file and shutdown the PC afterwards.
This is what the code looks like:
#ECHO OFF
set /p input=Insert text:
echo %DATE%: %input% >> text.txt
echo The system will shutdown...
shutdown -s -f -t 3
When I execute the batch, it prompts me and saves the input correctly, but after displaying The system will shutdown... it doesn't shut down, instead it starts over again promting me for input.
Does anyone know what causes this behavior?
May I ask the name of your batch file? If it is named shutdown.bat it is likely getting called again rather than executing the shutdown command. Try renaming your batch file if you would please.
The only thing I can see that might be wrong is that you are using -'s for the shutdown switches, which is correct in (I think) XP, but in Win7 (not sure about Vista) shutdown /? says to use /'s.
shutdown /s /f /t 3

Hide CMD window after using START to run a network application

I have an application that is run over a network. I need to be able to run this application from a batch file, and had ended up using this:
pushd \\server\folder
start /wait program.exe
Aside from the message saying...
\\server\folder
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
...it works fine, but the CMD window lingers. I know that /wait is the cause, but it appears that I can only get the program to run successfully if I use /wait. If I remove /wait, then I get bizarre errors from the program about not being able to start successfully.
What else might there be that I can try?
If you want to hide the program while it runs, you can also use the /MIN param, to have it start minimized.
Try:
start /b /wait program.exe

Why does batch file FOR fail when iterating over command output?

I have a batch file that uses this idiom (many times) to read a registry value into an environment variable:
FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "HKLM\SOFTWARE\Path\To\Key" /v ValueName') DO SET MyVariable=%%B
(There's a tab character after delims=)
This works fine on thousands of customer's computers. But on one customer's computer (running Windows Server 2003, command extensions enabled),
it fails with 'REG QUERY "HKLM\SOFTWARE\Path\To\Key" /v ValueName' is not recognized as an internal or external command, operable program or batch file.' Running the "reg query" command alone works fine. Reg.exe is present in C:\Windows\System32.
I was able to work around the problem by changing the code to
REG QUERY "HKLM\SOFTWARE\Path\To\Key" /v ValueName > temp.txt
FOR /F "tokens=2* delims= " %%A IN (temp.txt) DO SET MyVariable=%%B
This got the customer up and running, but I would like to understand why the problem occurred so I can avoid it in the future.
Slightly off the primary topic - a more direct way to get a registry value (string or DWORD) into an environment variable would also be useful.
I would check:
The customer's role on the machine - are they an admin?
Where is reg.exe on the box - is there more than one copy of copy of reg.exe in the path?
Is there any locale difference on the customer's machine from the machines where this normally works?
Basically, enumerate everything that differs between this machine and machines where it works as expected. Include service packs, domain membership, etc.
Wow, that is odd.
If the same commands work when split into two lines, then I'd guess it has something to do with the way the command gets run in a subshell in the FOR command.
If you were really dying to figure out why it's dying in this particular case, you could run commands like "SET > envvars.txt" as the FOR command and compare that with the top shell.
Or maybe start off simple and try running the REG command via CMD /C to see if that does anything?
One quick guess here, what's the values of COMSPEC and SHELL ?
I had a similar situation to this. In my case it was a bad value in COMSPEC. I fixed that and the script started working as expected.
The /F switch needs command extensions to be turned on. Usually they are turned on by default, but I'd check that. On XP systems you can turn them on doing something like
cmd /e:on
or checking the registry under
HKCU\Software\Microsoft\Command Processor\EnableExtensions
Dunno about Windows Server.
Doing help for and help cmd could provide some hints as well.

Resources