1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include <iostream>
#include <windows.h>
#include <cstring>
int main( int, char*[], char* envp[] )
{
static const char path[] = "Path" ;
{
std::cout << "process-specific path for this process:\n----------------------------\n" ;
for( std::size_t i = 0 ; envp[i] != nullptr ; ++i )
{
if( std::strncmp( envp[i], path, sizeof(path)-1 ) == 0 ) std::cout << envp[i] << '\n' ;
}
}
static BYTE buffer[1000000] ; // lazy
DWORD buffsz = sizeof(buffer) ;
{
std::cout << "\nsystem default path:\n----------------------------\n" ;
// HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment Path=
const char key_name[] = R"(System\CurrentControlSet\Control\Session Manager\Environment)" ;
HKEY key ;
if( RegOpenKeyExA( HKEY_LOCAL_MACHINE, key_name, 0, KEY_QUERY_VALUE, std::addressof(key) ) == 0 &&
RegQueryValueExA( key, path, nullptr, nullptr, buffer, std::addressof(buffsz) ) == 0 )
{
std::cout << reinterpret_cast<const char*>(buffer) << '\n' ;
}
}
{
std::cout << "\nuser default path:\n----------------------------\n" ;
// HKEY_CURRENT_USER\Environment Path=
const char key_name[] = "Environment" ;
HKEY key ;
if( RegOpenKeyExA( HKEY_CURRENT_USER, key_name, 0, KEY_QUERY_VALUE, std::addressof(key) ) == 0 &&
RegQueryValueExA( key, path, nullptr, nullptr, buffer, std::addressof(buffsz) ) == 0 )
{
std::cout << reinterpret_cast<const char*>(buffer) << '\n' ;
}
}
}
|