logo

Python Win32 process

Šajā rakstā mēs apspriedīsim Python win32 procesu. Un arī mēs apspriedīsim tās metodes pa vienam.

Būtībā Win32 process ir Python metode. Izmantojot šo moduli, ir pieejamas paplašinātas Win32 procesa izveides un pārvaldības iespējas. Metode Izveidot izveido procesa objektus (konstruktoru). Ir iespējams nogalināt, apturēt, atsākt un iestatīt procesu prioritāti objektos, izmantojot papildu metodes.

Windows Management Instrumentation (WMI; agrāk WBEM) un WMI paplašinājumi Windows draivera modelim kalpo par pamatu vadāmībai operētājsistēmās Windows 2019/2016/2012/2008 un Windows 10/7/XP (WDM).

Iespēju izveidot monitora pārbaudes procedūras, pamatojoties uz WMI, piedāvā ActiveXperts Network Monitor. Ir vairāk nekā simts WMI paraugu, ko ActiveXperts ir apkopojis. Šie piemēri var kalpot par sākumpunktu pilnīgi jaunām pārbaudes rutīnām, kuras izveidojat pats.

Šajā vietnē ir pieejami daudzi WMI paraugi.

ActiveXperts Network Monitor izmanto Win32_Process WMI klasi, lai pārraudzītu jūsu serverus.

Notikumu sēriju operētājsistēmā Windows attēlo Win32_Process WMI klase. Secība, kas ietver viena vai vairāku procesoru vai tulku, izpildāmā koda un ievades kopas mijiedarbību, piemēram, klienta programma, kas darbojas Windows sistēmā, ir šīs klases pēcnācējs vai dalībnieks.

Tagad rodas jautājums kas ir Python win32?

Tādējādi Python win32 un Win32 lietojumprogrammu saskarnes (API) iespējas var izmantot kopā ar Python, izmantojot PyWin32 paplašinājumu bibliotēku operētājsistēmai Windows.

Ņemsim nelielu ievadu par win32api modulis.

Win32api modulis piedāvā dažādas papildu metodes procesu kontrolei. Tie sniedz jums iespēju veikt daudzas parastās darbības, kas nepieciešamas jaunu procesu palaišanai, taču tās joprojām nespēj piedāvāt augstākā līmeņa zema līmeņa kontroli.

Atšķirībā no os.system funkcijas, kas tika izskaidrota iepriekš, funkcija WinExec nodrošina dažādus pielāgojumus GUI programmām. Piemēram, nav izveidota neviena konsole, un funkcija negaida, līdz jaunais process ir pabeigts.

Funkcijai ir nepieciešamas šīs divas ievades:

  • Rīkojums izpildīt
  • Vai arī lietojumprogrammas loga sākotnējais stāvoklis

Ņemsim nelielu ievadu par win32api.ShellExecute.

Turklāt win32api modulis piedāvā vēl vienu noderīgu funkciju jaunu procesu uzsākšanai. Atšķirībā no nejaušu procesu sākšanas, dokumentu atvēršana ir galvenais funkcijas ShellExecute mērķis. Piemēram, varat norādīt ShellExecute “atvērt MyDocument.doc”. Windows izvēlas, kuru procesu palaist jūsu vārdā, lai atvērtu.doc failus. Klikšķis (vai dubultklikšķis) uz a.doc faila liek Windows Explorer veikt to pašu darbību.

Programmu, kas tiek palaists, sauc par procesu (apstrādātu). Procesam nav jābūt tādam, ko lietotājs palaiž manuāli; tā vietā tas varētu būt sistēmas process, ko rada operētājsistēma. Jebkurai programmai, kas darbojas operētājsistēmā, vispirms ir jāģenerē atsevišķs process, lai tā varētu sākt darboties. Lielākā daļa procesu tipiskā OS instalācijā ir fona programmas un operētājsistēmas pakalpojumi, kas tiek izmantoti, lai uzturētu aparatūru, programmatūru un operētājsistēmu labā darba kārtībā.

Šajā ziņojumā tiks aplūkotas dažas alternatīvas Python metodes, lai iegūtu Windows OS pašlaik aktīvo procesu sarakstu.

Lai iegūtu vēlamo rezultātu, vispirms aprakstīsim Python metodi. Pēc tam mēs pārbaudīsim komandu no Windows komandu procesora, lai paveiktu to pašu.

pip instalēt wmi

Kopējiet šo iepriekš minēto kodu terminālī.

