Frescard Posted December 20, 2024 Posted December 20, 2024 If I run my script as a regular user, invoking the _ProcessSuspend library works just fine, but if I run the script as an admin (which I need for some other actions) it won't do anything. Any idea what might be going on there (or how to avoid this issue)? ;#RequireAdmin #include <Misc.au3> #include <_ProcessSuspend.au3> _ProcessSuspend("notepad.exe") While Not _IsPressed("20") ; space WEnd _ProcessResume("notepad.exe")
Nine Posted December 20, 2024 Posted December 20, 2024 Even if you execute it as an admin, you still need to run it elevated... “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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy
Frescard Posted December 20, 2024 Author Posted December 20, 2024 I'm not quite sure I understand... If I run the code as shown (with the #RequireAdmin disabled) it will work just fine. If I enable that code (and am then prompted for my admin password) it will not stop the process.
Nine Posted December 20, 2024 Posted December 20, 2024 Misunderstood what you meant. Here the code that will work on your regular user. expandcollapse popup#RequireAdmin #include <Misc.au3> #include <WinAPIProc.au3> #include <ProcessConstants.au3> _ProcessSuspend("notepad.exe") While Not _IsPressed("20") ; space WEnd _ProcessResume("notepad.exe") Func _ProcessSuspend($process) Local $iPID = ProcessExists($process) If $iPID Then Local $hProcess = _WinAPI_OpenProcess($PROCESS_ALL_ACCESS, False, $iPID, True) Local $iRet = DllCall("ntdll.dll", "int", "NtSuspendProcess", "int", $hProcess)[0] _WinAPI_CloseHandle($hProcess) If Not $iRet Then Return 1 Return SetError(1, $iRet, 0) Else Return SetError(2, 0, 0) EndIf EndFunc ;==>_ProcessSuspend Func _ProcessResume($process) Local $iPID = ProcessExists($process) If $iPID Then Local $hProcess = _WinAPI_OpenProcess($PROCESS_ALL_ACCESS, False, $iPID, True) Local $iRet = DllCall("ntdll.dll", "int", "NtResumeProcess", "int", $hProcess)[0] _WinAPI_CloseHandle($hProcess) If Not $iRet Then Return 1 Return SetError(1, $iRet, 0) Else Return SetError(2, 0, 0) EndIf EndFunc ;==>_ProcessResume “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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy
Frescard Posted December 20, 2024 Author Posted December 20, 2024 This works great. Thank you so much! And I guess it would be a general replacement for the existing function? (As it seems to work fine in either admin or restricted user mode.)
Nine Posted December 20, 2024 Posted December 20, 2024 Glad it is working for you. I suppose it could be a replacement, but I am not sure where I should post it... “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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy
Frescard Posted December 21, 2024 Author Posted December 21, 2024 3 hours ago, Nine said: Glad it is working for you. I suppose it could be a replacement, but I am not sure where I should post it... I guess this thread would be the best place:
Solution Nine Posted December 21, 2024 Solution Posted December 21, 2024 @Frescard Will do. Here my latest version of it. Smaller - better. #RequireAdmin #include <Misc.au3> #include <WinAPIProc.au3> #include <ProcessConstants.au3> Global Enum $NT_SUSPEND, $NT_RESUME NtProcess("notepad.exe", $NT_SUSPEND) While Not _IsPressed("20") ; space WEnd NtProcess("notepad.exe", $NT_RESUME) Func NtProcess($sProcess, $iFlag) Local $iPID = ProcessExists($sProcess) If Not $iPID Then Return SetError(1, 0, 0) Local $hProcess = _WinAPI_OpenProcess($PROCESS_ALL_ACCESS, False, $iPID, True) Local $iRet = DllCall("ntdll.dll", "int", $iFlag = $NT_SUSPEND ? "NtSuspendProcess" : "NtResumeProcess", "int", $hProcess)[0] _WinAPI_CloseHandle($hProcess) If $iRet Then SetError(2, $iRet, 0) Return 1 EndFunc ;==>NtProcess 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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy
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