Search code examples
batch-filevbscriptlockscreen

My Batch file wont continue while windows is locked


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.


Solution

  • 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.