Thursday, 31 January 2013

Deleting 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

<!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>Deleting Registry</title>
        <script type="text/javascript">
            function deleteRegistry() {
                var WshShell = new ActiveXObject("WScript.Shell");
                WshShell.RegDelete("HKCU\\Software\\ColdSoft Technologies\\W2SS");
                document.writeln("Registry Deleted Successfully");
            }
        </script>
    </head>
    <body onload="javascript: deleteRegistry()">

    </body>
</html>

Note: This code works only in Internet Explorer.

Reading Registry Value 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

<!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>Reading Registry Value</title>
        <script type="text/javascript">
            function readValue() {
                var WshShell = new ActiveXObject("WScript.Shell");
                var value = WshShell.RegRead("HKCU\\Software\\Microsoft\\FTP\\Use PASV");
                document.write("Value of Use PASV: " + value);
            }
        </script>
    </head>
    <body onload="javascript: readValue()">

    </body>
</html>

Note: This code works only in Internet Explorer.

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.