Jump to content

Cannot <_ProcessSuspend.au3> as admin


Go to solution Solved by Nine,

Recommended Posts

Posted

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")

 

Posted

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.

Posted

Misunderstood what you meant.  Here the code that will work on your regular user.

#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

 

Posted

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.)

Posted
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
Posted

@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

 

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
  • Recently Browsing   0 members

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