Wow64 Sample Script

  • Print

Here is a sample script in Lua that shows almost every action that is available in the Wow64 actions plugin. You can see how to test for errors, and how to set and retrieve data using the actions.

Further explanations can be found in the help file that is installed with the plugin.

You can also download this script from here.

--
-- File System Redirection tests
--
 
local os = System.GetOSVersionInfo();
if (System.Is64BitOS() or String.ToNumber(os.MajorVersion) >= 6) then
    -- test file system redirection
    Wow64.DisableFsRedirection();
    local error = Application.GetLastError();
    if (error ~= 0) then
        Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
    else
        Dialog.Message("Info", "File system redirection disabled successfully", MB_OK, 
            MB_ICONINFORMATION);
 
        -- create test file in protected folder
        local target = _WindowsFolder .. "\\System32\\Testfile.txt";
        TextFile.WriteFromString(target, "This is a test");
        error = Application.GetLastError();
        if (error ~= 0) then
            Dialog.Message("Error", _tblErrorMessages[error].."\r\n"..target, MB_OK, 
                MB_ICONEXCLAMATION);
        else
            Dialog.Message("Info", target .. " created successfully", MB_OK, 
                MB_ICONINFORMATION);
            -- delete test file
            File.Delete(target, false, false, true);
            if (error ~= 0) then
                Dialog.Message("Error", _tblErrorMessages[error], MB_OK, 
                    MB_ICONEXCLAMATION);
            end
        end
 
        -- revert file system redirection
        Wow64.RevertFsRedirection();
        error = Application.GetLastError();
        if (error ~= 0) then
            Dialog.Message("Error", _tblErrorMessages[error], MB_OK, 
                MB_ICONEXCLAMATION);
        else
            Dialog.Message("Info", "File system redirection restored successfully", 
                MB_OK, MB_ICONINFORMATION);
        end
 
        -- repeat the test file WITHOUT disabling the FS redirection
        -- now the file will actually be created in  _WindowsFolder\SysWOW64 !!!
        TextFile.WriteFromString(target, "This is a test");
        error = Application.GetLastError();
        if (error ~= 0) then
            Dialog.Message("Error", _tblErrorMessages[error].."\r\n"..target, MB_OK,
                MB_ICONEXCLAMATION);
        else
            Dialog.Message("Info", target .. " created successfully", MB_OK, 
                MB_ICONINFORMATION);
            -- delete test file
            File.Delete(target, false, false, true);
            if (error ~= 0) then
                Dialog.Message("Error", _tblErrorMessages[error], MB_OK, 
                    MB_ICONEXCLAMATION);
            end
        end
    end
else
    Dialog.Message("Info", "File system redirection not supported on this OS", MB_OK, 
        MB_ICONINFORMATION);
end
 
--
-- Registry access tests
--
 
-- try to disable registry reflection
res = Wow64.RegistryDisableReflectionKey(HKEY_LOCAL_MACHINE, "Software");
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    Dialog.Message("Info", "Registry reflection disabled", MB_OK, MB_ICONINFORMATION);
end
 
-- try to enable registry reflection
res = Wow64.RegistryEnableReflectionKey(HKEY_LOCAL_MACHINE, "Software");
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    Dialog.Message("Info", "Registry reflection enabled", MB_OK, MB_ICONINFORMATION);
end
 
local RegistryView = Wow64.KEY64;
-- On 64-bit Windows:
-- Wow64.KEY64 creates entries in HKEY_LOCAL_MACHINE\Software\MindQuake\Test
-- Wow64.KEY32 creates entries in HKEY_LOCAL_MACHINE\Software\Wow6432Node\MindQuake\Test
 
-- On 32-bit Windows:
-- you may use only Wow64.KEY32 for RegistryView or some functions, like
-- Wow64.RegistryDeleteKey(), are not expected to work correctly
 
-- create a registry key
local res = Wow64.RegistryCreateKey(HKEY_LOCAL_MACHINE, "Software\\MindQuake\\Test", 
            RegistryView);
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    Dialog.Message("Info", "Registry key created", MB_OK, MB_ICONINFORMATION);
end
 
-- set several values of different data types
res = Wow64.RegistrySetValue(HKEY_LOCAL_MACHINE, "Software\\MindQuake\\Test", 
      "Dummy_REG_SZ", "blah", REG_SZ, RegistryView);
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    Dialog.Message("Info", "REG_SZ value was set successfully", MB_OK, MB_ICONINFORMATION);
end
 
res = Wow64.RegistrySetValue(HKEY_LOCAL_MACHINE, "Software\\MindQuake\\Test", 
      "Dummy_REG_DWORD", 123456789, REG_DWORD, RegistryView);
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    Dialog.Message("Info", "REG_DWORD value was set successfully", MB_OK, MB_ICONINFORMATION);
end
 
res = Wow64.RegistrySetValue(HKEY_LOCAL_MACHINE, "Software\\MindQuake\\Test", 
      "Dummy_REG_BINARY", "00 01 02 03 04 05 06 07 08", REG_BINARY, RegistryView);
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    Dialog.Message("Info", "REG_BINARY value was set successfully", MB_OK, MB_ICONINFORMATION);
end
 