Piemērs

 #import wmi module import wmi # Initializise the wmi constructor f = wmi.WMI() # Print the header print(&apos;Printing the pid Process name&apos;) # all the running processes for process in f.Win32_Process(): print(f&apos;{process.ProcessId:<5} {process.name}') < pre> <p> <strong>Output:</strong> </p> <img src="//techcodeview.com/img/python-tutorial/88/python-win32-process.webp" alt="Python Win32 Process"> <br> <img src="//techcodeview.com/img/python-tutorial/88/python-win32-process-2.webp" alt="Python Win32 Process"> <p>The WMI() function of the wmi library is first initialized. This enables us to access its internal functions, such as WMI.Win32_Service, WMI.Win32_Process, and WMI.Win32_Printjob, each of which is intended to carry out a certain duty. To obtain a list of the system&apos;s active processes, we would use the WMI.Win32_Process function. After that, we iterated through all the running processes and placed them in the variable process by calling the function WMI.Win32_Process(). The corresponding attributes were then used to derive the process&apos;s ProcessID (pid) and ProcessName (name). To add padding to the output and properly align it, we used F-strings for the output.</p> <p>Now let&apos;s go through different methods of module Win32process.</p> <h3>1. STARTUPINFO</h3> <p>In this method, we create a new STARTUPINFO object.</p> <p>Let&apos;s understand how to create this, which is given below:</p> <p>win32process.STARTUPINFO</p> <p>PySTARTUPINFO = STARTUPINFO()</p> <h3>2. beginthreadex</h3> <p>In this method, we create a new thread.</p> <p>Let&apos;s understand how to create this, which is given below:</p> <p>win32process.beginthreadex</p> <p>PyHANDLE, int = beginthreadex(sa, stackSize , entryPoint , args , flags )</p> <p>Let&apos;s understand its parameters is given below</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>sa:</td> PySECURITY_ATTRIBUTES(The security attributes, or None) </tr><tr><td>stackSize :</td> int (The new thread&apos;s stack size, or 0 for the default size.) </tr><tr><td>entryPoint :</td> function (It is a thread function) </tr><tr><td>args :</td> tuple </tr><tr><td>flags :</td> int </tr></ul> <p>CREATE_SUSPENDED is an option for delaying the start of a thread.</p> <p> <strong>The thread handle and thread ID are returned as a tuple as the outcome.</strong> </p> <h3>3. CreateProcess</h3> <p>win32process.CreateProcess PyHANDLE, PyHANDLE, int, int = CreateProcess(appName, commandLine , processAttributes , threadAttributes , bInheritHandles , dwCreationFlags , newEnvironment , currentDirectory , startupinfo ) establishes a new process and the main thread for it. The newly created process runs the designated executable file.</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>appName:</td> string (executable module&apos;s name, or None) </tr><tr><td>Commandline:</td> string (command-line argument, or Nothing) </tr><tr><td>processAttributes:</td> PySECURITY_ATTRIBUTES (attributes of process security, or None) </tr><tr><td>threadAttributes:</td> PySECURITY_ATTRIBUTES (aspects of thread security, or None) </tr><tr><td>bInheritHandles:</td> int </tr><tr><td>dwCreationFlags:</td> int </tr></ul> <h3>4. CreateRemoteThread</h3> <p>win32process.CreateRemoteThread PyHANDLE, int = CreateRemoteThread(hprocess, sa , stackSize , entryPoint , Parameter , flags ) establishes a thread that executes in another process&apos;s virtual address space.</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>hprocess :</td> PyHANDLE (the remote process&apos;s handle) </tr><tr><td>sa :</td> PySECURITY_ATTRIBUTES (Security characteristics, or None) </tr><tr><td>stackSize :</td> int (The new thread&apos;s stack size, or 0 for the default size.) </tr><tr><td>entryPoint :</td> function (The address of the thread function.) </tr><tr><td>Parameter :</td> int (a void pointer that served as the argument given to the function) </tr><tr><td>flags :</td> int </tr></ul> <p>The thread handle and thread ID are returned as a tuple as the outcome.</p> <h3>5. CreateProcessAsUser</h3> <p>win32process.CreateProcessAsUser creates a new process with the provided user as its context.</p> <p>PyHANDLE, PyHANDLE, int, int = CreateProcessAsUser(hToken, appName , commandLine , processAttributes , threadAttributes , bInheritHandles , dwCreationFlags , newEnvironment , currentDirectory , startupinfo )</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>hToken:</td> PyHANDLE (Handle to a token that indicates a user who is currently logged in) </tr><tr><td>appName:</td> string (executable module&apos;s name, or None) </tr><tr><td>commandLine:</td> string (command-line argument, or Nothing) </tr><tr><td>processAttributes:</td> PySECURITY_ATTRIBUTES (attributes of process security, or None) </tr><tr><td>threadAttributes:</td> PySECURITY_ATTRIBUTES (aspects of thread security, or None) </tr><tr><td>bInheritHandles:</td> int (the inheritance flag handle) </tr><tr><td>dwCreationFlags:</td> int (creating of flags) </tr><tr><td>newEnvironment:</td> None (A dictionary of stringor Unicode pair definitions to specify the process environment, or None to use the default environment.) </tr><tr><td>currentDirectory:</td> string (name of the current directory, or None) </tr><tr><td>startupinfo:</td> PySTARTUPINFO (a STARTUPINFO object that describes the appearance of the new process&apos;s main window.) </tr></ul> <p> <strong>Consequently, a tuple of (hProcess, hThread, dwProcessId, dwThreadId)</strong> </p> <h3>6. GetCurrentProcess</h3> <p>win32process.GetCurrentProcess obtains a fictitious handle for the active process.</p> <p>int = GetCurrentProcess()</p> <h3>7. GetCurrentProcessId</h3> <p>win32process.GetCurrentProcessId reveals the caller process&apos;s unique process identification.</p> <p>int = GetCurrentProcessId()</p> <h3>8. GetProcessVersion</h3> <p>win32process.GetProcessVersion reveals the system&apos;s main and minor version numbers, which are needed to conduct a specific process.</p> <p>int = GetProcessVersion(processId)</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>processId:</td> int (a designation for the desired process.) </tr></ul> <h3>9. GetCurrentProcessId</h3> <p>win32process.GetCurrentProcessId reveals the caller process&apos;s unique process identification.</p> <p>int = GetCurrentProcessId()</p> <h3>10. GetStartupInfo</h3> <p>win32process.GetStartupInfo reveals the STARTUPINFO structure&apos;s contents, which were supplied when the caller process was established.</p> <p>PySTARTUPINFO = GetStartupInfo()</p> <h3>11. GetPriorityClass</h3> <p>win32process.GetPriorityClass</p> <p>int = GetPriorityClass(handle)</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>handle:</td> PyHANDLE (to the thread&apos;s handle) </tr></ul> <h3>12. GetExitCodeThread</h3> <p>win32process.GetExitCodeThread</p> <p>int = GetExitCodeThread(handle)</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>handle:</td> PyHANDLE (to the thread&apos;s handle) </tr></ul> <h3>13. GetExitCodeProcess</h3> <p>win32process.GetExitCodeProcess</p> <p>int = GetExitCodeProcess(handle)</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>handle:</td> PyHANDLE (to the thread&apos;s handle) </tr></ul> <h3>14. GetWindowThreadProcessId</h3> <p>win32process.GetWindowThreadProcessId returns the thread and process IDs that were responsible for the provided window&apos;s creation.</p> <p>int, int = GetWindowThreadProcessId(hwnd)</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>hwnd:</td> int (this parameter handles the window) </tr></ul> <p> <strong>Consequently, a tuple of (threadId, processId)</strong> </p> <h3>15. SetThreadPriority</h3> <p>win32process.SetThreadPriority</p> <p>SetThreadPriority(handle, nPriority)</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>handle:</td> PyHANDLE (This parameter handles the thread) </tr><tr><td>nPriority:</td> int (This parameter thread the priority level) </tr></ul> <h3>16. GetThreadPriority</h3> <p>win32process.GetThreadPriority</p> <p>int = GetThreadPriority(handle)</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>handle:</td> PyHANDLE (this parameter handles the threads) </tr></ul> <h3>17. GetProcessPriorityBoost</h3> <p>win32process.GetProcessPriorityBoost determines whether a process&apos;s dynamic priority adjustment is enabled.</p> <p>bool = GetProcessPriorityBoost(Process)</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>Process:</td> PyHANDLE (This parameter handles to a process) </tr></ul> <h3>18. SetProcessPriorityBoost</h3> <p>win32process.SetProcessPriorityBoost enables or disables a process&apos;s dynamic priority adjustment.</p> <p>SetProcessPriorityBoost(Process, DisablePriorityBoost)</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>Process:</td> PyHANDLE (This parameter handles a process) </tr><tr><td>DisablePriorityBoost:</td> boolean (This parameter indicates True to disable and False to enable) </tr></ul> <h3>19. GetThreadPriorityBoost</h3> <p>win32process.GetThreadPriorityBoost</p> <p>determines whether a thread&apos;s dynamic priority adjustment is enabled.</p> <p>bool = GetThreadPriorityBoost(Thread)</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>Thread:</td> PyHANDLE (This parameter handles to a thread) </tr></ul> <h3>20. SetThreadPriorityBoost</h3> <p>win32process.SetThreadPriorityBoost enables or disables a thread&apos;s dynamic priority adjustment.</p> <p>SetThreadPriorityBoost(Thread, DisablePriorityBoost)</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>Thread:</td> PyHANDLE (This parameter handles to a thread) </tr><tr><td>DisablePriorityBoost:</td> boolean ((This parameter indicates True to disable and False to enable) </tr></ul> <h3>21. GetThreadIOPendingFlag</h3> <p>win32process.GetThreadIOPendingFlag determines whether a thread has any open IO requests.</p> <p>bool = GetThreadIOPendingFlag(Thread)</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>Thread:</td> PyHANDLE (This parameter handles to a thread) </tr></ul> <h3>22. GetThreadTimes</h3> <p>win32process.GetThreadTimes</p> <p>It returns the time statistics for a thread.</p> <p>dict = GetThreadTimes(Thread)</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>Thread:</td> PyHANDLE (This parameter handles to a thread) </tr></ul> <h3>23. GetProcessId</h3> <p>int = GetProcessId(Process)</p> <p>It returns the Pid for a process handle.</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>Process:</td> PyHANDLE (This parameter handles to a thread) </tr></ul> <h3>24. SetPriorityClass</h3> <p>win32process.SetPriorityClass</p> <p>SetPriorityClass(handle, dwPriorityClass)</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>handle:</td> PyHANDLE (This parameter handles to the process) </tr><tr><td>dwPriorityClass:</td> int (This parameter gives priority class value) </tr></ul> <h3>25. AttachThreadInput</h3> <p>win32process.AttachThreadInput connects and disconnects the input of two threads.</p> <p>AttachThreadInput(idAttach, idAttachTo, Attach)</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>idAttach:</td> int (This parameter shows id of a thread) </tr><tr><td>idAttachTo:</td> int (This parameter shows the id of the thread) </tr><tr><td>Attach:</td> bool (determines whether a thread should be joined or disconnected.) </tr></ul> <h3>26. SetThreadIdealProcessor</h3> <p>win32process.SetThreadIdealProcessor</p> <p> <strong>Syntax</strong> </p> <pre>win32process.SetThreadIdealProcessor( handle, dwIdealProcessor )</pre> <p> <strong>Parameters</strong> </p> <ul> <tr><td>handle:</td> PyHANDLE ( handle to the thread of interest ) </tr><tr><td>dwIdealProcessor:</td> int ( ideal processor number ) </tr></ul> <p> <strong>Return type</strong> </p> <p>This method return the int value</p> <h3>27. GetProcessAffinityMask</h3> <p>win32process.GetProcessAffinityMask</p> <p> <strong>Syntax</strong> </p> <pre>win32process.GetProcessAffinityMask( hProcess )</pre> <p> <strong>Parameters</strong> </p> <ul> <tr><td>hProcess:</td> PyHANDLE ( handle to the process of interest ) </tr></ul> <p> <strong>Return type</strong> </p> <p>This method returns a tuple of ( process affinity mask, system affinity mask ).</p> <h3>28. SetProcessAffinityMask</h3> <p>win32process.SetProcessAffinityMask</p> <p> <strong>Syntax</strong> </p> <pre>win32process.SetProcessAffinityMask( hProcess, mask )</pre> <p>Sets a processor affinity mask for a specified process.</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>hProcess:</td> PyHANDLE ( handle to the process of interest ) </tr><tr><td>mask:</td> int ( a processor affinity mask ) </tr></ul> <h4>Note: Some platforms do not have this feature.</h4> <h3>29. SetThreadAffinityMask</h3> <p>win32process.SetThreadAffinityMask</p> <p> <strong>Syntax</strong> </p> <pre>win32process.SetThreadAffinityMask( hThread, ThreadAffinityMask )</pre> <p> <strong>Parameters</strong> </p> <ul> <tr><td>hThread:</td> PyHANDLE ( handle to the thread of interest ) </tr><tr><td>ThreadAffinityMask:</td> int ( a processor affinity mask ) </tr></ul> <p> <strong>Return type</strong> </p> <p>This method returns an int value.</p> <h3>30. SuspendThread</h3> <p>win32process.SuspendThread</p> <p> <strong>Syntax</strong> </p> <pre>int = SuspendThread( handle )</pre> <p>Suspends the specified thread.</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>handle:</td> PyHANDLE ( handle to the thread ) </tr></ul> <p> <strong>Return value</strong> </p> <p>The return value is the thread&apos;s previous suspend count</p> <h3>31. ResumeThread</h3> <p>win32process.ResumeThread</p> <p> <strong>Syntax</strong> </p> <pre>int = ResumeThread( handle )</pre> <p>Resumes the specified thread. When the suspend count is decremented to zero, the execution of the thread is resumed.</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>handle:</td> PyHANDLE ( handle to the thread ) </tr></ul> <p> <strong>Return value</strong> </p> <p>The return value is the thread&apos;s previous suspend count</p> <h3>32. TerminateProcess</h3> <p>win32process.TerminateProcess</p> <p> <strong>Syntax</strong> </p> <pre>TerminateProcess( handle, exitCode )</pre> <p> <strong>Parameters</strong> </p> <ul> <tr><td>handle:</td> PyHANDLE ( handle to the process ) </tr><tr><td>exitCode:</td> int ( The exit code for the process ) </tr></ul> <h3>33. xitProcess</h3> <p>win32process.ExitProcess</p> <ul> <tr><td>ExitProcess:</td> The process&apos;s end and all of its threads </tr></ul> <p> <strong>Parameters</strong> </p> <ul> <tr><td>exitCode:</td> int (Exit code information is provided for the process, and all threads that are terminated as a result of this call.) </tr></ul> <p>The best way to stop a process is with ExitProcess. A clean process shutdown is provided by this function. This includes contacting each associated dynamic-link library&apos;s (DLL) entry-point function with a value indicating that the process is separating from the DLL. The DLLs associated with the process are not informed of the process termination if a process terminates by invoking win32process::TerminateProcess.</p> <h3>34. EnumProcesses</h3> <p>win32process.EnumProcesses</p> <p> <strong>Syntax</strong> </p> <pre>( long,.... ) = EnumProcesses()</pre> <p>Provides Pids for activities that are actually running.</p> <h3>35. EnumProcessModules</h3> <p>win32process.EnumProcessModules</p> <p> <strong>Syntax</strong> </p> <pre>( long,.... ) = EnumProcessModules( hProcess )</pre> <p>Lists loaded modules for a process handle</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>hProcess:</td> PyHANDLE ( Process handle as returned by OpenProcess ) </tr></ul> <h3>36. EnumProcessModulesEx</h3> <p>win32process.EnumProcessModulesEx</p> <p> <strong>Syntax</strong> </p> <pre>( long,.... ) = EnumProcessModulesEx( hProcess, FilterFlag )</pre> <p>lists the 32- or 64-bit modules that a process has loaded.</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>hProcess :</td> PyHANDLE ( The process handle that OpenProcess returned ) FilterFlag=LIST_MODULES_DEFAULT : int ( choose whether to return 32-bit or 64-bit modules. ) needs Windows Vista or later. </tr></ul> <h3>37. GetModuleFileNameEx</h3> <p>win32process.GetModuleFileNameEx</p> <p> <strong>Syntax</strong> </p> <pre>PyUNICODE = GetModuleFileNameEx( hProcess, hModule )</pre> <p> <strong>Parameters</strong> </p> <ul> <tr><td>hProcess:</td> PyHANDLE ( The process handle that OpenProcess returned ) </tr><tr><td>hModule:</td> PyHANDLE ( This parameter handles the modules ) </tr></ul> <h3>38. GetProcessMemoryInfo</h3> <p>win32process.GetProcessMemoryInfo</p> <p> <strong>Syntax</strong> </p> <pre>dict = GetProcessMemoryInfo( hProcess )</pre> <p>A dict representing a PROCESS_MEMORY_COUNTERS struct is returned as the process memory statistics.</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>hProcess:</td> PyHANDLE ( Process handle as returned by OpenProcess ) </tr></ul> <h3>39. GetProcessTimes</h3> <p>win32process.GetProcessTimes</p> <p> <strong>Syntax</strong> </p> <pre>dict = GetProcessTimes( hProcess )</pre> <p>Obtain time statistics for a process using its handle. (In 100 nanosecond units for UserTime and KernelTime)</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>hProcess:</td> PyHANDLE ( Process handle as returned by OpenProcess ) </tr></ul> <h3>40. GetProcessIoCounters</h3> <p>win32process.GetProcessIoCounters</p> <p> <strong>Syntax</strong> </p> <pre>dict = GetProcessIoCounters( hProcess )</pre> <p>I/O statistics for a process are returned as a dictionary corresponding to an IO_COUNTERS struct.</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>hProcess:</td> PyHANDLE ( Process handle as returned by OpenProcess ) </tr></ul> <h3>41. GetProcessWindowStation</h3> <p>win32process.GetProcessWindowStation</p> <p> <strong>Syntax</strong> </p> <pre>GetProcessWindowStation()</pre> <p>Returns a handle to the window station for the calling process.</p> <h3>42. GetProcessWorkingSetSize</h3> <p>win32process.GetProcessWorkingSetSize</p> <p> <strong>Syntax</strong> </p> <pre>int,int = GetProcessWorkingSetSize( hProcess )</pre> <p>A process&apos;s minimum and maximum working set sizes are returned.</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>hProcess:</td> PyHANDLE ( Process handle as returned by win32api::OpenProcess ) </tr></ul> <h3>43. SetProcessWorkingSetSize</h3> <p>win32process.SetProcessWorkingSetSize</p> <p> <strong>Syntax</strong> </p> <pre>SetProcessWorkingSetSize( hProcess, MinimumWorkingSetSize, MaximumWorkingSetSize )</pre> <p>Sets minimum and maximum working set sizes for a process.</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>hProcess :</td> PyHANDLE ( Process handle as returned by OpenProcess ) </tr><tr><td>MinimumWorkingSetSize :</td> int ( Minimum number of bytes to keep in physical memory ) </tr><tr><td>MaximumWorkingSetSize :</td> int ( Maximum number of bytes to keep in physical memory ) </tr></ul> <h4>NOTE: To entirely swap out the procedure, set both min and max to -1.</h4> <h3>44. GetProcessShutdownParameters</h3> <p>win32process.GetProcessShutdownParameters</p> <p> <strong>Syntax</strong> </p> <pre>int,int = GetProcessShutdownParameters()</pre> <p>Reveals the process&apos;s current termination level and triggers.</p> <p>The range is 000-0FF. windows reserved, Last, 200-2FF Middle, First, 300-3FF, and Fourth, 400-4FF Windows reserves.</p> <h3>45. SetProcessShutdownParameters</h3> <p>win32process.SetProcessShutdownParameters</p> <p> <strong>Syntax</strong> </p> <pre>SetProcessShutdownParameters(Level, Flags)</pre> <p>Sets the process&apos;s flags and termination priority.</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>Level:</td> int (This parameter shows higher priority equals earlier) </tr><tr><td>Flags:</td> int (This parameter shows only SHUTDOWN NORETRY is valid at the moment). </tr></ul> <p>The range is 000-0FF. 100-1FF Last, 200-2FF Middle, 300-3FF First, 400-4FF, and reserved by windows window reserved.</p> <h3>46. GetGuiResources</h3> <p>win32process.GetGuiResources</p> <p> <strong>Syntax</strong> </p> <pre>int = GetGuiResources(Process, Flags )</pre> <p>Gives the amount of GDI or user object handles that a process is holding.</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>Process:</td> PyHANDLE (This parameter Win32api::OpenProcess&apos;s returned handle to a process) </tr><tr><td>Flags:</td> int (This parameter shows either GR USEROBJECTS or GR GDIOBJECTS (from win32con)) </tr></ul> <h3>47. IsWow64Process</h3> <p>win32process.IsWow64Process</p> <p> <strong>Syntax</strong> </p> <pre>bool = IsWow64Process(Process)</pre> <p>Identifies whether WOW64 is currently running the specified process.</p> <p> <strong>Parameters</strong> </p> <ul> <tr><td>Process=None:</td> PyHANDLE (Process handle returned by win32api::OpenProcess, win32api::GetCurrentProcess, etc.; if None (the default) is given, the current process handle will be used.) </tr></ul> <p>Let&apos;s see its Return Value.</p> <p>The return value is False if the operating system does not provide this function (ie,</p> <p>a NotImplemented exception will never be thrown). However, a</p> <p>win32process.error exception to this is normally thrown if the function is available</p> <p>but ineffective.</p> <h2>Conclusion</h2> <p>In this article, we have discussed Python win32 process. And also, we have discussed the different types of methods and their parameters and return values one by one.</p> <hr></5}>

