Aller au contenu






- - - - -

Process Tool

Posté par sebdraluorg, 26 janvier 2007 · 489 visite(s)

Ptool est un petit utilitaire de gestion des processus en ligne de commande

Pour l'instant il y a les commandes suivantes:

GetCurrentPid 'permet de recuperer le pid du processus courrant
GetParentPid 'permet de recuperer le pid du processus parent d'un processus ou du processus en cours
GetProcessList 'permet de recuperer la liste des processus en cours
GetProcessInfo 'permet de recuperer des information sur un processus depuis son pid (chemin de l'exe, user etc...)
GetProcessCount 'permet de recuperer le nombre total de processus en cours ou pour un nom donner (exemple savoir combien de fois est lancé notepad.exe)
GetPid 'permet de recuperer le pid d'un processus depuis son nom
KillProcess ' permet de teminer un processus
SuspendProcess 'permet de suspendre un processus
ResumeProcess 'permet de relancer un processus suspendu
IsProcessRunning 'permet de savoir si un processus est en cours
GetProcessAffinity 'permet de savoir sur quel core tourne un processus
SetProcessAffinity 'permet d'affecter un processus a un core
EnablePrivilege 'pour donner un privilege a un processus (exemple + liste des privileges dans le zip)
DisablePrivilege pour retirer un privilege a un processus

Je compte en ajouter petit a petit, si vous avec des suggestions...

J'ai mis quelques exemples d'utilisation dans le zip mais si vous avez des questions n'hesitez pas...

télécharger Ptool.zip
Tuto complet (html)

  • 0



P'tite mise a jour:

Ajout des deux fonctions suivantes:

GetProcessAffinity 'permet de savoir sur quel core tourne un processus
SetProcessAffinity 'permet d'affecter un processus a un core
    • 0
  • Signaler
P'tite mise a jour,

Ajout de ces deux fonctions:

EnablePrivilege 'pour donner un privilege a un processus
DisablePrivilege pour retirer un privilege a un processus

J'ai mis un exemple et la liste des privileges dans le zip

++
    • 0
  • Signaler
Bonjour,

votre software applications "Process Tool" PTool.exe et SelectCore.exe sont très interèssante. Je ne sais pas bien le francais et c'est pourquoi je prefère d'écrire mon question en anglais:

At the moment I do some tests running time critical processes on one core and all others on the other. Normally Windows assigns the affinity of a started process two both cores and there is no possibility to store the information for the next boot. Therefore I try to iterate at startup through all processes and then change their affinity to e.g. CPU1 and my time critical ones to CPU2. BUT: Normally your are not allowed to change the affinity of other processes except you have DEBUG rights or similar. By I do not find the corresponding API call to get these rights.
Is it possible that you make your source-code of PTool.exe and/or SelectCore.exe public (choose the licence model you like)?

Best regards et merci beaucoup

Lobo Marunga
    • 0
  • Signaler
Hi,

to have the debug privilege you must use the following API:

OpenProcess
AdjustTokenPrivileges
LookupPrivilegeValue
OpenProcessToken
CloseHandle

Sample in VB6
Private Const TOKEN_QUERY			   As Long = &H8&
Private Const TOKEN_ADJUST_PRIVILEGES   As Long = &H20&

Public Const SE_PRIVILEGE_ENABLED			   As Long = &H2
Public Const SE_PRIVILEGE_DISBALED			  As Long = &H0
Public Const SE_PRIVILEGE_ENABLED_BY_DEFAULT	As Long = &H1
Public Const SE_PRIVILEGE_USED_FOR_ACCESS	   As Long = &H80000000

