C++ writes registry key instances
- 2020-04-02 02:52:07
- OfStack
The example of this article describes the C++ write registry to achieve the startup method. Share with you for your reference.
The specific implementation method is as follows:
void SelfRun(LPSTR lpszValueName) //The name that lpszValueName displays & NBSP; < br / >
{
LPCTSTR lpSubKey = "Software\Microsoft\Windows\CurrentVersion\Run";
HKEY hKey;
DWORD dwDisposition = REG_OPENED_EXISTING_KEY;
//Open the registry key & NBSP; < br / >
LONG lRet = ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, lpSubKey, NULL, NULL, REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
//LONG lRet = ::RegCreateKeyA(HKEY_LOCAL_MACHINE, lpSubKey, &hKey);
if ( ERROR_SUCCESS != lRet)
{
return;
}
char szModuleName[MAX_PATH]={0};
::GetModuleFileNameA(NULL, szModuleName, MAX_PATH); //Gets the current program path & NBSP; < br / >
lRet = ::RegSetValueEx(hKey, lpszValueName, NULL, REG_SZ, (BYTE*)szModuleName, strlen(szModuleName)+1); //Setting the registry key & NBSP; < br / >
if ( ERROR_SUCCESS != lRet)
{
return;
}
::RegCloseKey(hKey); //Write & NBSP; match with RegCreateKeyEx; < br / >
}
int main(int argc, char *argv[])
{
//RecursiveDelete("C:\20_128\");
SelfRun("runModel");
return 0;
}
Hope that the article described in the C++ programming to help you.