Jump to content

_processgetpriority Shows Negative On Some


Recommended Posts

Some process priorities show correct, others show -1.

See something I am doing wrong?

#include <GuiConstants.au3>
#include <Process.au3>
$Processes = ProcessList()
GUICreate('Processes', 392, 316, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
$Processesview = GUICtrlCreateListView('Process|Process ID|Priority', 10, 20, 370, 214)
$OKButton = GUICtrlCreateButton('OK', 160, 260, 70, 30)
For $i = 1 To $Processes[0][0]
    $ListViewItem = GUICtrlCreateListViewItem($Processes[$i][0] & '|' & $Processes[$i][1] & '|' & _ProcessGetPriority($Processes[$i][1]), $Processesview)
Next
GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $OKButton
            ExitLoop
        Case Else
           ;;;
    EndSelect
WEnd
Exit
Link to comment
Share on other sites

Some process priorities show correct, others show -1.

See something I am doing wrong?

Doesn't look like you're doing anything wrong. All the processes with a -1 value are SYSTEM, LOCAL SERVICE, or NETWORK SERVICE processes.

In Process.au3, _ProcessGetPriority uses a DLLCall to OpenProcess. The first parameter is dwDesiredAccess which is set to 0x1f0fff which translates into "PROCESS_ALL_ACCESS - All possible access rights for a process object".

One would think that would be what is needed, but when I changed the value in Process.au3 to 0x0400 "PROCESS_QUERY_INFORMATION - Required to retrieve certain information about a process, such as its token, exit code, and priority class (see OpenProcessToken, GetExitCodeProcess, GetPriorityClass, and IsProcessInJob)", I got better results, and only some system processes showed up with a -1 value. I'm just tinkering here, and a little out of my league. I played with trying to add, BitAND, and BitOR the values, but didn't come up with any better results.

Someone with a little better programming knowledge can get it to work for all processes, maybe there are just some processes that can't be queried that way.

J

Edited by JerryD
Link to comment
Share on other sites

hi,

I started to write a little programm that displays the list of running and auto-executing processes.

I give you the source hoping that may help you in writing your script.

#include <GUIConstants.au3>

#include <GuiListView.au3>

#include <Process.au3>

#include <Math.au3>

#include <File.au3>

#include <Array.au3>

Opt("MustDeclareVars", 1)

Opt("GUIOnEventMode", 1)

Opt("TrayOnEventMode", 1)

Opt("TrayMenuMode", 1)

; #################################################

; ### ANALYSE DES PROCESSUS EN COURS ###

; #################################################

$i = 1

For $i = 1 To $Process_list[0][0]

$Process_priority[$i] = _ProcessGetPriority($Process_list[$i][1])

$Processus[$i] = $Process_list[$i][0] & "|" & $Process_list[$i][1] & "|" & $Process_priority[$i]

Next

Tray_Process_Controller()

; ###################################

; ##### TRIER LES LISTVIEW #####

; ###################################

Func auto_sort()

Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($LV_Auto) ]_GUICtrlListViewSort($LV_Auto, $B_DESCENDING, GUICtrlGetState($LV_Auto))

EndFunc

Func win_sort()

Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($LV_Win) ]

_GUICtrlListViewSort($LV_Win, $B_DESCENDING, GUICtrlGetState($LV_Win))

EndFunc

Func cours_sort()

Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($LV_Cours) ]

_GUICtrlListViewSort($LV_Cours, $B_DESCENDING, GUICtrlGetState($LV_Cours))

EndFunc

Func kill_sort()

Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($LV_Kill) ]

_GUICtrlListViewSort($LV_Kill, $B_DESCENDING, GUICtrlGetState($LV_Kill))

EndFunc

Func interdits_sort()

Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($LV_Interdits) ]

_GUICtrlListViewSort($LV_Interdits, $B_DESCENDING, GUICtrlGetState($LV_Interdits))

EndFunc

; ###################################

; ##### AJOUTER EN COURS #####

