AutoHotkey Community

It is currently May 27th, 2012, 6:43 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: August 2nd, 2011, 4:40 pm 
Offline

Joined: October 19th, 2007, 8:30 pm
Posts: 136
Location: PA
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 2nd, 2011, 8:29 pm 
Offline
User avatar

Joined: June 22nd, 2011, 4:02 pm
Posts: 171
I know you said that you can't turn UAC completely off, maybe it's possible to tweak it a little?

http://www.vista4beginners.com/TweakUAC
http://www.vista4beginners.com/Disable-UAC-for-certain-applications


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 2nd, 2011, 9:57 pm 
Offline
User avatar

Joined: June 22nd, 2011, 4:02 pm
Posts: 171
Also, rather than selecting the menu item using keystrokes you might try:

WinMenuSelectItem

or

PostMessage


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2011, 12:50 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
UAC has a feature called User Interface Privelege Isolation, specifically designed to... well, isolate the user interface of high privilege applications from exploitation by low privilege applications. If you can't turn off or tweak UAC, the only easy option is to run the script which is sending keystrokes as admin.

I believe WinMenuSelectItem works by sending messages, like PostMessage. UIPI filters out most useful messages.

Quote:
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?
Speccy is not a console application. IMO, this is one of the major flaws with UAC/UIPI - any low privilege application can "drive" a high privilege console application. I believe the console window is actually owned by a low privilege process (either csrss.exe or conhost.exe), not the console application which caused it to be created.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2011, 6:12 am 
Offline
User avatar

Joined: June 22nd, 2011, 4:02 pm
Posts: 171
This works for me:
Code:
WinMenuSelectItem Piriform Speccy ,  , File , Save Snapshot...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2011, 2:35 pm 
Offline

Joined: October 19th, 2007, 8:30 pm
Posts: 136
Location: PA
Hmmm, I will have to try WinMenuSelectItem again. Before anyone had posted replies, I found that command and tried it....hoping I could close my help request before anyone replied. ;)
I tested it on a machine with UAC enabled at the default level and alas, it did not work.

The script does run elevated already. I have a separate compiled script that the user runs, which launches the main script as an admin and then that launches Speccy as an admin. It's weird that WinMenuSelectItem doesn't work though, because I would think that this command isn't simulating keystrokes, like "Send" and "SendInput", etc., do.
Although, if I understand Lexikos correctly, what he said explains why it doesn't work:
Quote:
I believe WinMenuSelectItem works by sending messages, like PostMessage. UIPI filters out most useful messages.


The nice thing is that the main goal for this was for our engineers computers, which have UAC disabled because it blocks macros for another application they use. So my script runs perfectly for them. :D Didn't think about that at first.
But it would be nice to be able to use this for any computer in the office.

@Lexikos - So it sounds as if I only have 3 options: UAC off (can't do), UAC tweak, or admin keystrokes(tried already). Correct?
If there is no time-efficient solution, it won't be worth pursuing. Compromising security is not an option either.

Thanks to everyone for their suggestions so far.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 3rd, 2011, 4:57 pm 
Offline
User avatar

Joined: June 22nd, 2011, 4:02 pm
Posts: 171
I think I have found a workaround:
    Leave UAC in its default position
    Open C:\Program Files\AutoHotkey
    Change the properties of the AutoHotkey to "Run in Compatability Mode - Windows XP SP3"

This will allow you to use commands like WinMenuSelectItem.
Unfortuately, every time you run a new script the stupid UAC dialog will popup.

@Lexikos - Do you think doing this will cause any problems?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: batto, Bing [Bot], JSLover, sjc1000 and 61 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group