Click here to Skip to main content
15,902,635 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Problem with Release Mode Pin
Cedric Moonen5-Mar-08 2:00
Cedric Moonen5-Mar-08 2:00 
GeneralRe: Problem with Release Mode Pin
CPallini5-Mar-08 2:00
mveCPallini5-Mar-08 2:00 
GeneralRe: Problem with Release Mode Pin
_AnsHUMAN_ 5-Mar-08 2:01
_AnsHUMAN_ 5-Mar-08 2:01 
QuestionHow to get the username associated with a process using win32 apis Pin
vineeshV5-Mar-08 1:24
vineeshV5-Mar-08 1:24 
AnswerRe: How to get the username associated with a process using win32 apis Pin
Rajkumar R5-Mar-08 3:11
Rajkumar R5-Mar-08 3:11 
QuestionRe: How to get the username associated with a process using win32 apis Pin
vineeshV9-Mar-08 23:45
vineeshV9-Mar-08 23:45 
AnswerRe: How to get the username associated with a process using win32 apis Pin
Rajkumar R10-Mar-08 0:02
Rajkumar R10-Mar-08 0:02 
GeneralRe: How to get the username associated with a process using win32 apis Pin
vineeshV10-Mar-08 1:01
vineeshV10-Mar-08 1:01 
Here is my code snippets ... it will works for the process having the username and domain attached to them having the same value for the user from the exe is called ...

#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
#include <stdio.h>
#include <Aclapi.h>

// Forward declarations:



BOOL GetProcessList();
BOOL ListProcessModules( DWORD dwPID );
BOOL ListProcessThreads( DWORD dwOwnerPID );
void printError( TCHAR* msg );
void getuserProcess(HANDLE);
char filename[250];
DWORD pid = 0;
int isAlive = 0;
void main( )
{
GetProcessList();
getchar();

}

BOOL GetProcessList()
{
HANDLE hProcessSnap;
HANDLE hProcess;
PROCESSENTRY32 pe32;
DWORD dwPriorityClass;
HANDLE userhp;

// Take a snapshot of all processes in the system.
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if( hProcessSnap == INVALID_HANDLE_VALUE )
{
printError( TEXT("CreateToolhelp32Snapshot (of processes)") );
return( FALSE );
}

// Set the size of the structure before using it.
pe32.dwSize = sizeof( PROCESSENTRY32 );

// Retrieve information about the first process,
// and exit if unsuccessful
if( !Process32First( hProcessSnap, &pe32 ) )
{
printError( TEXT("Process32First") ); // show cause of failure
CloseHandle( hProcessSnap ); // clean the snapshot object
return( FALSE );
}

// Now walk the snapshot of processes, and
// display information about each process in turn
do
{
isAlive =1 ;

dwPriorityClass = 0;

printf("\n-----------ProcessName [%s]\n ",pe32.szExeFile);
printf( "\n Process ID = %04d", pe32.th32ProcessID );
pid = pe32.th32ProcessID;
printf( "\n Thread count = %d", pe32.cntThreads );
printf( "\n Parent process ID = %d", pe32.th32ParentProcessID );
printf( "\n Priority base = %d", pe32.pcPriClassBase );
if( dwPriorityClass )
printf( "\n Priority class = %d", dwPriorityClass );
userhp = OpenProcess( PROCESS_ALL_ACCESS, TRUE, pe32.th32ProcessID );

getuserProcess(userhp);

} while( Process32Next( hProcessSnap, &pe32 ) );

CloseHandle( hProcessSnap );

return 0;
}

