Thursday, 31 January 2013

Writing Data to Registry using JavaScript



Root Key Name
Abbreviation
HKEY_CURRENT_USER
HKCU
HKEY_LOCAL_MACHINE
HKLM
HKEY_CLASSES_ROOT
HKCR
HKEY_USERS
HKEY_USERS
HKEY_CURRENT_CONFIG
HKEY_CURRENT_CONFIG

Type
Description
In the form of
REG_SZ
A string
A string
REG_DWORD
A number
An integer
REG_BINARY
A binary value
An integer
REG_EXPAND_SZ
An expandable string (e.g., “%windir%\\calc.exe”)
A string

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>Writing Data to Registry File</title>
        <script type="text/javascript">
            function writeValue() {
                var WshShell = new ActiveXObject("WScript.Shell");
                WshShell.RegWrite("HKCU\\Software\\ColdSoft Technologies\\W2SS", "Some Value", "REG_SZ");
                document.writeln("Value Changed <br />");
                var value = WshShell.RegRead("HKCU\\Software\\ColdSoft Technologies\\W2SS");
                document.writeln("New Value is \"" + value + "\"");
            }
        </script>
    </head>
    <body onload="javascript: writeValue()">

    </body>
</html>

Note: This code only works in Internet Explorer.

No comments:

Post a Comment