 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
180fok Newbie cheater
Reputation: 0
Joined: 08 Jul 2010 Posts: 16
|
Posted: Mon Jul 12, 2010 10:25 pm Post subject: OpenProcess: it just doesn't work! |
|
|
Hi guys, my main problem is that I can't get OpenProcess to work. After many research, I'm writing here, because I am not able to continue writing my program until this problem is solved. Everything goes fine, until OpenProcess is processed. I called the function "EnablePrivilege"that was made by Wiccaan from this thread:Sorry, I can't post urls, I post the function below the code
What do I do wrong? Any help would be appreciated.
Here is my code:
Code: |
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
HWND hWndfindwindow;
hInst = hInstance; // Store instance handle in our global variable
hWndfindwindow = FindWindow(NULL,L"Untitled - Notepad");
if(hWndfindwindow == NULL)
{
MessageBox(NULL,L"Unable to attach to process",L"Error",MB_OK);
PostQuitMessage(0);
}
else
{
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, 250, 200, NULL, NULL, hInstance, NULL);
}
if (!hWnd)
return FALSE;
//ofstream file;
//file.open("Config.txt");
DWORD ProcessID = 0;
HANDLE hProcess = NULL;
ProcessID = GetWindowThreadProcessId(hWndfindwindow,NULL);
if(ProcessID == 0){
MessageBox(NULL,L"Unable to attach to process",L"Error",MB_OK);
PostQuitMessage(0);
}
EnablePrivilege(SE_DEBUG_NAME, true);
hProcess = OpenProcess(PROCESS_ALL_ACCESS,false, ProcessID);
MessageBox(NULL,L"OpenProcess fail",L"Error",MB_OK);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
} |
Code: |
BOOL EnablePrivilege(LPCTSTR lpszPrivilegeName, BOOL bEnable)
{
HANDLE hToken;
TOKEN_PRIVILEGES tp;
LUID luid;
BOOL ret;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY | TOKEN_READ, &hToken))
return FALSE;
if (!LookupPrivilegeValue(NULL, lpszPrivilegeName, &luid))
return FALSE;
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = bEnable ? SE_PRIVILEGE_ENABLED : 0;
ret = AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL);
CloseHandle(hToken);
return ret;
}
|
|
|
Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Mon Jul 12, 2010 11:52 pm Post subject: |
|
|
Code: | EnablePrivilege(SE_DEBUG_NAME, true);
hProcess = OpenProcess(PROCESS_ALL_ACCESS,false, ProcessID);
MessageBox(NULL,L"OpenProcess fail",L"Error",MB_OK); |
That doesn't make any sense. You are obviously error checking here, but the messagebox will always pop up because there's no conditional statement.
Also when i've used this in the past i believe i had to specify what access i wanted. So ALL didn't work, i had to specify read and write
_________________
|
|
Back to top |
|
 |
180fok Newbie cheater
Reputation: 0
Joined: 08 Jul 2010 Posts: 16
|
Posted: Tue Jul 13, 2010 1:35 am Post subject: |
|
|
HomerSexual wrote: | Code: | EnablePrivilege(SE_DEBUG_NAME, true);
hProcess = OpenProcess(PROCESS_ALL_ACCESS,false, ProcessID);
MessageBox(NULL,L"OpenProcess fail",L"Error",MB_OK); |
That doesn't make any sense. You are obviously error checking here, but the messagebox will always pop up because there's no conditional statement.
Also when i've used this in the past i believe i had to specify what access i wanted. So ALL didn't work, i had to specify read and write |
Somehow I deleted the if statement, but that's not the point, because when i did if(hProcess == NULL), the statement was true, so it doesn't work. I tried what you said, the "PROCESS_VM_READ | PROCESS_VM_WRITE", but still nothing. Ideas?
|
|
Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Tue Jul 13, 2010 4:10 am Post subject: |
|
|
180fok wrote: | Somehow I deleted the if statement, but that's not the point, because when i did if(hProcess == NULL), the statement was true, so it doesn't work. I tried what you said, the "PROCESS_VM_READ | PROCESS_VM_WRITE", but still nothing. Ideas? |
Also check the return value of EnablePrivilege.
Furthermore, what OS are you using.
|
|
Back to top |
|
 |