res = Wow64.RegistrySetValue(HKEY_LOCAL_MACHINE, "Software\\MindQuake\\Test", 
      "Dummy_REG_MULTI_SZ", "Line1|Line2|Line3", REG_MULTI_SZ, RegistryView);
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    Dialog.Message("Info", "REG_MULTI_SZ value was set successfully", MB_OK, MB_ICONINFORMATION);
end
 
res = Wow64.RegistrySetValue(HKEY_LOCAL_MACHINE, "Software\\MindQuake\\Test", 
      "Dummy_REG_EXPAND_SZ", "%UserProfile%", REG_EXPAND_SZ, RegistryView);
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    Dialog.Message("Info", "REG_EXPAND_SZ value was set successfully", MB_OK, MB_ICONINFORMATION);
end
 
-- get key names
tKeyNames = Wow64.RegistryGetKeyNames(HKEY_LOCAL_MACHINE, "Software\\MindQuake", RegistryView);
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    if (Table.Count(tKeyNames) > 0) then
        for i,name in pairs(tKeyNames) do
            Dialog.Message("Info", "Key "..i..": "..name, MB_OK, MB_ICONINFORMATION);
        end
    else
        Dialog.Message("Info", "No keys found", MB_OK, MB_ICONINFORMATION);
    end
end
 
-- read value names
tValueNames = Wow64.RegistryGetValueNames(HKEY_LOCAL_MACHINE, "Software\\MindQuake\\Test", 
              RegistryView);
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    if (Table.Count(tValueNames) > 0) then
        for i,name in pairs(tValueNames) do
            Dialog.Message("Info", "Value "..i..": "..name, MB_OK, MB_ICONINFORMATION);
        end
    else
        Dialog.Message("Info", "No values found", MB_OK, MB_ICONINFORMATION);
    end
end
 
-- get value type
res = Wow64.RegistryGetValueType(HKEY_LOCAL_MACHINE, "Software\\MindQuake\\Test", 
      "Dummy_REG_SZ", RegistryView);
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    Dialog.Message("Info", "Dummy_REG_SZ is type "..res, MB_OK, MB_ICONINFORMATION);
end
 
-- get values
res = Wow64.RegistryGetValue(HKEY_LOCAL_MACHINE, "Software\\MindQuake\\Test", 
      "Dummy_REG_EXPAND_SZ", true, RegistryView);
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    Dialog.Message("Info", "Dummy_REG_EXPAND_SZ contains "..res, MB_OK, MB_ICONINFORMATION);
end
 
res = Wow64.RegistryGetValue(HKEY_LOCAL_MACHINE, "Software\\MindQuake\\Test", 
      "Dummy_REG_DWORD", true, RegistryView);
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    Dialog.Message("Info", "Dummy_REG_DWORD contains "..res, MB_OK, MB_ICONINFORMATION);
end
 
res = Wow64.RegistryGetValue(HKEY_LOCAL_MACHINE, "Software\\MindQuake\\Test", 
      "Dummy_REG_MULTI_SZ", true, RegistryView);
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    Dialog.Message("Info", "Dummy_REG_MULTI_SZ contains "..res, MB_OK, MB_ICONINFORMATION);
end
 
res = Wow64.RegistryGetValue(HKEY_LOCAL_MACHINE, "Software\\MindQuake\\Test", 
      "Dummy_REG_BINARY", true, RegistryView);
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    Dialog.Message("Info", "Dummy_REG_BINARY contains "..res, MB_OK, MB_ICONINFORMATION);
end
 
-- check if key exists
res = Wow64.RegistryDoesKeyExist(HKEY_LOCAL_MACHINE, "Software\\MindQuake\\Test", 
      RegistryView);
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    if res then
        Dialog.Message("Info", "Registry key does exist", MB_OK, MB_ICONINFORMATION);
    else
        Dialog.Message("Info", "Registry key does not exist", MB_OK, MB_ICONINFORMATION);
    end
end
 
-- delete value
res = Wow64.RegistryDeleteValue(HKEY_LOCAL_MACHINE, "Software\\MindQuake\\Test", "Dummy_REG_SZ",
      RegistryView);
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    Dialog.Message("Info", "REG_SZ value was deleted successfully", MB_OK, MB_ICONINFORMATION);
end
 
-- delete test key and data
res = Wow64.RegistryDeleteKey(HKEY_LOCAL_MACHINE, "Software\\MindQuake\\Test", RegistryView);
error = Application.GetLastError();
if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
    Dialog.Message("Info", "Registry key deleted successfully", MB_OK, MB_ICONINFORMATION);
end
 
Application.Exit();
 

Add a comment (For questions, please use the contact form!)

Security code
Refresh

Our Plugins & Examples Feed

  • POP3 Actions plugin released

    A new, free actions plugin was released today. With it, the developer can check POP3...

  • Reminder: Update Serial Number Validation and/or Subscription Validation

    Next week IPInfoDB's API 2.0 will stop working. If you use an older version than...

Subscribe now!

Advertisement