Home Download Screenshots Wiki Plugins Translations Developers Donate Forums/Help Contact Us |
StrokeIt
0.97 "enhanced" [alien] Registry set values - not working error huntingPosted by Leo
Hello I want manipulate Registry but is not working so far. This is my
little script. require[[alien]] local RegSetValueEx= alien.Advapi32.RegSetValueExA RegSetValueEx:types{ret ='long', abi = 'stdcall','long','string','long','long','string','long'} local RegOpenKeyEx= alien.Advapi32.RegOpenKeyExA RegOpenKeyEx:types{ret ='long', abi = 'stdcall','long','string','long','long','long'} local RegCloseKey= alien.Advapi32.RegCloseKey RegCloseKey:types{ret ='long', abi = 'stdcall','long'} local hKey = alien.buffer(512) RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\StrokeIt\\UsageCount",0, KEY_ALL_ACCESS, hKey) RegSetValueEx(hKey, "UsageCount", 0, REG_DWORD, 1, 5) RegCloseKey(hKey) Thanks Leo
The registry editing functions are a little tricky, but here's an example that you should be able to use.
Windows uses a lot of "magic numbers" (constants) that are usually defined in ALL_CAPS. To use these in a lua script, you'll need to define the number before using the constants. require [[alien]] -- Windows constants local HKEY_CURRENT_USER = 0x80000001 local HKEY_LOCAL_MACHINE = 0x80000002 local HKEY_USERS = 0x80000003 local REG_DWORD = 4 local KEY_ALL_ACCESS = 0xF003F local KEY_READ = 0x20019 local ERROR_SUCCESS = 0 local MB_OK = 0 -- Define the windows functions that we'll be calling local RegOpenKeyEx = alien.Advapi32.RegOpenKeyExA RegOpenKeyEx:types { ret ='long', abi = 'stdcall', 'ulong', 'string', 'ulong', 'ulong', 'pointer' } local RegSetValueEx = alien.Advapi32.RegSetValueExA RegSetValueEx:types { ret ='long', abi = 'stdcall', 'ulong', 'string', 'ulong', 'ulong', 'pointer', 'ulong' } local RegCloseKey = alien.Advapi32.RegCloseKey RegCloseKey:types { ret ='long', abi = 'stdcall', 'ulong' } local MessageBox = alien.User32.MessageBoxA MessageBox:types { ret = 'long', abi = 'stdcall', 'long', 'string', 'string', 'long' } function RegSetDWORD( hKeyRoot, sKeyName, sValueName, dwValue) -- Create a buffer for the value we are writing local cDataSize = 4 -- DWORD values are 4 bytes long local lpData = alien.buffer(cDataSize) lpData:set(1, dwValue, "ulong"); -- Copy the value into the buffer local phKey = alien.buffer(4) -- create a buffer for the key handle -- Open the registry key local ret = RegOpenKeyEx( hKeyRoot, sKeyName, 0, KEY_ALL_ACCESS, phKey ) if ( ret ~= ERROR_SUCCESS ) then MessageBox(0, "Could not open key\nError: " .. tostring(ret) , "Error", MK_OK) else local hKey = phKey:get(1, "ulong"); -- get the handle from the buffer -- Write the new value ret = RegSetValueEx( hKey, sValueName, 0, REG_DWORD, lpData, cDataSize ) if ( ret ~= ERROR_SUCCESS ) then MessageBox(0, "Could not write key\nError: " .. tostring(ret) , "Error", MK_OK) end -- Always close the registry key when we're done using it RegCloseKey( hKey ) end end RegSetDWORD(HKEY_CURRENT_USER, "Software\\TCB Networks\\StrokeIt", "UsageCount", 1)
|