180fok Newbie cheater
Reputation: 0
Joined: 08 Jul 2010 Posts: 16
|
Posted: Tue Jul 13, 2010 4:24 am Post subject: |
|
|
tombana wrote: | 180fok wrote: | Somehow I deleted the if statement, but that's not the point, because when i did if(hProcess == NULL), the statement was true, so it doesn't work. I tried what you said, the "PROCESS_VM_READ | PROCESS_VM_WRITE", but still nothing. Ideas? |
Also check the return value of EnablePrivilege.
Furthermore, what OS are you using. |
I did check the return value of EnablePrivilege, and it was true.
I'm using windows 7 32bit with Visual c++ 2010 express. The getlasterror says(translated from my language, maybe incorrectly) "The parameter is incorrect"
|
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25796 Location: The netherlands
|
Posted: Tue Jul 13, 2010 4:54 am Post subject: |
|
|
GetWindowThreadProcessId returns the ThreadID, not the processid
The second parameter is what gets the processID
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
 |
180fok Newbie cheater
Reputation: 0
Joined: 08 Jul 2010 Posts: 16
|
Posted: Tue Jul 13, 2010 5:16 am Post subject: |
|
|
Dark Byte wrote: | GetWindowThreadProcessId returns the ThreadID, not the processid
The second parameter is what gets the processID |
Yesss! I knew if DarkByte comes in, everything will be okay:) I haven't yet tried it, but 99% that this is the problem, so thank you DB!
|
|
Back to top |
|
 |
180fok Newbie cheater
Reputation: 0
Joined: 08 Jul 2010 Posts: 16
|
Posted: Tue Jul 13, 2010 1:26 pm Post subject: |
|
|
After I took DB's advice, It still showed errorcode 57"The parameter is incorrect". Then I put the EnablePrivilege function AFTER the OpenProcess, and Getlasterror shows succesful. But still, OpenProcess returns NULL! HElp!
Code: |
LPDWORD pid = NULL;
hProcess = OpenProcess(PROCESS_ALL_ACCESS,false,(DWORD)pid);
if(hProcess == NULL)
MessageBox(NULL,L"OpenProcess fail",L"Error",MB_OK);
|
|
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25796 Location: The netherlands
|
Posted: Tue Jul 13, 2010 1:56 pm Post subject: |
|
|
try
Code: |
DWORD pid=0;
GetWindowThreadProcessId(hWndfindwindow,&pid);
hProcess = OpenProcess(PROCESS_ALL_ACCESS,false,pid);
|
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
 |
180fok Newbie cheater
Reputation: 0
Joined: 08 Jul 2010 Posts: 16
|
Posted: Tue Jul 13, 2010 2:09 pm Post subject: |
|
|
Dark Byte wrote: | try
Code: |
DWORD pid=0;
GetWindowThreadProcessId(hWndfindwindow,&pid);
hProcess = OpenProcess(PROCESS_ALL_ACCESS,false,pid);
|
|
It just works! I know you're not surprised:) Finally !
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Tue Jul 13, 2010 5:51 pm Post subject: |
|
|
In the future, instead of copying code, you may want to read up on the API and understand what they do and how to use them in the future.
_________________
- Retired. |
|
Back to top |
|
 |
bhpianist Cheater
Reputation: 1
Joined: 17 Apr 2010 Posts: 38
|
Posted: Tue Jul 20, 2010 2:32 pm Post subject: |
|
|
Doesn't PROCESS_ALL_ACCESS not work on Vista/7?
|
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25796 Location: The netherlands
|
Posted: Tue Jul 20, 2010 3:18 pm Post subject: |
|
|
works fine in vista and win 7 when you're running as admin and have granted the process SeDebugPrivilege
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|