I know there were a few posts on this already, but most of the solutions were to "turn off UAC". I cannot do that in my work environment, unfortunately.
I have a script that is launching
Speccy (Piriform's PC specs grabber) and waits until the program has scanned the user's PC and then saves a snapshot of the computer specs to a network share so I can view it.
It works perfectly with UAC turned off and the problem with the UAC on occurs when it tries to automate the keystrokes. Here are the steps that occur:
1. Run Speccy as admin
2. WinActivate Speccy
3. Send keystrokes ALT-F,S (Save Snapshot under the file menu)
-- Step 3 does not work with UAC turned on. Running as Admin does not change anything. (code at the bottom of the snippet below)
I'm going to stop the steps there and post the code for it, but is there any way to get keystrokes to work with UAC? I searched AHK forums and Google. Not finding anything relevant.
The only other thing I will note is that Send and SendInput have no issues with UAC being on when used with an elevated %comspec%. Why is it not the same with Speccy?
Code:
; If x64 or x86 Windows file structure
IfExist, C:\Program Files (x86)\Speccy\Speccy.exe
SpeccyPath = "C:\Program Files (x86)\Speccy\Speccy.exe"
Else
SpeccyPath = "C:\Program Files\Speccy\Speccy.exe"
; Run Speccy
Run %SpeccyPath%
Sleep 20000 ; After testing, I found that 20 seconds is adequate for Speccy to populate on most systems. I do have a loop process later on that keeps trying if 20 seconds isn't long enough.
SaveAgain: ; "SaveAgain:" is referenced later in the script
WinActivate, Piriform Speccy
WinWaitActive, Piriform Speccy
Send !fs ; Send the keystrokes ALT-fs (This works with UAC off)
Also, how does A_ProgramFiles work with a x64 system? Does it search both paths or just one since x64 systems have "C:\Program Files" and "C:\Program Files (x86)" ?? I would like to consolidate/simplify that IfExist code at the top, if possible.
Anyways, if anyone knows any work around for the UAC thing WITHOUT turning it off, that would be awesome. I've tried a number of things and am at a loss atm.
My curiosity question is, "Why does UAC block keystrokes to other programs, but not CMD Prompt - even when they are both run as an administrator??
Thanks.
- Firewolf
P.s. I can post more code if necessary, but really all I need is to know how to get keystrokes to work with UAC on and I'm golden.
EDIT - added comments to the code.