Parametri

    rokturis:PyHANDLE (apturiet interesējošo pavedienu)dwIdealProcessor:int (ideāls procesora numurs)

Atgriešanās veids

Šī metode atgriež int vērtību

27. GetProcessAffinityMask

win32process.GetProcessAffinityMask

Sintakse

win32process.GetProcessAffinityMask( hProcess )

Parametri

    hProcess:PyHANDLE (interesējošā procesa rokturis)

Atgriešanās veids

Šī metode atgriež virkni (procesa afinitātes maska, sistēmas afinitātes maska).

28. SetProcessAffinityMask

win32process.SetProcessAffinityMask

Sintakse

win32process.SetProcessAffinityMask( hProcess, mask )

Iestata procesora radniecības masku noteiktam procesam.

Parametri

    hProcess:PyHANDLE (interesējošā procesa rokturis)maska:int (procesora afinitātes maska)

Piezīme. Dažām platformām šīs funkcijas nav.

29. SetThreadAffinityMask

win32process.SetThreadAffinityMask

Sintakse

win32process.SetThreadAffinityMask( hThread, ThreadAffinityMask )

Parametri

    hPavediens:PyHANDLE (apturiet interesējošo pavedienu)ThreadAffinityMask:int (procesora afinitātes maska)

Atgriešanās veids

