Jump to content

Recommended Posts

Posted (edited)

Hi all,

I'm been experiencing false positives lately for some of my compiled code and as such I'm working on minimizing unneeded access and system calls. I've changed a bit but I'm currently using 

$aProcesses = ProcessList()
For $Loop = 3 To $aProcesses[0][0] ; Skip System
    $hCurProcess = _WinAPI_OpenProcess($PROCESS_ALL_ACCESS, False, $aProcesses[$Loop][1])
    $aAffinity = _WinAPI_GetProcessAffinityMask($hCurProcess)
    ; Other code here
    _WinAPI_CloseHandle($hCurProcess)
Next

 but I feel this may be too much access for what I'm needing to do. I just wanna confirm that if I'm only reading process affinity I can use at MINIMUM

$PROCESS_QUERY_INFORMATION

and if I'm setting affinity I'd need at MINIMUM

$PROCESS_SET_INFORMATION

 

Thanks!

Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11, MSEdgeRedirect
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Posted (edited)

 

Func ProcessPidUserSelf($sProcessName = 'explorer.exe')
    Local $aData, $aList = 0
    $aList = ProcessList($sProcessName)
    For $i = 1 To UBound($aList) -1
        $aData = _WinAPI_GetProcessUser($aList[$i][1])
        If IsArray($aData) Then
            If $aData[0] = @UserName Then Return $aList[$i][1]
        EndIf
    Next
    Return SetError(1, 0, 0)
EndFunc

the help example for _WinAPI_GetProcessUser() calls for it, but as you can see ( by trying the above code ), is not necessarily needed.

So it depends in what you need in "; Other code here".

 

Edit: Too late here in my timezone ;) 

Here, hope it helps:

#include <Debug.au3>
#include <WinAPIProc.au3>
#include <WinAPISys.au3>

_DebugArrayDisplay(ProcessAffinityMaskUserSelf(), "_WinAPI_GetProcessAffinityMask()")

Func ProcessAffinityMaskUserSelf($sProcessName = 'explorer.exe')
    Local $err = 0, $ext = 0, $aAffinity, $hProcess, $aData, $aList = 0
    $aList = ProcessList($sProcessName)
    For $i = 1 To UBound($aList) - 1
        $aData = _WinAPI_GetProcessUser($aList[$i][1])
        If IsArray($aData) Then
            If $aData[0] = @UserName Then
                If Number(_WinAPI_GetVersion()) >= 6.0 Then
                    $hProcess = _WinAPI_OpenProcess($PROCESS_QUERY_LIMITED_INFORMATION, 0, $aList[$i][1])
                Else
                    $hProcess = _WinAPI_OpenProcess($PROCESS_QUERY_INFORMATION, 0, $aList[$i][1])
                EndIf
                $aAffinity = _WinAPI_GetProcessAffinityMask($hProcess) ; An affinity mask is a bit mask in which each bit represents a processor.
                $err = @error ;          On Failure: Sets the @error flag to non-zero, call
                If $err Then
                    $ext = _WinAPI_GetLastError() ;  to get extended error information
                    $aAffinity = _WinAPI_GetLastErrorMessage()
                EndIf
                _WinAPI_CloseHandle($hProcess)
                Return SetError($err, $ext, $aAffinity)
            EndIf
        EndIf
    Next
    Return SetError(1, 0, 0)
EndFunc   ;==>ProcessAffinityMaskUserSelf

 

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting  image.gif.922e3a93535f431de08b31ee669cc446.gif
autoit_scripter_blue_userbar.png

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
×
×
  • Create New...