473,395 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Openprocess Error 5

Here is my code...

Expand|Select|Wrap|Line Numbers
  1. #include <windows.h> 
  2. #include <iostream> 
  3.  
  4. int main() 
  5.     DWORD pId; HWND hWnd; HANDLE hMine; 
  6.  
  7.     do { 
  8.         hWnd = FindWindow(0, "Minesweeper"); 
  9.         Sleep(10); 
  10.     } while(hWnd == NULL); 
  11.  
  12.     std::cout << "Minesweeper was found." << std::endl; 
  13.     GetWindowThreadProcessId(hWnd, &pId); 
  14.     if(pId != 0) { 
  15.         hMine = OpenProcess(PROCESS_ALL_ACCESS, 0, pId); 
  16.         if(hMine != NULL) { 
  17.             std::cout << "Opened the process." << std::endl; 
  18.             CloseHandle(hMine); 
  19.         } 
  20.     } else { 
  21.         std::cout << "Failed to find pID." << std::endl; 
  22.     } 
  23. }
  24.  
I can get the PID but I can't get the hMine to work. hMine isalways at 0. I read I need to use something like this...

Expand|Select|Wrap|Line Numbers
  1. //main.h: AdjustTokenToDebug function 
  2. BOOL AdjustTokenToDebug() 
  3.     //Define variables. 
  4.     LUID tLUID; HANDLE hToken; TOKEN_PRIVILEGES tTP, tTPOld; 
  5.     DWORD lengthReturned; BOOL ret = TRUE; 
  6.  
  7.     //Fill the tLUID struct with our privilage info. 
  8.     if(LookupPrivilegeValue(NULL,SE_DEBUG_NAME,&tLUID)) { 
  9.         //Open the token up. 
  10.         if(OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&hToken)) { 
  11.             //Modify it so we become teh debuggzors. 
  12.             tTP.PrivilegeCount=1; 
  13.             tTP.Privileges->Attributes=SE_PRIVILEGE_ENABLED; 
  14.             tTP.Privileges->Luid.HighPart=tLUID.HighPart; 
  15.             tTP.Privileges->Luid.LowPart=tLUID.LowPart; 
  16.             //Make the changes and check for errors. 
  17.             if(!AdjustTokenPrivileges(hToken,0,&tTP,sizeof(tTP),&tTPOld,&lengthReturned)) 
  18.                 ret = FALSE; //Bad 
  19.             CloseHandle(hToken); 
  20.         } else ret = FALSE; //Bad 
  21.     } else ret = FALSE; //Bad 
  22.     return ret; 
  23. }
but I don't know how. Can someone plese do this for me?
Jan 29 '08 #1
4 8540
weaknessforcats
9,208 Expert Mod 8TB
I compiled your main() and ran it on my machine. It waited until I start Minesweeper, then displayed: Opened the process.

I did this both with and without the TCHAR mappings (which you arent using and that's not good).

I used XP SP2 and Visual Studio.NET 2005.

I guess I don't see your problem.
Jan 30 '08 #2
I get Error 5: Access denied. I use Visual C++ 2008 Express. MSDN says I need to use the second code to make it work.Can someone just show me how to use the second code to make the first one work.
Jan 30 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
Is this maybe a limitation of Visual Studio Express??

I might ask Microsoft about this. I can't imagine that the Express will do all the real version will.
Jan 31 '08 #4
I've recently done some research and a lot of people are haveing trouble with the openprocess() in MSVC++ 2008. I think I'm going to switch back to 2005.
Jan 31 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ian | last post by:
Hi I am using the Openprocess api and the GetExitCodeProcess api to determine to start and finish of my shelled dos program. Does any one know how i could add a progress bar to give the user...
2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
5
by: Tony Wright | last post by:
Hi, I am having a problem installing an msi for a web site. The error message I am getting is: "The specified path 'http://mipdev05/features/Fas2' is unavailable. The Internet Information...
1
by: Aravind | last post by:
we have two files: 1. rc4.c (defines one function "create_pin()") 2. MyImpl.c(calling the function "create_pin()"),This implements JNI method. 1.When I am trying to create .dll file with one...
1
by: yanwan | last post by:
I met this problem in executing a c++ project in visual studio. Does anyone have suggestions to resolve "error lnk 2001"? --------------------Configuration: reconstruction - Win32...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.