I am trying to search the registry's uninstall folder for a given program that I know is there by checking regedit. My function currently finds the program, but for some reason it doesn't update the output value from the RegGetValue function until the next iteration. So it prints the correct registry key and its predecessor. Any ideas?
I am on a Windows 10 64bit workstation with Intel processors using Visual Studio 2015 if that matters.
main.cpp
#include "Registry.h"
#include <Windows.h>
#include <tchar.h>
void main()
{
Registry test(_T("Microsoft SQL Server 2012 Native Client "));
}
Registry.h
#pragma once
#include <Windows.h>
#include <string>
#define REG_PATH L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
#define X86REG_PATH L"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
class Registry
{
public:
Registry(TCHAR* name);
~Registry();
TCHAR* findGUID();
TCHAR* getDisplayName();
TCHAR* getGUID();
TCHAR* getVersion();
TCHAR* getPublisher();
TCHAR* getInstallDate();
private:
TCHAR* displayName;
TCHAR* guid;
TCHAR* version;
TCHAR* publisher;
TCHAR* installDate;
};
Registry.cpp
#pragma once
#include "Registry.h"
#include <Windows.h>
#include <iostream>
#include <tchar.h>
#include <fstream>
Registry::Registry(TCHAR* name)
{
HKEY hKey;
LPCTSTR lpSubKey;
DWORD ulOptions;
REGSAM samDesired;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_PATH, NULL, KEY_READ, &hKey) == ERROR_SUCCESS)
{
std::wofstream file;
file.open("test.txt");
int index = 0;
HKEY UninstallDir = hKey;
TCHAR subKey[MAX_PATH];
DWORD subKeySize = MAX_PATH;
while (RegEnumKeyEx(hKey, index, subKey, &subKeySize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
{
HKEY guid;
TCHAR* guidPath = new TCHAR[MAX_PATH];
_tcscpy_s(guidPath, MAX_PATH, REG_PATH);
_tcscat_s(guidPath, MAX_PATH, subKey);
TCHAR compareName[MAX_PATH];
DWORD nameSize;
//print all registry keys to file
file << index << ": " << guidPath << std::endl;
int test;
RegGetValue(HKEY_LOCAL_MACHINE, guidPath, _T("DisplayName"), RRF_RT_ANY, NULL, &compareName, &nameSize);
//compare all registry keys *temporary to debug
if (_tcscmp(guidPath, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{49D665A2-4C2A-476E-9AB8-FCC425F526FC}")) == 0)
{
std::wcout << guidPath << " found" << std::endl;
}
if (_tcscmp(compareName, name) == 0)
{
_tprintf(_T("%d: %s\n"), index, guidPath);
}
//print if found
index++;
subKeySize = 260;
}
file.close();
}
else
{
std::cout << "Could not open registry key." << std::endl;
}
//temporary to see console
std::cin.get();
}
//still need to be completed
Registry::~Registry()
{
}
TCHAR* Registry::findGUID()
{
return _T("");
}
TCHAR* Registry::getDisplayName()
{
return _T("");
}
TCHAR* Registry::getGUID()
{
return _T("");
}
TCHAR* Registry::getVersion()
{
return _T("");
}
TCHAR* Registry::getPublisher()
{
return _T("");
}
TCHAR* Registry::getInstallDate()
{
return _T("");
}
I see a lot of problems with your code.
You are mixing std::wcout and _tprintf(), which causes buffering conflicts.
You are mixing char and wchar_t data incorrectly.
You are leaking guidPath on every loop iteration.
You are not initializing nameSize when calling RegGetValue().
You are not setting up your code to access the 32bit Wow64Node key correctly.
Try something more like this instead.
main.cpp
#include <Windows.h>
#include "Registry.h"
void main()
{
Registry test(L"Microsoft SQL Server 2012 Native Client");
}
Registry.h
#pragma once
#include <Windows.h>
#include <string>
class Registry
{
public:
Registry(const std::wstring &name);
~Registry();
std::wstring findGUID();
std::wstring getDisplayName();
std::wstring getGUID();
std::wstring getVersion();
std::wstring getPublisher();
std::wstring getInstallDate();
private:
std::wstring displayName;
std::wstring guid;
std::wstring version;
std::wstring publisher;
std::wstring installDate;
};
Registry.cpp
#pragma once
#include <Windows.h>
#include "Registry.h"
#include <iostream>
#include <fstream>
#define REG_PATH L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
Registry::Registry(const std::wstring &name)
{
HKEY hKey;
// If you want to open the 32bit Wow64Node key,
// DO NOT open the key directly! Open the 64bit
// key and include the KEY_WOW64_32KEY flag
// so it will redirect to the Wow64Node key...
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_PATH, NULL, KEY_READ, &hKey) == ERROR_SUCCESS)
{
std::wofstream file;
file.open(L"test.txt");
WCHAR subKey[MAX_PATH];
DWORD subKeySize = MAX_PATH;
WCHAR compareName[MAX_PATH];
DWORD nameSize;
int index = 0;
while (RegEnumKeyEx(hKey, index, subKey, &subKeySize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
{
// print all registry keys to file
file << index << L": " << REG_PATH << subKey << std::endl;
int test;
nameSize = sizeof(compareName);
RegGetValue(hKey, NULL, L"DisplayName", RRF_RT_REG_SZ | RRF_RT_REG_EXPAND_SZ | RRF_ZEROONFAILURE, NULL, compareName, &nameSize);
//compare all registry keys *temporary to debug
if (wcscmp(subKey, L"{49D665A2-4C2A-476E-9AB8-FCC425F526FC}") == 0)
{
std::wcout << subKey << L" found" << std::endl;
}
if (name == compareName)
{
std::wcout << name << L" found" << std::endl;
}
//print if found
index++;
subKeySize = MAX_PATH;
}
file.close();
}
else
{
std::wcout << L"Could not open registry key." << std::endl;
}
//temporary to see console
std::wcin.get();
}
//still need to be completed
Registry::~Registry()
{
}
std::wstring Registry::findGUID()
{
return L"";
}
std::wstring Registry::getDisplayName()
{
return L"";
}
std::wstring Registry::getGUID()
{
return L"";
}
std::wstring Registry::getVersion()
{
return L"";
}
std::wstring Registry::getPublisher()
{
return L"";
}
std::wstring Registry::getInstallDate()
{
return L"";
}
Related
I haven't been able to find anything else about this online at all. I have a simple authenticator program, with a .dll injector written into it. If the key matches the one in the database, it will run the injector, and constantly check to make sure that the key is still active. For some reason, my console window outputs "tick" about every second. When the injector is taken out, and it is just the authenticator it will not do this.
#include <iostream>
#include <string>
#include <Windows.h>
#include <thread>
#include <WinInet.h>
#include <TlHelp32.h>
#include <fcntl.h>
#include <io.h>
#include <fcntl.h>
#include <cstdio>
#include <chrono>
#include "include/c0gnito.h"
std::string Key;
std::string hwid = GetHardwareID(); //Gets the hwid
char* StringToChar(std::string string) //A function to convert a string to a char
{
return _strdup(string.c_str());
}
template <class T>
void msg(T msg)
{
std::cout << msg << std::endl;
}
bool FileExists(const std::string& fileName)
{
struct stat buffer;
return (stat(fileName.c_str(), &buffer) == 0);
}
void WriteStringToIni(std::string string, std::string file, std::string app, std::string key)
{
WritePrivateProfileStringA(app.c_str(), key.c_str(), string.c_str(), file.c_str());
}
std::string ReadStringFromIni(std::string file, std::string app, std::string key)
{
char buf[100];
GetPrivateProfileStringA(app.c_str(), key.c_str(), "NULL", buf, 100, file.c_str());
return (std::string)buf;
}
LONG address = 0x0;
BYTE newvalue[] = { 0x0 };
HWND hwnd;
HANDLE phandle;
DWORD pid;
DWORD GetProcId(const char* procName)
{
DWORD procId = 0;
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnap != INVALID_HANDLE_VALUE)
{
PROCESSENTRY32 procEntry;
procEntry.dwSize = sizeof(procEntry);
if (Process32First(hSnap, &procEntry))
{
do
{
if (!_stricmp(procEntry.szExeFile, procName))
{
procId = procEntry.th32ProcessID;
break;
}
} while (Process32Next(hSnap, &procEntry));
}
}
CloseHandle(hSnap);
return procId;
}
const char* dllPath = "C:\\Windows\\System32\\sysproc.dll";
const char* procName = "Project1.exe";
DWORD procId = 0;
int main() //Entry point
{
system("color b"); //Sets the color to blue
Initialize("B2wVksYPzgCBOtNq8SFQ05GCuKrzwNIRytotMczYWCSv59sypLJhPEnLY9w8cmml"); //Connects to the authentication server
if (FileExists("./Config.ini"))
{
Key = ReadStringFromIni("./Config.ini", "License", "Key"); //Gets the key saved in the file
}
else
{
std::cout << "Welcome, please enter your license key: ";
std::cin >> Key; //Gets the user's key
if (Authenticate(StringToChar(Key), (StringToChar(hwid)))) {}// Authenticates key & hwid
else
{
std::cout << "Invalid Key!" << std::endl;
exit(2000);
}
WriteStringToIni(Key, "./Config.ini", "License", "Key"); //Creates a file that stores the key entered
}
if (Authenticate(StringToChar(Key), (StringToChar(hwid)))) // Authenticates key & hwid
{
std::cout << "Sucessfully Authenticated!" << std::endl;
Sleep(2000);
while (!procId)
{
procId = GetProcId(procName);
Sleep(30);
}
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, 0, procId);
if (hProc && hProc != INVALID_HANDLE_VALUE)
{
void* loc = VirtualAllocEx(hProc, 0, MAX_PATH, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
WriteProcessMemory(hProc, loc, dllPath, strlen(dllPath) + 1, 0);
HANDLE hThread = CreateRemoteThread(hProc, 0, 0, (LPTHREAD_START_ROUTINE)LoadLibraryA, loc, 0, 0);
if (hThread)
{
CloseHandle(hThread);
}
}
if (hProc)
{
CloseHandle(hProc);
}
}
else
{
exit(0);
}
system("cls");
std::cout << "Hardware ID: " << hwid << std::endl;
std::cout << "_______________________________________________________" << std::endl;
std::cout << " " << std::endl;
std::thread auth([&]() //Authentication Thread that keep on checking the connection and user previleges
{
while (true)
{
std::cout << "Auth is checking..." << std::endl;
if (!Authenticate(StringToChar(Key), (StringToChar(hwid))))
{
exit(0);
}
std::cout << "Sucessfully Authenticated!" << std::endl;
Sleep(60000);
}
});
std::cin.get();
}
I would like to check the UAC configuration settings of windows. And thus recover the parameters of the UAC in the registry keys.
I used the windows SHGetValue function but the status always returns me 2 without any information.
I use C++11, MinGW and windows.
My code is :
DWORD dwStatus;
LPCSTR pszSubKey= "HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
LPCSTR pszValue="";
DWORD pdwType=REG_SZ;
PVOID pvData[63];
DWORD pcbData;
pcbData=sizeof(pvData);
dwStatus=SHGetValueA(HKEY_LOCAL_MACHINE, pszSubKey, pszValue, &pdwType, pvData, &pcbData);
//Here dwStatus = 2
// pvData = 0x11fd0b2
// pcbData = 504
What specific key you are trying to read? I am not an expert on win32 API so I don't know whether there is a way to read a set of keys at once (Edit: I think there areRegEnumValue/RegEnumValueA functions for this purpose). Here is an example that shows how you can read "EnableLUA" or any other key from that path:
#include <windows.h>
#include <iostream>
#include <shlwapi.h>
bool ReadUACRegistryKey(char* key, DWORD &keyValue)
{
LPCTSTR pszSubKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
LPCTSTR pszValue = key;
// don't care
DWORD dwType = 0;
DWORD dwValue = 0;
//
DWORD dwValueSize = sizeof(dwValue);
int retval = SHGetValue( HKEY_LOCAL_MACHINE, pszSubKey, key, &dwType, &dwValue, &dwValueSize);
if ( retval != ERROR_SUCCESS)
{
return false;
}
keyValue = dwValue;
return true;
}
int main()
{
DWORD keyValue;
char* key = "EnableLUA"; // "EnableSecureUIAPaths" etc..;
if (ReadUACRegistryKey(key, keyValue))
{
std::cout << "Successfully readed key " << key << ", value:" << keyValue << std::endl;
}
else
{
std::cout << "Unable to read value of key " << key << std::endl;
}
return 0;
}
Also keep in mind that value of read key value is stored in value parameter, not in the return value of the function.
Edit: Answer of the the op's comment "I want use FilterAdministratorToken but is disable by default how give it back enable .?". Keep in mind that your process need to have admin rights to perform these operation.
#include <windows.h>
#include <iostream>
#include <shlwapi.h>
bool ReadUACRegistryKey(char* key, DWORD &keyValue)
{
LPCTSTR pszSubKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
LPCTSTR pszValue = key;
// don't care
DWORD dwType = 0;
DWORD dwValue = 0;
//
DWORD dwValueSize = sizeof(dwValue);
int retval = SHGetValue( HKEY_LOCAL_MACHINE, pszSubKey, key, &dwType, &dwValue, &dwValueSize);
if ( retval != ERROR_SUCCESS)
{
return false;
}
keyValue = dwValue;
return true;
}
bool EnableFilterAdministratorToken()
{
// first check if its already enabled or not
DWORD val;
if (ReadUACRegistryKey("FilterAdministratorToken", val))
{
if (val == 1)
{
std::cout << "FilterAdministratorToken is already enabled" << std::endl;
return true;
}
}
else
{
std::cout << "Unable to read key" << std::endl;
return false;
}
// its not enabled, we need to enable it manually
// obtain a handle to reg key
HKEY hKey;
int retval = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", 0, KEY_SET_VALUE, &hKey);
if (retval != ERROR_SUCCESS)
{
// we are unable to obtain a handle to reg key
std::cout << "Unable to obtain handle to reg key" << std::endl;
return false;
}
DWORD enabledValue = 1;
retval = RegSetValueExA(hKey, "FilterAdministratorToken", 0, REG_DWORD, (BYTE*) &enabledValue, sizeof(DWORD));
if (retval != ERROR_SUCCESS)
{
// some error occured
std::cout << "Some error occured during setting the key value" << std::endl;
RegCloseKey(hKey);
return false;
}
std::cout << "Successfully changed key value" << std::endl;
RegCloseKey(hKey);
return true;
}
int main()
{
if (EnableFilterAdministratorToken())
{
std::cout << "OK" << std::endl;
}
else
{
std::cout << "FAIL" << std::endl;
}
return 0;
}
I'm new in c++. I'm trying to list files in dir. I'm using unicode. The problem is not listing files but treat string and paths with wchar*, I'm going mad. Here's my test code:
#define UNICODE 1
#include <stdio.h>
#include <windows.h>
#include <wchar.h>
int wmain(int argc,wchar_t **argv){
if (argc > 1){
wchar_t* path=argv[1];
wchar_t* pwc;
int last_occurence;
pwc=wcsrchr(path,L'\\');
last_occurence = pwc-path+1;
int len = wcslen(path);
if (last_occurence == len){
//slash
}else{
//no slash
wcscat(path,L"\\");
}
wcscat(path,L"*");
WIN32_FIND_DATA FindData;
HANDLE hSearch;
hSearch = FindFirstFile(path , &FindData);
if(hSearch == INVALID_HANDLE_VALUE){
return -1;
}else{
// *** PROBLEM STARTS HERE
wchar_t* filePath=NULL;
do{
wcscpy(filePath,path);
wcscat(filePath,FindData.cFileName);
wprintf(L"Path %s\n",filePath);
memset(filePath, '\0', wcslen(filePath));
// *** PROBLEM ENDS HERE
}while( FindNextFile(hSearch, &FindData) > 0 );
int ret = FindClose(hSearch);
return 0;
}
}
}
When I run the compiled app, it stops responding. What I would like to do is print the path I pass to my app (c:\dir1\dir2) and append the files in it (file1,file2) as follows:
c:\dir1\dir2\file1
c:\dir1\dir2\file2
How to solve this problem? There are best methods to do something like this? I would remain with wchar not std string if possible
There are a few issues with your code.
you are concatenating "\\*" to the memory that argv[1] points to, which is bad. You need to change path from a wchar_t* pointer to an wchar_t[] array, and then wcscpy the argv[1] data into it.
you are not allocating any memory for filePath, so wcscpy() and wcscat() are writing to invalid memory. You need to change filePath to a wchar_t[] array as well, and then wcscpy/wcscat the path data into it.
you are also not ignoring the concatenated * when combining the path and cFileNames values together.
you don't need the memset() at all (especially since you are giving it the wrong byte count anyway).
Try something more like this instead:
#define UNICODE 1
#include <stdio.h>
#include <windows.h>
#include <wchar.h>
int wmain(int argc, wchar_t **argv)
{
if (argc < 2)
{
wprintf(L"Usage: \"%s\" path\n", argv[0]);
return -1;
}
int len = wcslen(argv[1]);
if (len >= MAX_PATH)
{
wprintf(L"Path is too long\n");
return -1;
}
wchar_t path[MAX_PATH+1] = {};
wcscpy(path, argv[1]);
if ((len > 0) && (path[len-1] != L'\\'))
wcscat(path, L"\\");
wchar_t searchMask[MAX_PATH+2] = {};
wcscpy(searchMask, path);
wcscat(searchMask, L"*");
WIN32_FIND_DATA FindData;
HANDLE hSearch = FindFirstFileW(searchMask, &FindData);
if (hSearch == INVALID_HANDLE_VALUE)
{
if (GetLastError() != ERROR_FILE_NOT_FOUND)
{
wprintf(L"Error looking for first file\n");
return -1;
}
wprintf(L"No files found\n");
}
else
{
wchar_t filePath[MAX_PATH*2];
do
{
wcscpy(filePath, path);
wcscat(filePath, FindData.cFileName);
wprintf(L"Path %s\n", filePath);
}
while (FindNextFileW(hSearch, &FindData));
if (GetLastError() != ERROR_NO_MORE_FILES)
{
FindClose(hSearch);
wprintf(L"Error looking for next file\n");
return -1;
}
FindClose(hSearch);
}
return 0;
}
Though, you really should be using the std::unique_ptr and std::wstring classes and let them manage memory/resources for you. Using C library functions is not helping you learn C++:
#define UNICODE 1
#include <windows.h>
#include <wchar.h>
#include <iostream>
#include <string>
#include <memory>
struct FindDeleter
{
typedef HANDLE pointer;
void operator()(HANDLE h)
{
if(h != INVALID_HANDLE_VALUE)
FindClose(h);
}
};
int wmain(int argc, wchar_t **argv)
{
if (argc < 2)
{
std::wcerr << L"Usage: \"" << argv[0] << L"\" path" << std::endl;
return -1;
}
std::wstring path = argv[1];
if ((!path.empty()) && (path[path.length()-1] != L'\\'))
path += L'\\';
WIN32_FIND_DATA FindData;
std::unique_ptr<HANDLE, FindDeleter> hSearch(FindFirstFileW((path + L"*").c_str(), &FindData));
if (hSearch.get() == INVALID_HANDLE_VALUE)
{
if (GetLastError() != ERROR_FILE_NOT_FOUND)
{
std::wcerr << L"Error looking for first file" << std::endl;
return -1;
}
std::wcout << L"No files found" << std::endl;
}
else
{
do
{
std::wstring filePath = path + FindData.cFileName;
std::wcout << L"Path " << filePath << std::endl;
}
while (FindNextFileW(hSearch.get(), &FindData));
if (GetLastError() != ERROR_NO_MORE_FILES)
{
std::wcerr << L"Error looking for next file" << std::endl;
return -1;
}
}
return 0;
}
Or, if you are not using a C++11 compiler:
#define UNICODE 1
#include <windows.h>
#include <wchar.h>
#include <iostream>
#include <string>
class FindHandle
{
private:
HANDLE m_hFind;
public:
FindHandle(HANDLE hFind) : m_hFind(hFind) {}
~FindHandle()
{
if (m_hFind != INVALID_HANDLE_VALUE)
FindClose(m_hFind);
}
HANDLE get() { return m_hFind; }
};
int wmain(int argc, wchar_t **argv)
{
if (argc < 2)
{
std::wcerr << L"Usage: \"" << argv[0] << L"\" path" << std::endl;
return -1;
}
std::wstring path = argv[1];
if ((!path.empty()) && (path[path.length()-1] != L'\\'))
path += L'\\';
WIN32_FIND_DATA FindData;
FindHandle hSearch(FindFirstFileW((path + L"*").c_str(), &FindData));
if (hSearch.get() == INVALID_HANDLE_VALUE)
{
if (GetLastError() != ERROR_FILE_NOT_FOUND)
{
std::wcerr << L"Error looking for first file" << std::endl;
return -1;
}
std::wcout << L"No files found" << std::endl;
}
else
{
do
{
std::wstring filePath = path + FindData.cFileName;
std::wcout << L"Path " << filePath << std::endl;
}
while (FindNextFileW(hSearch.get(), &FindData));
if (GetLastError() != ERROR_NO_MORE_FILES)
{
std::wcerr << L"Error looking for next file" << std::endl;
return -1;
}
}
return 0;
}
How can i get current file name without path, i want to use it on WinExec,
example for what am trying to do,
WinExec("Do something to <mycurrentfilename.exe>", SW_HIDE);
In common case you have to use GetModuleFileName function.
Example:
#include <Windows.h>
#include <sstream>
int main(void) {
char myexepath[MAX_PATH] = { 0 };
DWORD returnCode = GetModuleFileNameA(NULL, myexepath, MAX_PATH);
if (returnCode != 0 && returnCode < MAX_PATH)
{
std::string filepath(myexepath);
filepath = filepath.substr(filepath.find_last_of('\\') + 1);
std::ostringstream ss;
ss << "Do something to \"" << filepath << "\"";
WinExec(ss.str().c_str(), SW_HIDE);
}
else
{
// process GetModuleFileName error.
}
return 0;
}
Example uses char encoding for filename, but it can be changed to wchar_t or universal TCHAR
So, I've now fought with this for 2 days, still the same error.
I've been on over 300 results with google, still same FAILURE. It shows up as HEX all the time or it doesn't work at all.
This is not using any external librarys and no .net framework.
100% non-dependent.
I've tried over 30 methods.
TCHAR szExeFileName[MAX_PATH];
GetModuleFileName(NULL, szExeFileName, MAX_PATH);
^ Doesn't work; returns hex.
The code is in a void.
#include "SharedHeader.h"
#include <Psapi.h>
#include "CommandLine_Pres.h"
#include <TlHelp32.h>
using namespace std;
void filePath()
{
// Figure out file path of current file
char cCurrentPath[FILENAME_MAX];
if(!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath)))
{
cout << "error" << endl;
}
cCurrentPath[sizeof(cCurrentPath) -1] = '\0';
cout << cCurrentPath << endl;
// Get process id, filename
//cout << GetCommandLine();
int procId = GetCurrentProcessId();
SYSTEM_INFO si;
GetNativeSystemInfo(&si);
/*
DOES NOT WORK BELOW [debug]
HANDLE Handle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE,GetCurrentProcessId());
if(Handle)
{
TCHAR Buffer[MAX_PATH];
if(GetModuleFileNameEx(Handle, 0, Buffer, MAX_PATH))
{
}
else
{
}
CloseHandle(Handle);
}*/
}
To get the address of the current running process you can use:
#include <iostream>
int main(int argc, char** argv)
{
std::cout << argv[0] << std::endl;
getchar();
return 0;
}
or:
#include <iostream>
#include <windows.h>
int main()
{
char szExeFileName[MAX_PATH];
GetModuleFileName(NULL, szExeFileName, MAX_PATH);
std::cout << szExeFileName;
getchar();
return 0;
}