Šī metode atgriež int vērtību.

kurā gadā izgudroja datoru

30. SuspendThread

win32process.SuspendThread

Sintakse

int = SuspendThread( handle )

Aptur norādīto pavedienu.

Parametri

    rokturis:PyHANDLE ( vītnes rokturis )

Atdeves vērtība

Atgriešanas vērtība ir pavediena iepriekšējais apturēšanas skaits

31. ResumeThread

win32process.ResumeThread

Sintakse

int = ResumeThread( handle )

Atsāk norādīto pavedienu. Kad apturēšanas skaits tiek samazināts līdz nullei, pavediena izpilde tiek atsākta.

Parametri

    rokturis:PyHANDLE ( vītnes rokturis )

Atdeves vērtība

Atgriešanas vērtība ir pavediena iepriekšējais apturēšanas skaits

32. Pārtraukt procesu

win32process.TerminateProcess

Sintakse

TerminateProcess( handle, exitCode )

Parametri

    rokturis:PyHANDLE (procesa rokturis)izejas kods:int ( procesa izejas kods )

33. xitProcess

win32process.ExitProcess

    Izejas process:Procesa beigas un visi tā pavedieni

Parametri

    izejas kods:int (Procesam tiek nodrošināta izejas koda informācija un visi pavedieni, kas tiek pārtraukti šī izsaukuma rezultātā.)

Labākais veids, kā apturēt procesu, ir ExitProcess. Šī funkcija nodrošina tīru procesa izslēgšanu. Tas ietver sazināšanos ar katras saistītās dinamiskās saites bibliotēkas (DLL) ieejas punkta funkciju ar vērtību, kas norāda, ka process tiek atdalīts no DLL. Ar procesu saistītie DLL netiek informēti par procesa pārtraukšanu, ja process tiek pārtraukts, izsaucot win32process::TerminateProcess.

34. EnumProcesses

win32process.EnumProcesses

Sintakse

( long,.... ) = EnumProcesses()

Nodrošina PID darbībām, kas faktiski darbojas.

35. EnumProcessModules

win32process.EnumProcessModules

Sintakse

( long,.... ) = EnumProcessModules( hProcess )

Uzskaita ielādētos moduļus procesa rokturam

Parametri

    hProcess:PyHANDLE (OpenProcess atgrieztais procesa rokturis)

36. EnumProcessModulesEx

win32process.EnumProcessModulesEx

Sintakse

( long,.... ) = EnumProcessModulesEx( hProcess, FilterFlag )

uzskaitīti 32 vai 64 bitu moduļi, ko process ir ielādējis.

Parametri

objektu klase java
    h Process:PyHANDLE (procesa rokturis, ko OpenProcess atgrieza) FilterFlag=LIST_MODULES_DEFAULT : int (izvēlieties, vai atgriezt 32 bitu vai 64 bitu moduļus. ) nepieciešama Windows Vista vai jaunāka versija.

