Thodoris Alexopoulos
Thodoris Alexopoulos

Reputation: 37

i want to run a batch script into my pc when it is locked

i want to run a batch file on my pc for an overnight activity. The problem is that i can't do that because the pc is locked.

I am using this code:

@echo off      
tasklist /FI "IMAGENAME eq \\Desktop\notepad.exe" | find /i "\\Desktop\notepad.exe"      

IF ERRORLEVEL 1 GOTO LOOP1
IF ERRORLEVEL 0 GOTO EXIT 

:LOOP1 
  start notepad.exe 
goto EXIT 

:EXIT

and it works only the pc is unlocked.

Any help will matters.

Upvotes: 2

Views: 2629

Answers (1)

user7818749
user7818749

Reputation:

Create a new Scheduled Task. Set the task to run when user is logged in or not. Then set the interval of your task time.

On Windows 8 etc you are able to set triggers on when the task should be kicked of by using either a set time or when PC goes on idle, when an event occurs etc. There is also an option for On Workstation Lock

If this is not your intention to use scheduler. Then right a script that runs in a permanent loop by adding some sleep time and only rerun the taks every now and again, something like this (untested, just used yours as example)

:START
@echo off      
tasklist /FI "IMAGENAME eq \\Desktop\notepad.exe" |find /i "\\Desktop\notepad.exe"      

IF ERRORLEVEL 1 GOTO LOOP1
IF ERRORLEVEL 0 GOTO EXIT 

:LOOP1 
  start notepad.exe 
  timeout 300
  goto START

timeout 300 is basically sleeping the script for 300 seconds and will start from START again. We can then run the batch file before locking the PC and it wil lrun in a continuous loop. Even though it might not be the right way, it is an option. Perhaps some more detail around how often the batch file should run?

Upvotes: 2

Related Questions