Jump to content

Running AutoIt.exe As administrator causes ObjGet("","Excel.Applcation") to fail.


Go to solution Solved by Nine,

Recommended Posts

Hi Thanks in advance for any help ☺️

I have a basic AutoIt.exe that works fine until a user Right Clicks the application and Runs as Administrator.

The script checks if the Microsoft Excel application is open and prompts the user via a MsgBox to Close Excel.

If Excel is Open the AutoIt.exe simply Exits and the user has to run the program again once they have closed Excel.

The application has been/is working fine until some bright spark decided to Run As Admin; under this senario the script does not error?

Local $oExcel = ObjGet("","Excel.Application") 
If @error Then
         ;  
Excel is CLOSED - continue

Else
        ;  Excel is OPEN - user needs to close excel - Exit
EndIf

Has anyone got an explanation/solution to ensure Excel is detected when the application is Run As admin?

Thanks

Link to comment
Share on other sites

Hi.

What happens, when Excel is running UAC elvated as well?

Never tried such a thing, but the different UAC levels might hinder your interaction.

 

So you will notice, that when you open a CMD prompt, then you can drag-drop files from Windows Explorer to the CMD box, ending up with the FullFilePathName to "land" in the CMD box.

 

When you try the same with an UAC elevated CMD box, this drag-drop will not work.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Found this old post with the same issue:

may help someone who stumbles accross this post?

Summary:

If your Autoit.exe and Excel are not running with the same level of privileges then the ObjGet function will not work.

For my application, looking at the information in the above link, it's way over kill for the odd 1% of users that may end up encountering this senario. (and abit above my head TBH).

Link to comment
Share on other sites

  • Solution

Here how you can test if another process is run elevated or not :

#include <WinAPIProc.au3>
#include <ProcessConstants.au3>

Local $iPID = ProcessExists("excel.exe")
ConsoleWrite($iPID & @CRLF)
Local $hProcess = _WinAPI_OpenProcess($PROCESS_QUERY_LIMITED_INFORMATION, False, $iPID, False)
ConsoleWrite($hProcess & @CRLF)
Local $hToken = _WinAPI_OpenProcessToken($TOKEN_ALL_ACCESS, $hProcess)
If $hToken Then
  ConsoleWrite("Process is not elevated" & @CRLF)
  _WinAPI_CloseHandle($hToken)
Else
  ConsoleWrite("Process is elevated" & @CRLF)
EndIf
_WinAPI_CloseHandle($hProcess)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...