37. GetModuleFileNameEx

win32process.GetModuleFileNameEx

Sintakse

PyUNICODE = GetModuleFileNameEx( hProcess, hModule )

Parametri

    hProcess:PyHANDLE (procesa rokturis, ko OpenProcess atgrieza)hModulis:PyHANDLE (šis parametrs apstrādā moduļus)

38. GetProcessMemoryInfo

win32process.GetProcessMemoryInfo

Sintakse

dict = GetProcessMemoryInfo( hProcess )

Dikts, kas attēlo PROCESS_MEMORY_COUNTERS struktūru, tiek atgriezts kā procesa atmiņas statistika.

Parametri

    hProcess:PyHANDLE (OpenProcess atgrieztais procesa rokturis)

39. GetProcessTimes

win32process.GetProcessTimes

Sintakse

dict = GetProcessTimes( hProcess )

Iegūstiet procesa laika statistiku, izmantojot tā rokturi. (100 nanosekunžu vienībās UserTime un KernelTime)

Parametri

    hProcess:PyHANDLE (OpenProcess atgrieztais procesa rokturis)

40. GetProcessIoCounters

win32process.GetProcessIoCounters

Sintakse

masīvs virknē
dict = GetProcessIoCounters( hProcess )

Procesa I/O statistika tiek atgriezta kā vārdnīca, kas atbilst IO_COUNTERS struktūrai.

