How to open a process?

+1 Timmy Cafe · December 24, 2014
I am trying to open a process of mine, but when i run my code it's not letting me open it, here is part of my code:




        DWORD proc_id; 
        GetWindowThreadProcessId(hWnd, &proc_id);

        HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proc_id);
        if (!hProc){
            cout << "ERROR: Could not open Process!" << endl;
        }
        else{
            cout << "Process opened." << endl;
        }




Is there a way to get it to open?

Post a Reply

Replies

Oldest  Newest  Rating
0 Timmy Cafe · December 24, 2014
@Krootushas Gesu  Thank you for your reply.  The thing is i am trying to read memory from the process and i thought that i needed to open the process to read the memory?

here is my full code(so far):


#include "stdafx.h"
#include<iostream>
#include <Windows.h>
#pragma comment(lib, "user32.lib")

using namespace std;

int main()
{
    cout << "Started!" << endl;

    HWND hwmd = FindWindow(0, L"Test");

    if (hwmd == 0){
        cout << "ERROR: Could not find Test!" << endl;
    }
    else{
        cout << "Test Has Been Found." << endl;
        DWORD proc_id;
        GetWindowThreadProcessId(hwmd, &proc_id);

        HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proc_id);
        if (!hProc){
            cout << "ERROR: Could not open Process!" << endl;
        }
        else{
            cout << "Process opened." << endl;
        }
    }

    cin.get();
    return 0;
}
  • 1

C++

103,592 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator