I have a batch file which calls other programs to open and run.
I want this batch file to run overnight while my computer is locked. I use Windows Task Scheduler to run this program overnight. The batch file runs fine except when it gets to start Check1.msl. Then windows can't seem to find that file. When I unlock my computer and manually execute the batch file, it has no problem finding and running those files.
Here is my code:
#echo off
Start Check1.msl
PING 1.1.1.1 -w 1000 -n 1
start passwordinjector.vbs
IF EXIST C:\Users\Username\Desktop\New folder\check.rpt (
taskkill /IM MAINRDW.exe >nul
PING 1.1.1.1 -w 500 -n 1
Start Trial.msl
PING 1.1.1.1 -w 1000 -n 1
start passwordinjector.vbs
Del C:\Users\Username\Desktop\New folder\check.rpt
) ELSE (
PING 1.1.1.1 -w 500 -n 1
taskkill /IM MAINRDW.exe >nul
)
EDIT:
I've been trying it out for awhile now. To test it, I simply use Windows Task Scheduler to run it a minute out then lock my computer and wait for the Scheduler to kick in.
Here is what I have so far:
#echo off
cd /d "%~dp0"
PING 1.1.1.1 -w 2000 -n 1
echo starting the check1 msl file
Start Check1.msl
PING 1.1.1.1 -w 2000 -n 1
echo starting the password injector file
WScript //B passwordinjector.vbs
IF EXIST C:\Users\USERNAME\Desktop\New folder\check.rpt (
echo check if the check exists
taskkill /IM MAINRDW.exe /f >nul 2>&1
PING 1.1.1.1 -w 2000 -n 1
echo It does exist, so run the next Trial msl
Start Trial.msl
PING 1.1.1.1 -w 3000 -n 1
WScript //B passwordinjector.vbs
Del C:\Users\USERNAME\Desktop\New folder\check.rpt
) ELSE (
PING 1.1.1.1 -w 1000 -n 1
it doesnt exits
taskkill /IM MAINRDW.exe /f >nul 2>&1
)
exit
It is very hard to troubleshoot batch files. If anyone has any suggestions, I would appreciate it. Through trial and error, I figured out (still not sure) that it wasn't executing the .vbs script. So I looked it up online from Microsoft's developer network and got the syntax WScript //B.
EDIT2:
I put a pause into the code to break it down and make sure it is doing what it is supposed to do. Its not.
The Check1.msl will spit out a file named check.rpt. When i run it manually and the batch file pauses - check.rpt is there. I schedule the task and lock my computer. When I log back in, the msl program is open and the cmd prompt is sitting at pause but there is NO check.rpt file.
Here is what I have at the beginning:
#ECHO OFF
PUSHD "%~dp0
ECHO CD is now %CD%
PING 1.1.1.1 -w 2000 -n 1
echo starting the check1 msl file
DIR Check1.msl
Start Check1.msl
PING 1.1.1.1 -w 2000 -n 1
echo starting the password injector file
WScript //B passwordinjector.vbs
pause
I've tried cscript passwordinjector.vbs to no avail.
The .bat script can make the current working directory to be the one in which it is located by:
PUSHD "%~dp0"
Remember to POPD before exiting.
#ECHO OFF
PUSHD "%~dp0"
ECHO CD is now %CD%
DIR Check1.msl
START Check1.msl
...
It seems like the issue lies in the VBScript. I use .sendkey to inject the password. This is retricted while the computer is locked; so I'm out of luck.
Related
I have a command that watches a certain folder for new files. These files are created by a video transcoder so are locked and keep growing in size till completion.
#echo OFF
:loop
if exist "E:\OUT\*.mxf" (
for %%i in ("E:\OUT\*.mxf") DO (
C:\bmx\bmxtranswrap -o "E:\DPP_create\DPP_OUT\%%~ni.mxf" -t as11op1a -y 09:59:50:00 --afd 10 "%%i"
ping -n 5 localhost >nul
del "%%i"
)
)
ping -n 5 localhost >nul
goto :loop
Is there a way to only pick up files which are fully completed (Windows unlocked)? At the moment the next command is tripping up as it is attempting to open an incomplete file.
Any advise? Thanks.
As long as you are correct in that your transcoder has the file locked until it is complete, then the solution is actually simple.
Use redirection to test that you can open the file for writing, but don't modify it. Only process if the redirection succeeded.
Note:
You don't need your outer IF statement.
You can use an infinite FOR /L loop instead of a GOTO loop
I don't understand why you need a delay before your DEL, but I preserved it anyway.
#echo OFF
for /l %. in () do (
for %%i in ("E:\OUT\*.mxf") do 2>nul( (call )>>"%%i" ) && (
C:\bmx\bmxtranswrap -o "E:\DPP_create\DPP_OUT\%%~ni.mxf" -t as11op1a -y 09:59:50:00 --afd 10 "%%i"
ping -n 5 localhost >nul
del "%%i"
)
ping -n 5 localhost >nul
)
So, I have a bat file I've been building to do a simple profile backup/restore. I'm running Windows 7 64bit.
I get through 99% of the script until it gets to this point and then dies. To be clear, in the environment I'm working in, I HAVE to turn off UAC for certain things. Someone much higher up than me made that call.
However, this needs to do this but it dies after the "[ COMPLETE ]" is echoed. It doesn't close the window, it just goes back to the C prompt.
The only other thing it's going (trying) to do after that is log the user off after a 15 second timer.
Any help would be much appreciated.
echo [ Turning off UAC... ]
C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f
ping -n 2 -w 1000 127.0.0.1 > nul
echo [ COMPLETE ]
ping -n 2 -w 1000 127.0.0.1 > nul
echo.
ECHO ==========================================================
ECHO = Restore Complete =
ECHO = Computer will logoff in 15 seconds to apply changes. =
ECHO ==========================================================
TIMEOUT 16
shutdown /l
#pause
:EOF
I made a test batch file that does what you're trying:
#echo off
echo before
cmd /k echo I'm doing it!
echo after
And here was the result:
C:\files\j>test
before
I'm doing it!
So I changed it to call:
#echo off
echo before
call echo I'm doing it!
echo after
And got this:
C:\files\j>test
before
I'm doing it!
after
So clearly, /k isn't for you. But CALL will put it in a new shell... So my recommendation is to just change that line to be :
%windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f
No cmd, no \k, no anything - just run the REG.exe.
If you have to, use the CALL since you're adding a registry key and it should stay there.
I have a LAN with 4 PCs and one Synology server.
I wish that every time a computer is turned off, it runs a batch (from windows pc) and see if other PCs are on, - if any is on do nothing, - otherwise runs a command that shuts down the server.
Here is what I have at the moment:
#echo off
PING 192.168.1.10
IF %ERRORLEVEL% EQU 1 plink root#192.168.1.10 -pw MYPASSWORD poweroff
But I would like to do something like:
http://i.imgur.com/BLAVCBt.png
THANK YOU!!
No need to do it from client-side.
I would do it on server-side: check if at least one client is up, if not then shutdown (basically a one-liner):
(ping -4 Client1 & ping -4 Client2 & ping -4 Client3 & ping -4 Client4) |find "TTL=" >nul || shutdown -s -t 60 -f -c "Shutdown because all clients are down"
Create a scheduled task on the server that runs this script - let's say all 5 minutes. The timeout gives you enough time to abort the shutdown (shutdown -a) in case you are working on the server.
first you should schedule a shutdown batch.. follow these steps to run the batch when you shut down..
https://technet.microsoft.com/en-us/magazine/dd630947.aspx
The batch looks fine.. but if you want to do nothing in the first case and shutdown in the second case use it like this:
#echo off
PING 192.168.1.10
IF %ERRORLEVEL% EQU 1 plink root#192.168.1.10 -pw MYPASSWORD shutdown -s -t 00
So the statement "do nothing" is deleted and the poweroff command is shutdown -s -t 00
for %%a in (pc-1 pc-2 pc-3 pc-4) do if /i "%computername%" neq "%%a" ping %%a&if not errorlevel 1 goto :eof
echo shut-down-the-server-code
That way, you ping until you find a PC that's on, skipping your own (which is obviously on). If any are found on, just terminate the batch by jumping to end-of-file. If all are off (other than yours, obviously) then shut down the server and shut down your PC.
http://ss64*org/viewtopic.php?pid=8188
http://stackoverflow*com/questions/28304099/batch-script-to-ping-other-pc-in-my-lan-and-shutdown-together-last-online-pc
http://wwwmsfnorg/board/topic/173438-shutdown-last-running-pc-on-the-lan-with-server/
http://forum_synology*com/enu/viewtopic.php?f=145&t=96609
http://www_dostips*com/forum/viewtopic.php?f=3&t=6245
I think last one will be more easy to use thank you for the answer!
#echo off
set "flag="
ping 192.168.1.1 -n 2 |find /i "TTL=" >nul && set flag=1
ping 192.168.1.2 -n 2 |find /i "TTL=" >nul && set flag=1
ping 192.168.1.3 -n 2 |find /i "TTL=" >nul && set flag=1
ping 192.168.1.4 -n 2 |find /i "TTL=" >nul && set flag=1
if not defined flag echo shutdown server
I want to run command line with patameters to make it wait for connection then do "gpupdate /force" and then nofity user the job is done. The thing I am stuck at is making it wait for connection.
cmd /c echo Connect a network cable. & *something* & echo n | gpupdate /force & msg * Done.
If something was following code then it would work:
:top
ping -n 1 site.com >nul
if errorlevel 1 (
goto top
)
but I don't know how would I write it on 1 line as a parameter.
How would I make it work the way I wish? Alternative solutions are welcome as well!
I don't understand your aversion to a batch script. But the following one liner should work.
#echo Connect a network cable.&cmd /q /c "for /l %N in () do ping -n 1 site.com >nul&&exit"&echo echo n^|gpupdate /force&msg * Done.
The key bit is cmd /q /c "for /l %N in () do ping -n 1 site.com >nul&&exit". A new CMD.EXE process is created that enters an infinite FOR loop. It continuously pings the site until it is successful. The EXIT command only executes when PING was successful because of the && operator. Once EXIT executes, control is returned to the parent CMD.EXE process.
Why not make it all a batch file?
#echo off
echo Connect a network cable.
:top
ping -n 1 site.com >nul || goto :top
echo Connected.
gpupdate /force
msg * Done.
I have this bat file to just kill and start the file, but I need a delay.
TASKKILL /F /IM "file.exe"
(what is the code to delay 1 minute before executing the code below?)
start /d "path" file.exe
Can you please help me? Thanks
You can use ping as #Krister suggested
ping 127.0.0.1 -n 60
of if you are using Vista and above you can use the much easier timeout
timeout /t 60
I have used the ping command to achive this, you could ping an invalid host and set the timeout for the command to your desired delay.
#echo off
ping 1.2.3.4 -n 1 -w 60000 >NUL
# this command will be run after 60000ms
echo 'running';
pause