I want to get the path from where the application is installed. There is an entry in the registry that gives the path to my application, see this screenshot:
http://i56.tinypic.com/2ly1l6s.jpg
I want to read the path where my application is located. In other words, I need part of C: \ Projects \ MyApplication \ MyApplication.exe. Here is what I am trying to do:
HKEY hKey;
wchar_t mydata[2048];
DWORD dataLength = sizeof(mydata);
DWORD dwType = REG_SZ;
LPVOID messagecaliss;
LONG regOpenCriss = RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\", 0, KEY_QUERY_VALUE, &hKey);
GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), NULL,(LPTSTR) &messagecaliss, 0, NULL );
if (regOpenCriss == ERROR_SUCCESS) {
RegQueryValueEx(HKEY_CURRENT_USER, "TestApplication", 0, &dwType, (BYTE*)mydata, &dataLength);
wprintf(L"%s\n", mydata);
system("PAUSE");
}
else
MessageBox(NULL,(LPCTSTR)messagecaliss,"ERROR",MB_OK|MB_ICONINFORMATION);
This does not work, unwanted characters are printed. Thank you very much.
source
share