Parametri

    hProcess:PyHANDLE (OpenProcess atgrieztais procesa rokturis)

41. GetProcessWindowStation

win32process.GetProcessWindowStation

Sintakse

GetProcessWindowStation()

Atgriež rokturi logu stacijai izsaukšanas procesam.

42. GetProcessWorkingSetSize

win32process.GetProcessWorkingSetSize

Sintakse

int,int = GetProcessWorkingSetSize( hProcess )

Tiek atgriezti procesa minimālie un maksimālie darba kopas izmēri.

Parametri

    hProcess:PyHANDLE (procesa rokturis, ko atgriezis win32api::OpenProcess)

43. SetProcessWorkingSetSize

win32process.SetProcessWorkingSetSize

Sintakse

SetProcessWorkingSetSize( hProcess, MinimumWorkingSetSize, MaximumWorkingSetSize )

Iestata procesa minimālo un maksimālo darba komplekta izmēru.

Parametri

    h Process:PyHANDLE (OpenProcess atgrieztais procesa rokturis)Minimālais darba komplekta izmērs:int (minimālais baitu skaits, kas jāsaglabā fiziskajā atmiņā)Maksimālais darba komplekta izmērs:int (Maksimālais baitu skaits, kas jāsaglabā fiziskajā atmiņā)