; ###################################

Func COURS_additem()

additem($LV_Cours,'lancer un processus')

Run($FOD)

Return $FOD

EndFunc

; ###################################

; ##### AJOUTER INTERDITS #####

; ###################################

Func INTERDITS_additem()

additem($LV_Interdits,'interdire un processus')

Return $FOD

EndFunc

; #######################################

; ##### AJOUTER UN PROCESSUS #####

; #######################################

Func additem($LV,$message)

Dim $FOD = FileOpenDialog($message, "C:\", "Application (*.exe)", 1 + 2 )

Dim $process_add = _PathSplit($FOD, $PS_Drive, $PS_Dir, $PS_FName, $PS_Ext)

_GUICtrlListViewInsertItem($LV, -1, $process_add[3] & $process_add[4])

Return $FOD

EndFunc

; ###################################

; ##### SUPPRIMER EN COURS #####

; ###################################

Func COURS_delitem()

delitem($LV_Cours)

Return $FOD

EndFunc

; ###################################

; ##### SUPPRIMER INTERDITS #####

; ###################################

Func INTERDITS_delitem()

delitem($LV_Interdits)

Return $FOD

EndFunc

; #######################################

; ##### SUPRRIMER UN PROCESSUS #####

; #######################################

Func delitem($LV)

GUICtrlSetData($Status,"")

$select_indice = _GUICtrlListViewGetItemTextArray($LV)

If (Not IsArray($select_indice)) Then

MsgBox(16,"","Aucun Processus Sélectionné")

Else

_GUICtrlListViewDeleteItemsSelected($LV)

ProcessClose($select_indice[1])

EndIf

EndFunc

; #######################################

; ##### RECHERCHER UN PROCESSUS #####

; #######################################

Func ProcSearch($Wanted)

FileChangeDir("C:\")

$PS_Path = _PathSplit($Search, $PS_Drive, $PS_Dir, $PS_FName, $PS_Ext)

$PS_Browse = FileSelectFolder ( "Recherche de " & $Wanted & " en cours",$PS_Path[1] & $PS_Path[2] & $PS_Path[3] & $PS_Path[4], "6")

Return $Search

EndFunc

; ############################################

; ##### AJOUTER UNE CLE DE REGISTRE #####

; ##### DANS LES PROCESSUS A LANCER #####

; ##### AU DEMARRAGE #####

; ############################################

Func RUN_addkey()

$FOD = FileOpenDialog("supprimer une application du démarrage", "C:\", "Application (*.exe)", 1 + 2 )

Dim $reg_addkey = _PathSplit($FOD, $PS_Drive, $PS_Dir, $PS_FName, $PS_Ext)

GuiCreate("ajouter un processus au démarrage", 220, 230,(@DesktopWidth-220)/2, (@DesktopHeight-230)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$Reg = GuiCtrlCreateList("", 30, 40, 160, 65)

GUICtrlSetData(-1,"pour l'utilisateur courant|pour tous les utilisateurs")

$Run = GUICtrlCreateCheckbox("lancer maintenant", 30, 110, 160, 30)

$Valider = GuiCtrlCreateButton("Valider", 60, 180, 100, 30)

GuiSetState()

While 1

$msg = GuiGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

GUIDelete("ajouter un processus au démarrage")

ExitLoop

Case $msg = $Valider

$Reg = GUICtrlRead($Reg)

MsgBox(0,"",$Reg)

If $Reg = "pour l'utilisateur courant" Then $Reg = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run"

If $Reg = "pour tous les utilisateurs" Then $Reg = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"

RegWrite ($Reg, $PS_FName, "REG_SZ", $FOD)

_GUICtrlListViewInsertItem($LV_Auto, -1, $PS_FName & $PS_Ext & "|" & $FOD)

If GUICtrlRead($Run) = 1 Then Run ($FOD)

GUIDelete("ajouter un processus au démarrage")

ExitLoop

EndSelect

WEnd

EndFunc

; ##############################################

; ##### SUPPRIMER UNE CLE DE REGISTRE #####

; ##### DES PROCESSUS A LANCER #####

; ##### AU DEMARRAGE #####

; ##############################################

Func RUN_delkey()

$FOD = _GUICtrlListViewGetItemText ($LV_Auto)

_GUICtrlListViewDeleteItemsSelected($LV_Auto)

$Key = StringSplit($FOD,"|")

RegDelete ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", $Key[1])

RegDelete ("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run", $Key[1])

EndFunc

; ###########################################

; ###########################################

; ##### MENUS #####

; ###########################################

; ###########################################

; ############################################

; ##### AFFICHER #####

; ##### LA FENETRE DE #####

; ##### PROCESS CONTROLLER #####

; ############################################

Func display()

Gui_Process_Controller($Processus, $Process_priority)

EndFunc

; ############################################

; ##### FERMER #####

; ##### LA FENETRE DE #####

; ##### PROCESS CONTROLLER #####

; ############################################

Func closewindow()

;~ GUIDelete("PROCESS CONTROLLER")

;~ TrayItemDelete($tray_display)

;~ TrayItemDelete($tray_empty01)

;~ TrayItemDelete($tray_saveconfig)

;~ TrayItemDelete($tray_restorconfig)

;~ TrayItemDelete($tray_empty02)

;~ TrayItemDelete($tray_reinit)

;~ TrayItemDelete($tray_empty03)

;~ TrayItemDelete($Tray_help)

;~ TrayItemDelete($tray_empty04)

;~ TrayItemDelete($tray_close)

;~ Tray_Process_Controller()

Run (@ScriptDir & "\PROCESS CONTROLLER.exe")

Exit

EndFunc

; ############################################

; ##### SAUVEGARDER #####

; ##### LA CONFIGURATION DE #####

; ##### PROCESS CONTROLLER #####

; ############################################

Func saveconfig()

FileCopy (@ScriptDir & "\PROC variables.ini", @ScriptDir & "\Config Save.ini", 1)

EndFunc

; ############################################

; ##### REINITIALISER #####

; ##### PROCESS CONTROLLER #####

; ############################################

Func reinit()

FileCopy (@ScriptDir & "\PROCESS reinit.ini", @ScriptDir & "\PROC variables.ini", 1)

Run (@ScriptDir & "\PROCESS CONTROLLER.exe")

Exit

EndFunc

; ############################################

; ##### RESTAURER #####

; #####LA DERNIERE CONFIGURATION DE #####

; ##### PROCESS CONTROLLER #####

; ############################################

Func restorconfig()

$msg = MsgBox(52,"",@CRLF & "ATTENTION," & @CRLF & "Si vous continuez, la configuration en cours sera perdue." & @CRLF & @CRLF & "Voulez-vous continuer ?" & @CRLF & @CRLF)

Select

Case $msg = 6 ;Yes

FileCopy (@ScriptDir & "\Config Save.ini", @ScriptDir & "\PROC variables.ini", 1)

Run (@ScriptDir & "\PROCESS CONTROLLER.exe")

Exit

EndSelect

EndFunc

; ############################################

; ##### AFFICHER LES INFOS DE #####

; ##### PROCESS CONTROLLER #####

; ############################################

Func info()

Dim $dfon = "logiciel de contrôle des processus", $version = "version 1.0", $date_creation = "date de création :"

Dim $createur = "Créateur : Stéphane-Hervé", $email = "contact : stephane_herve17@yahoo.fr"

MsgBox(64,"Process Controller Information", $dfon & @CRLF & $version & @CRLF & @CRLF & $date_creation & @CRLF & $createur & @CRLF & $email)

EndFunc

; ############################################

; ##### QUITTER #####

; ##### PROCESS CONTROLLER #####

; ############################################

Func close()

GUIDelete($WINgui)

Exit

EndFunc

Edited by Shao
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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