malmoores Posted December 8, 2023 Share Posted December 8, 2023 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 More sharing options...
rudi Posted December 8, 2023 Share Posted December 8, 2023 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 More sharing options...
malmoores Posted December 8, 2023 Author Share Posted December 8, 2023 Hi Rudi Good call when excel and the exe are both run as admin then it works, excel is detected. So the question is: Is there a way to detect Excel is it's running under elevated permissions? Thanks for the quick input Link to comment Share on other sites More sharing options...
malmoores Posted December 8, 2023 Author Share Posted December 8, 2023 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 More sharing options...
ioa747 Posted December 8, 2023 Share Posted December 8, 2023 (edited) _WinAPI_IsElevated ( ) Edited December 8, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
Solution Nine Posted December 8, 2023 Solution Share Posted December 8, 2023 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) ioa747 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now