PIEZĪME. Lai pilnībā nomainītu procedūru, iestatiet gan min, gan maksimumu uz -1.

44. GetProcessShutdownParameters

win32process.GetProcessShutdownParameters

Sintakse

int,int = GetProcessShutdownParameters()

Atklāj procesa pašreizējo beigu līmeni un aktivizētājus.

Diapazons ir 000-0FF. logi rezervēti, pēdējā, 200-2FF vidējā, pirmā, 300-3FF un ceturtā, 400-4FF Windows rezerves.

45. SetProcessShutdownParameters

win32process.SetProcessShutdownParameters

Sintakse

SetProcessShutdownParameters(Level, Flags)

Iestata procesa karogus un beigu prioritāti.

Parametri

    Līmenis:int (šis parametrs parāda augstāku prioritāti, kas vienāda ar agrāku)Karogi:int (Šis parametrs parāda, ka pašlaik ir spēkā tikai SHUTDOWN NORETRY).

Diapazons ir 000-0FF. 100-1FF Pēdējais, 200-2FF vidējais, 300-3FF pirmais, 400-4FF un rezervēts ar Windows logu rezervēts.

46. ​​GetGuiResources

win32process.GetGuiResources

Sintakse

int = GetGuiResources(Process, Flags )

Norāda procesa aizturēto GDI vai lietotāja objektu rokturu skaitu.

Parametri

    Process:PyHANDLE (šis parametrs Win32api::OpenProcess atgrieza procesa rokturi)Karogi:int (Šis parametrs parāda vai nu GR USEROBJECTS, vai GR GDIOBJECTS (no win32con))

47. IsWow64Process

win32process.IsWow64Process

Sintakse

bool = IsWow64Process(Process)

Identificē, vai WOW64 pašlaik palaiž norādīto procesu.

Parametri

    Process=Nav:PyHANDLE (procesa rokturis, ko atgriež win32api::OpenProcess, win32api::GetCurrentProcess utt.; ja ir norādīts None (noklusējums), tiks izmantots pašreizējais procesa rokturis.)

Apskatīsim tā atdeves vērtību.

Atgriešanas vērtība ir False, ja operētājsistēma nenodrošina šo funkciju (ti,

a NotImplemented izņēmums nekad netiks izmests). Tomēr a

win32process.error izņēmums parasti tiek izmests, ja funkcija ir pieejama

bet neefektīvi.

Secinājums

Šajā rakstā mēs esam apsprieduši Python win32 procesu. Un arī mēs pa vienam esam apsprieduši dažāda veida metodes un to parametrus un atgriešanas vērtības.