+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    25

    OpenProcessToken cant open Process Winlogon.exe

    Code:
    #ifdef UNICODE
    #undef UNICODE
    
    #include<windows.h>
    #include <tlhelp32.h>
    int EnableDebugPriv (void){
    
    	HANDLE hToken = 0;
    	TOKEN_PRIVILEGES newPrivs;
    
    	if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
    		return 0;
    
    	if(!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &newPrivs.Privileges[0].Luid)){
    		CloseHandle (hToken);
    		return 0;
    	}
    	newPrivs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    	newPrivs.PrivilegeCount = 1;
    	if(AdjustTokenPrivileges(hToken, FALSE, &newPrivs, 0, NULL, NULL)){
    		CloseHandle (hToken);
    		return 1;
    	}else{
    		CloseHandle (hToken);
    		return 0;
    	}
    }
    TCHAR convertChar(TCHAR q)
    {
    	if (q >= 'a' && q<= 'z')
    	{
    		return (q - ' ');
    	}
    	else
    	{
    		return q;
    	}
    } //hoa
    TCHAR *convertString(TCHAR *chuoi)
    {
    	int n= lstrlen(chuoi);
    	int i;
    	for(i=0;i<n;i++)
    	{
    		chuoi[i] = hoa(chuoi[i]); 
    	}
    	return chuoi;
    }
    int main()
    {
    	EnableDebugPriv();
    	PROCESS_INFORMATION pi;
    	STARTUPINFO si;
    	DWORD winlogonPid = 0;
    	HANDLE hPToken, hProcess;
    	PROCESSENTRY32 procEntry;
    	HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    	if (hSnap == INVALID_HANDLE_VALUE) 
    		return 0;
    	procEntry.dwSize = sizeof(PROCESSENTRY32);
    	if (!Process32First(hSnap, &procEntry))    
    		return 0;
    	do
    	{
    		if (_stricmp(convertString(procEntry.szExeFile),"WINLOGON.EXE") == 0)
    		{
    			winlogonPid = procEntry.th32ProcessID;
    			break;
    		}
    	} while (Process32Next(hSnap, &procEntry));
    	hProcess = OpenProcess(MAXIMUM_ALLOWED, FALSE, winlogonPid);
    	if (hProcess == NULL)
    	{
    		MessageBox(0,"loi OpenProcess","d",0);
    		return 0;
    	}
    	if(OpenProcessToken(hProcess,TOKEN_DUPLICATE,&hPToken) == FALSE)
    	{
    		MessageBox(0,"loi OpenProcessToken","d",0);
    		return 0;
    	}
    }
    
    #endif
    i dont understand why OpenProcessToken cant Open Process Winlogon.exe,why???,can you help me edit source ,thank

  2. #2
    Senior Member FusioN's Avatar
    Join Date
    Mar 2009
    Location
    O__O
    Posts
    368
    its a system process
    ┌∩┐()┌∩┐ Delighted!

  3. #3
    Junior Member
    Join Date
    Sep 2009
    Posts
    25
    but i was Enable Debug Privilege

  4. #4
    Junior Member
    Join Date
    Sep 2009
    Posts
    25
    Code:
    #ifdef UNICODE
    #undef UNICODE
    
    #include<windows.h>
    #include <tlhelp32.h>
    int EnableDebugPriv (void){
    
    	HANDLE hToken = 0;
    	TOKEN_PRIVILEGES newPrivs;
    
    	if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))
    		return 0;
    
    	if(!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &newPrivs.Privileges[0].Luid)){
    		CloseHandle (hToken);
    		return 0;
    	}
    	newPrivs.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    	newPrivs.PrivilegeCount = 1;
    	if(AdjustTokenPrivileges(hToken, FALSE, &newPrivs, 0, NULL, NULL)){
    		CloseHandle (hToken);
    		return 1;
    	}else{
    		CloseHandle (hToken);
    		return 0;
    	}
    }
    TCHAR convertChar(TCHAR q)
    {
    	if (q >= 'a' && q<= 'z')
    	{
    		return (q - ' ');
    	}
    	else
    	{
    		return q;
    	}
    } //hoa
    TCHAR *convertString(TCHAR *chuoi)
    {
    	int n= lstrlen(chuoi);
    	int i;
    	for(i=0;i<n;i++)
    	{
    		chuoi[i] = convertChar(chuoi[i]); 
    	}
    	return chuoi;
    }
    int main()
    {
    	EnableDebugPriv();
    	PROCESS_INFORMATION pi;
    	STARTUPINFO si;
    	DWORD winlogonPid = 0;
    	HANDLE hPToken, hProcess;
    	PROCESSENTRY32 procEntry;
    	HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    	if (hSnap == INVALID_HANDLE_VALUE) 
    		return 0;
    	procEntry.dwSize = sizeof(PROCESSENTRY32);
    	if (!Process32First(hSnap, &procEntry))    
    		return 0;
    	do
    	{
    		if (_stricmp(convertString(procEntry.szExeFile),"WINLOGON.EXE") == 0)
    		{
    			winlogonPid = procEntry.th32ProcessID;
    			break;
    		}
    	} while (Process32Next(hSnap, &procEntry));
    	hProcess = OpenProcess(MAXIMUM_ALLOWED, FALSE, winlogonPid);
    	if (hProcess == NULL)
    	{
    		MessageBox(0,"loi OpenProcess","d",0);
    		return 0;
    	}
    	if(OpenProcessToken(hProcess,TOKEN_DUPLICATE,&hPToken) == FALSE)
    	{
    		MessageBox(0,"loi OpenProcessToken","d",0);
    		return 0;
    	}
    }
    
    #endif

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Open a file used by another process.
    By mabazzer in forum Delphi Help
    Replies: 5
    Last Post: 26-09-2008, 18:53
  2. Replies: 1
    Last Post: 29-05-2008, 12:19
  3. Open url
    By OD_ in forum Delphi Help
    Replies: 1
    Last Post: 13-03-2006, 08:45
  4. Open a FTP Server
    By unreachableboy in forum Delphi Help
    Replies: 2
    Last Post: 22-10-2005, 12:06
  5. Open a FTP Server
    By unreachableboy in forum General Programming Help
    Replies: 4
    Last Post: 22-10-2005, 12:01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.