Running script after windows machine is locked Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
wired137

Running script after windows machine is locked

14 Sep 2018, 11:08

I'm trying to get a script to run while a machine is locked. My script works fine when my machine is not locked. I'm using a standard windows 10 machine. My script is below.

When my machine is locked, the first part of my script executes (launching the 'program')

However, I'm expecting another window to be open while my machine is locked (this is where the ControlSend !f (Alt + F) comes in...then I hit s for the menu I want (called 'Searching), then hit Enter to bring up a new window)

Any suggestions on what could be the issue?

;DllCall("user32.dll\LockWorkStation")
;Sleep 2000
run C:\App.exe
WinWait, ProgramWindowTitle
Sleep 10000
ControlSend ,,!f, ProgramWindowTitle
Sleep 2000
ControlSend ,,s, ProgramWindowTitle
Sleep 2000
ControlSend ,,{Enter}, ProgramWindowTitle

Thanks for any suggestions!
wired137
Posts: 3
Joined: 14 Sep 2018, 11:13

Re: Running script after windows machine is locked

14 Sep 2018, 12:03

I'd like to add that removing WinWait didn't resolve this based on some documentation I found from AutoIT (I know, different software, but figured the logic applied the same)

I also know it can be done and this script below works on my workstation perfectly:

Code: Select all

Send #l
Sleep 2000
Run Notepad.exe
WinWait Untitled - Notepad
Sleep 400
ControlSend ,,{Shift Down}h{Shift Up}ello{control down}s{control up}, Untitled - Notepad
WinWait Save As
Sleep 300
ControlSend, Edit1, Hi ,Save As
ControlClick , &Save, Save As
Sleep 2000
WinClose ahk_class Notepad
garry
Posts: 3758
Joined: 22 Dec 2013, 12:50

Re: Running script after windows machine is locked  Topic is solved

14 Sep 2018, 14:11

not sure , some ideas
it's possible to run program if you're not admin
to write and save text can use the command 'fileappend'
a german example to send text to notepad and save

Code: Select all

#warn
setworkingdir,%a_scriptdir%
Settitlematchmode,2
SetKeyDelay,20,20

sc=ahk_exe notepad.exe
sk=ahk_class #32770
File=Test.txt
fpath=%a_scriptdir%\%file%
ifexist,%fpath%
   filedelete,%fpath%

IfWinNotExist,%sc%
 Run,notepad,,,pid2
IfWinNotActive ,%sc%,,WinActivate,%sc%
WinWaitActive,%sc%
Sleep 400
ControlSend ,,Hello{control down}s{control up}, %sc%
WinWait,Speichern unter                  ;- Save as (german)
Sleep 300
ControlSend ,,!n{Backspace}%file%,%sk%   ;- send name
sleep,1500
send,!s                                  ;- save file Test.txt
Sleep,2000
WinClose, ahk_pid %pid2%
WinWaitClose,ahk_pid %pid2%
msgbox,Saved =%file%`n%a_scriptdir%
return
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Running script after windows machine is locked

14 Sep 2018, 16:02

controlsend sends keystrokes which is strictly blocked by windows when locked. you're going to need a more "silent" method of interacting with your application like controlsettext or a COM interface
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
wired137
Posts: 3
Joined: 14 Sep 2018, 11:13

Re: Running script after windows machine is locked

18 Sep 2018, 18:16

Tank, can you provide an example of using ControlSetText with the original code I supplied or point me in the right direction? Can you also explain why the notepad script I pasted works fine when a windows machine is locked?
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Running script after windows machine is locked

19 Sep 2018, 16:21

your not doing anything in notepad as far as i see looking at your code. Maybe you shoulld just experiment with controlsettext. you dont need an example.
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
wired137
Posts: 3
Joined: 14 Sep 2018, 11:13

Re: Running script after windows machine is locked

21 Sep 2018, 15:07

tank wrote:your not doing anything in notepad as far as i see looking at your code. Maybe you shoulld just experiment with controlsettext. you dont need an example.
I'm not sure what you mean by "your not doing anything" The notepad script I provided locks the computer and then performs the action (create a simple text file) properly while the computer is locked, which is what I am after. I was looking for a reason why this works just fine, even though you said windows security prevents keystrokes being sent
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Running script after windows machine is locked

22 Sep 2018, 12:57

Fine then I appear to be wrong. Not refute your first hand accounts of what happened
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, ShatterCoder and 115 guests