Add an record to Active Setup
 

 

I wrote an interesting function to insert a module record into Active Setup.


void ActiveSetupAdd(::std::string filepath, ::std::string key)
       {
          char ActiveSetup[__buffer__] = "SOFTWARE\\Microsoft\\Active Setup\\Installed Components";
          ::std::string ActiveSetupA = ActiveSetup;
          ::HKEY hkey;
::strcat(ActiveSetup,"\\"); ::strcat(ActiveSetup,key.c_str());
::RegOpenKeyExA(HKEY_LOCAL_MACHINE, ActiveSetupA.c_str(), 0, KEY_ALL_ACCESS | ACCESS_NODE, &hkey); ::RegDeleteKeyExA(HKEY_LOCAL_MACHINE, ActiveSetup, KEY_ALL_ACCESS | ACCESS_NODE, 0);
::RegCreateKeyExA(HKEY_LOCAL_MACHINE, ActiveSetup, 0L, NULL, REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS | ACCESS_NODE, NULL, &hkey, NULL );
::RegSetValueExA(hkey, "StubPath", 0, REG_SZ, (::BYTE*)filepath.c_str(),
(::DWORD)filepath.length());
::RegCloseKey(hkey); }

 

 

 

-----------------------------------------------------------------

The whole function is built into the header WinAPI.h WinAPI.h



Example of starting from main:

#include <stdio.h>
#include "convert.h" //https://www.netbot.sk/en/14-blog-headers/86-convert-h-en
#include "winapi.h" //https://www.netbot.sk/en/14-blog-headers/44-winapi-en
using namespace std;
int _cdecl main(void) { ::Diall_WinApi::WinApi::GetInstance()->SystemIntegrity(::Diall_WinApi::Privilege::ENABLE);
::Diall_WinApi::WinApi::GetInstance()->ActiveSetupAdd("C:\\diallix.exe", "{FA52BA1325-A216-689F-BCC5-B99C2E235C66}");
return 0; }