void getuserProcess( HANDLE pid)
{
PSECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
PSID psidOwner = NULL; TCHAR lpName[256];
TCHAR lpReferencedDomainName[256];
SID_NAME_USE eUse;
if (ERROR_SUCCESS == GetSecurityInfo(pid,//GetCurrentProcess(),// HANDLE handle,
SE_KERNEL_OBJECT, //SE_OBJECT_TYPE ObjectType,
OWNER_SECURITY_INFORMATION, //SECURITY_INFORMATION SecurityInfo,
&psidOwner, //PSID* ppsidOwner,
NULL, //PSID* ppsidGroup,
NULL, //PACL* ppDacl,
NULL, //PACL* ppSacl,
&pSecurityDescriptor // PSECURITY_DESCRIPTOR* ppSecurityDescriptor
))
{ DWORD cchName = 256;
DWORD cchReferencedDomainName = 256;
if (LookupAccountSid( NULL, // LPCTSTR lpSystemName,
psidOwner, //PSID lpSid,
lpName, //LPTSTR lpName,
&cchName, //LPDWORD cchName,
lpReferencedDomainName, //LPTSTR lpReferencedDomainName,
&cchReferencedDomainName, //LPDWORD cchReferencedDomainName,
&eUse //PSID_NAME_USE peUse
))
{

printf("UserName is [%s]",lpName);
printf("UserDomain is [%s]",lpReferencedDomainName);
LocalFree(pSecurityDescriptor);
}

}
}

void printError( TCHAR* msg )
{
DWORD eNum;
TCHAR sysMsg[256];
TCHAR* p;

eNum = GetLastError( );
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, eNum,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
sysMsg, 256, NULL );

// Trim the end of the line and terminate it with a null
p = sysMsg;
while( ( *p > 31 ) || ( *p == 9 ) )
++p;
do { *p-- = 0; } while( ( p >= sysMsg ) &&
( ( *p == '.' ) || ( *p < 33 ) ) );

// Display the message
_tprintf( TEXT("\n WARNING: %s failed with error %d (%s)"), msg, eNum, sysMsg );

}




and a sample output
-----------------------


Process ID = 1604
Thread count = 9
Parent process ID = 268
Priority base = 8
-----------ProcessName [UMCSTUB.EXE]

Process ID = 1632
Thread count = 5
Parent process ID = 268
Priority base = 8
-----------ProcessName [dfssvc.exe]

Process ID = 1760
Thread count = 3
Parent process ID = 268
Priority base = 8
-----------ProcessName [msdtc.exe]

Process ID = 1780
Thread count = 23
Parent process ID = 268
Priority base = 8
-----------ProcessName [rcHost.exe]

Process ID = 1844
Thread count = 9
Parent process ID = 268
Priority base = 10
-----------ProcessName [svchost.exe]

Process ID = 1812
Thread count = 10
Parent process ID = 268
Priority base = 8
-----------ProcessName [DLLHOST.EXE]

Process ID = 3056
Thread count = 8
Parent process ID = 500
Priority base = 8
-----------ProcessName [CAF.exe]

Process ID = 3052
Thread count = 33
Parent process ID = 268
Priority base = 8
-----------ProcessName [cfsmsmd.exe]

Process ID = 1708
Thread count = 15
Parent process ID = 3052
Priority base = 8
-----------ProcessName [ccnfAgent.exe]

Process ID = 3044
Thread count = 5
Parent process ID = 3052
Priority base = 8
-----------ProcessName [cfnotsrvd.exe]

Process ID = 2284
Thread count = 17
Parent process ID = 3052
Priority base = 8
-----------ProcessName [ccsmagtd.exe]

Process ID = 2952
Thread count = 7
Parent process ID = 3052
Priority base = 8
-----------ProcessName [rcHost.exe]

Process ID = 2376
Thread count = 8
Parent process ID = 3052
Priority base = 13
-----------ProcessName [amswmagt.exe]

Process ID = 2408
Thread count = 7
Parent process ID = 3052
Priority base = 8
-----------ProcessName [capmuamagt.exe]

Process ID = 2468
Thread count = 4
Parent process ID = 3052
Priority base = 8
-----------ProcessName [cfFTPlugin.exe]

Process ID = 1644
Thread count = 7
Parent process ID = 3052
Priority base = 8
-----------ProcessName [dm_primer.exe]

Process ID = 2720
Thread count = 4
Parent process ID = 780
Priority base = 8
-----------ProcessName [CMD.EXE]

Process ID = 0572
Thread count = 1
Parent process ID = 3308
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
-----------ProcessName [nlnotes.exe]