Public Const SE_AUDIT_NAME				  As String = "SeAuditPrivilege"
Public Const SE_BACKUP_NAME				 As String = "SeBackupPrivilege"
Public Const SE_CHANGE_NOTIFY_NAME		  As String = "SeChangeNotifyPrivilege"
Public Const SE_CREATE_PAGEFILE_NAME		As String = "SeCreatePagefilePrivilege"
Public Const SE_CREATE_PERMANENT_NAME	   As String = "SeCreatePermanentPrivilege"
Public Const SE_CREATE_TOKEN_NAME		   As String = "SeCreateTokenPrivilege"
Public Const SE_DEBUG_NAME				  As String = "SeDebugPrivilege"
Public Const SE_REMOTE_SHUTDOWN_NAME		As String = "SeRemoteShutdownPrivilege"
Public Const SE_PROF_SINGLE_PROCESS_NAME	As String = "SeProfileSingleProcessPrivilege"
Public Const SE_RESTORE_NAME				As String = "SeRestorePrivilege"
Public Const SE_SECURITY_NAME			   As String = "SeSecurityPrivilege"
Public Const SE_SHUTDOWN_NAME			   As String = "SeShutdownPrivilege"
Public Const SE_SYSTEM_ENVIRONMENT_NAME	 As String = "SeSystemEnvironmentPrivilege"
Public Const SE_SYSTEM_PROFILE_NAME		 As String = "SeSystemProfilePrivilege"
Public Const SE_SYSTEMTIME_NAME			 As String = "SeSystemtimePrivilege"
Public Const SE_TAKE_OWNERSHIP_NAME		 As String = "SeTakeOwnershipPrivilege"
Public Const SE_TCB_NAME					As String = "SeTcbPrivilege"
Public Const SE_MANAGE_VOLUME_NAME		  As String = "SeManageVolumePrivilege"
Public Const SE_INC_BASE_PRIORITY_NAME	  As String = "SeIncreaseBasePriorityPrivilege"
Public Const SE_INCREASE_QUOTA_NAME		 As String = "SeIncreaseQuotaPrivilege"
Public Const SE_LOCK_MEMORY_NAME			As String = "SeLockMemoryPrivilege"
Public Const SE_LOAD_DRIVER_NAME			As String = "SeLoadDriverPrivilege"
Public Const SE_MACHINE_ACCOUNT_NAME		As String = "SeMachineAccountPrivilege"

Private Type LUID
   lowpart As Long
   highpart As Long
End Type

Private Type LUID_AND_ATTRIBUTES
   pLuid		As LUID
   Attributes   As Long
End Type

Private Type TOKEN_PRIVILEGES
   PrivilegeCount   As Long
   Privileges	   As LUID_AND_ATTRIBUTES
End Type

Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As Long, ByVal DisableAllPriv As Long, NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long				'Used to adjust your program's security privileges, can't restore without it!
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As Any, ByVal lpName As String, lpLuid As LUID) As Long		   'Returns a valid LUID which is important when making security changes in NT.
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Public Function SetPrivilege(ByVal ProcessId As Long, ByVal seName As String, ByVal Status As Boolean) As Boolean
	
	Dim hProcess			As Long
	Dim hProcessToken	   As Long
	Dim Ret				 As Long
	Dim p_lngToken		  As Long
	Dim p_lngBufferLen	  As Long
	Dim p_typLUID		   As LUID
	Dim p_typTokenPriv	  As TOKEN_PRIVILEGES
	Dim p_typPrevTokenPriv  As TOKEN_PRIVILEGES
	
	hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, ProcessId)
	If hProcess Then
		hProcessToken = OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, p_lngToken)
		If hProcessToken Then
			Ret = LookupPrivilegeValue(0&, seName, p_typLUID)
			If Ret Then
				p_typTokenPriv.PrivilegeCount = 1
				p_typTokenPriv.Privileges.Attributes = GetStatusLong(Status)
				p_typTokenPriv.Privileges.pLuid = p_typLUID
				SetPrivilege = (AdjustTokenPrivileges(p_lngToken, False, p_typTokenPriv, Len(p_typPrevTokenPriv), p_typPrevTokenPriv, p_lngBufferLen) = 1)
			End If
		End If
	End If
	
End Function

Private Function GetStatusLong(ByVal Status As Boolean) As Long
	If Status = True Then GetStatusLong = SE_PRIVILEGE_ENABLED Else GetStatusLong = SE_PRIVILEGE_DISBALED
End Function


++
    • 0
  • Signaler

Derniers billets

Mes liens Favoris

utilisateur(s) actif(s)

membre(s), invité(s), utilisateur(s) anonyme(s)

Rechercher dans le blog