0

I use below coding to open an application. The PClist has list of all IP address of the remote PCs that I want to execute the program and an dummy IP 0.0.0.0 at last to trigger the program execution at the master.

@echo off
setlocal enableextensions enabledelayedexpansion
st b="C:\Program Files\TeamViewer\TeamViewer.exe"
For %%B in (%b%) do (
    Set c=%%~dpB
    Set d=%%~nxB
)
for /f "tokens=*" %%a in (C:\COST\PCList.txt) do (
IF %%a equ 0.0.0.0 (
cd %c%
"%d%"
) ELSE (
ping %%a -n 1 -w 100
IF errorlevel 1 (
ECHO REMOTE %%a IS NOT REACHABLE
) else (
psexec \\%%a -i -d -s cmd /c cd %c%
psexec \\%%a -i -d -s cmd /c "%d%"
)
)
)

My problem is that when I run the above batch file the application opens and also an empty cmd console is open at background in the Master as well as slave PCs. It doesn't close until I close the launched application*(In this case Teamviewer)* or the directly the console window.

Is there any way to make the console window to close automatically?

0

I Found the answer. I changed the coding as below updated one and it works as I wanted it to. The trick was to use start as below syntax to run the application and close the console using exit.

@echo off
setlocal enableextensions enabledelayedexpansion
st b="C:\Program Files\TeamViewer\TeamViewer.exe"
For %%B in (%b%) do (
    Set c=%%~dpB
    Set d=%%~nxB
)
for /f "tokens=*" %%a in (C:\COST\PCList.txt) do (
IF %%a equ 0.0.0.0 (
cmd /s /k "cd %c% && start "" "%d%" && exit"
) ELSE (
ping %%a -n 1 -w 100
IF errorlevel 1 (
ECHO REMOTE %%a IS NOT REACHABLE
) else (
psexec \\%%a -i -d -s cmd /s /k "cd %c% && start "" "%d%" && exit"
)
)
)
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.