Mr. Cluey
: Classes : CRegCReg is designed to do the work of interacting with the Win32 Registry. It provides a simple interface to the Win32 API functions
//Defined in WinReg.h
dll "advapi32.dll"
{
LONG RegCloseKey (LONG hKey);
LONG RegOpenKeyEx (LONG hKey, STRING lpSubKey, LONG ulOptions, LONG samDesired, out LONG phkResult) alias "RegOpenKeyExA";
LONG RegQueryValueEx (LONG hKey, STRING lpValueName, LONG lpReserved, inout LONG lpType, inout STRING lpData, inout LONG lpcbData) alias "RegQueryValueExA";
LONG RegSetValueEx( LONG hKey, STRING lpValueName, LONG Reserved, LONG dwType, string lpData, LONG cbData ) alias "RegSetValueExA" ;
LONG RegDeleteValue ( LONG hKey, STRING lpValueName ) alias "RegDeleteValueA" ;
LONG RegCreateKeyEx ( LONG hKey, STRING lpSubKey, LONG Reserved, STRING lpClass, LONG dwOptions, LONG samDesired, LONG lpSecurityAttributes, out LONG phkResult, out LONG lpdwDisposition) alias "RegCreateKeyExA" ;
LONG RegDeleteKey ( LONG hKey, STRING lpSubKey ) alias "RegDeleteKeyA" ;
// returns ERROR_NO_MORE_ITEMS (259) when dwIndex is beyond the range of the enumeration
LONG RegEnumValue( LONG hKey, LONG dwIndex, out STRING lpValueName, out LONG lpcbValueName, LONG lpReserved, out LONG lpType, out STRING lpData, out LONG lpcbData ) alias "RegEnumValueA" ;
// I haven't gotten these to succeed yet - They keep generating
// ERROR_PRIVILEGE_NOT_HELD (1314)
LONG RegSaveKey ( LONG hKey, STRING lpFile, LONG lpSecurityAttributes) alias "RegSaveKeyA" ;
LONG RegRestoreKey ( LONG hKey, STRING lpFile, LONG dwFlags ) alias "RegRestoreKeyA" ;
}
private dll "advapi32.dll"
{
LONG _RegQueryLong (LONG hKey, STRING lpValueName, LONG lpReserved, inout LONG lpType, inout LONG lpData, inout LONG lpcbData) alias "RegQueryValueExA";
LONG _RegSetLong( LONG hKey, STRING lpValueName, LONG Reserved, LONG dwType, LONG lpData, LONG cbData ) alias "RegSetValueExA" ;
}
//defined in WinReg.h
// also defined in mswconst.inc
private const HKEY_LOCAL_MACHINE = 0x80000002;
//These are defined in WinNT.h
const READ_CONTROL = 0x20000;
const SYNCHRONIZE = 0x100000;
const STANDARD_RIGHTS_READ = (READ_CONTROL);
const STANDARD_RIGHTS_WRITE = (READ_CONTROL) ;
const KEY_QUERY_VALUE = 0x1;
const KEY_SET_VALUE = 0x2 ;
const KEY_CREATE_SUB_KEY = 0x4 ;
const KEY_ENUMERATE_SUB_KEYS = 0x8;
const KEY_NOTIFY = 0x10;
const KEY_READ = ((STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY) & (~SYNCHRONIZE));
const KEY_WRITE = ((STANDARD_RIGHTS_WRITE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY) & (~ SYNCHRONIZE));
type REG_DATA is enum
{
REG_NONE = 0
, REG_SZ = 1
, REG_BINARY = 3
, REG_DWORD = 4
}
//Defined in WinError.h
const ERROR_SUCCESS = 0 ;
const ERROR_PRIVILEGE_NOT_HELD = 1314 ;
const ERROR_NO_MORE_ITEMS = 259 ;
winclass CReg
{
String lpSubKey ;
Long hRootKey ;
Create ()
{
LONG hNewKey ;
LONG lDisposition ;
RegCreateKeyEx( this.hRootKey, this.lpSubKey, 0, "", 0, KEY_READ, 0, hNewKey, lDisposition ) ;
RegCloseKey( hNewKey ) ;
}
Delete ()
{
RegDeleteKey( hRootKey, lpSubKey ) ;
}
DeleteValue( string lpValueName )
{
LONG hKey ;
RegOpenKeyEx( this.hRootKey, this.lpSubKey, 0, KEY_WRITE, hKey ) ;
RegDeleteValue( hKey, lpValueName ) ;
RegCloseKey( hKey ) ;
}
anytype GetValue( string lpValueName )
{
LONG hKey ;
RegOpenKeyEx( this.hRootKey, this.lpSubKey, 0, KEY_READ, hKey ) ;
string lpData = "";
long lpcbData = Len( lpData ) ;
long lpType = REG_NONE;
anytype aRet ;
RegQueryValueEx( hKey, lpValueName, 0, lpType, lpData, lpcbData );
switch( lpType )
{
case REG_SZ:
lpData = Replicate( " ", lpcbData ) ;
RegQueryValueEx( hKey, lpValueName, 0, lpType, lpData, lpcbData );
aRet = lpData ;
case REG_DWORD:
LONG dw = 0 ;
_RegQueryLong( hKey, lpValueName, 0, lpType, dw, lpcbData ) ;
aRet = dw ;
default:
raise 123, "unrecognized value type in CReg::Get()" ;
}
RegCloseKey( hKey ) ;
return aRet ;
}
Save( string sFileName )
{
LONG hKey ;
RegOpenKeyEx( this.hRootKey, this.lpSubKey, 0, KEY_READ | KEY_WRITE, hKey ) ;
RegSaveKey( hKey, sFileName, 0 ) ;
RegCloseKey( hKey ) ;
}
Restore( string sFileName )
{
LONG hKey ;
RegOpenKeyEx( this.hRootKey, this.lpSubKey, 0, KEY_READ | KEY_WRITE, hKey ) ;
RegRestoreKey( hKey, sFileName, 0 ) ;
RegCloseKey( hKey ) ;
}
Enum ()
{
LONG hKey ;
long lenValueName = 1000 ;
string sValueName = Replicate( " ", lenValueName ) ;
long lenData = 1000 ;
string sData = Replicate( " ", lenData ) ;
LONG dwType ;
RegOpenKeyEx( this.hRootKey, this.lpSubKey, 0, KEY_READ | KEY_WRITE, hKey ) ;
int idx = 0 ;
while ( ERROR_SUCCESS == RegEnumValue( hKey, idx, sValueName, lenValueName, 0, dwType, sData, lenData ) )
{
//should probably create a list or something...
print ( "Value: " + sValueName ) ;
//Restore everything to its original state
lenValueName = 1000 ;
sValueName = Replicate( " ", lenValueName ) ;
lenData = 1000 ;
sData = Replicate( " ", lenData ) ;
++idx ;
}
RegCloseKey( hKey ) ;
}
}
type REG_SIMPLE is window ;
winclass CRegSimple : CReg
{
boolean Init( String SubKey )
{
this.hRootKey = HKEY_LOCAL_MACHINE ;
this.lpSubKey = SubKey ;
return true ;
}
}
type REG_SMART is window ;
winclass CRegSmart : CReg
{
boolean Init ( String SubKey )
{
int nBreak = StrPos( "\" , SubKey ) ;
string sRootName = Left( SubKey, nBreak - 1 ) ;
this.lpSubKey = SubStr( SubKey, nBreak + 1 ) ;
this.hRootKey = @(sRootName) ;
return true ;
}
}
main ()
{
REG_SMART theReg = CRegSmart () ;
theReg.Init( "HKEY_LOCAL_MACHINE\Software\Cluey" ) ;
theReg.Delete () ;
}
| Mr. Cluey : Classes : CReg |