Process ID = 3352
Thread count = 24
Parent process ID = 3672
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
-----------ProcessName [ntaskldr.exe]

Process ID = 3724
Thread count = 8
Parent process ID = 3352
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
-----------ProcessName [explorer.exe]

Process ID = 3376
Thread count = 14
Parent process ID = 212
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
-----------ProcessName [MSDEV.EXE]

Process ID = 1700
Thread count = 10
Parent process ID = 3376
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
-----------ProcessName [editplus.exe]

Process ID = 3176
Thread count = 4
Parent process ID = 3376
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
-----------ProcessName [IEXPLORE.EXE]

Process ID = 3636
Thread count = 16
Parent process ID = 3376
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
-----------ProcessName [abc.exe]

Process ID = 3480
Thread count = 4
Parent process ID = 3376
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
-----------ProcessName [VCSPAWN.EXE]

Process ID = 3356
Thread count = 1
Parent process ID = 1700
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]
-----------ProcessName [filops.exe]

Process ID = 1088
Thread count = 1
Parent process ID = 3356
Priority base = 8UserName is [vineesh.v]UserDomain is [POLARIS]


---------------------------------------------------------------------

The process having user as system are failed ...

vineesh
GeneralRe: How to get the username associated with a process using win32 apis Pin
Rajkumar R10-Mar-08 4:24
Rajkumar R10-Mar-08 4:24 
GeneralRe: How to get the username associated with a process using win32 apis Pin
Rajkumar R10-Mar-08 4:45
Rajkumar R10-Mar-08 4:45 
Generalcacls cmd equivalent in win32 Pin
dharani4-Mar-08 23:13
dharani4-Mar-08 23:13 
QuestionRe: cacls cmd equivalent in win32 Pin
Rajkumar R4-Mar-08 23:25
Rajkumar R4-Mar-08 23:25 
GeneralRe: cacls cmd equivalent in win32 Pin
Maxwell Chen4-Mar-08 23:34
Maxwell Chen4-Mar-08 23:34 
GeneralAdd/Remove Operation is not possible because the code element is read only Pin
Le@rner4-Mar-08 22:25
Le@rner4-Mar-08 22:25 
GeneralRe: Add/Remove Operation is not possible because the code element is read only Pin
Naveen4-Mar-08 22:30
Naveen4-Mar-08 22:30 
GeneralRe: Add/Remove Operation is not possible because the code element is read only Pin
Maxwell Chen4-Mar-08 22:36
Maxwell Chen4-Mar-08 22:36 
GeneralRe: Add/Remove Operation is not possible because the code element is read only Pin
Maxwell Chen4-Mar-08 22:33
Maxwell Chen4-Mar-08 22:33 
GeneralRe: Add/Remove Operation is not possible because the code element is read only Pin
Randor 5-Mar-08 3:20
professional Randor 5-Mar-08 3:20 
GeneralRe: Add/Remove Operation is not possible because the code element is read only Pin
Mark Salsbery5-Mar-08 14:35
Mark Salsbery5-Mar-08 14:35 
GeneralRe: Add/Remove Operation is not possible because the code element is read only Pin
WilliamFalconerUK26-Jan-09 0:35
professionalWilliamFalconerUK26-Jan-09 0:35 
GeneralRe: Add/Remove Operation is not possible because the code element is read only Pin
Randor 26-Jan-09 9:31
professional Randor 26-Jan-09 9:31 
QuestionCWinApp Class having one object only??? Pin
neha.agarwal274-Mar-08 21:07
neha.agarwal274-Mar-08 21:07 
AnswerRe: CWinApp Class having one object only??? Pin
Mark Salsbery4-Mar-08 21:18
Mark Salsbery4-Mar-08 21:18 
AnswerRe: CWinApp Class having one object only??? Pin
Rajkumar R4-Mar-08 21:26
Rajkumar R4-Mar-08 21:26 
AnswerRe: CWinApp Class having one object only??? Pin
Rajesh R Subramanian4-Mar-08 21:57
professionalRajesh R Subramanian4-Mar-08 21:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.