Javascript to read Registry Value

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
oakguy
Posts: 1
Joined: Thu May 06, 2010 3:04 am

Javascript to read Registry Value

Post by oakguy » Thu May 06, 2010 3:15 am

I would like to read a registry value in my script and assign it to a variable but I have no clue when it comes to Jscript. The script has two functions with embeded that are called with onclick:

Code: Select all

<html>  
<head>  
<script language="javascript">   
<!--  
   var value;  
   var Shell;  
             var cicserver;  
     
   Shell = new ActiveXObject("WScript.Shell");  
   value = Shell.RegRead("HKLMSoftwareInteractive IntelligenceEICNotifier");  
   
   if value = "servername1"  
   { cicserver = "servername1"  
   }  
   else  
   { cicserver = "servername2"  
   }
Thanks!!!

User avatar
jvierra
Posts: 13736
Joined: Tue May 22, 2007 9:57 am
Contact:

Javascript to read Registry Value

Post by jvierra » Thu May 06, 2010 3:56 am

This is not shell scripting it's web scripting. YOu cannot read teh registry from aa web page. You need to use a local script; either vbs or jscript. YOu can also use an HTA.

Put this in a file with a .js extension and run it at a command prompt.

Code: Select all

var Shell = new ActiveXObject("WScript.Shell");  
var value = Shell.RegRead("HKLMSoftwareInteractive IntelligenceEICNotifier");  
   
if (value == "servername1"){  
     var cicserver = "servername1"  
}else{  
     var cicserver = "servername2"  
}  
WScript.Echo( cicserver

User avatar
jvierra
Posts: 13736
Joined: Tue May 22, 2007 9:57 am
Contact:

Javascript to read Registry Value

Post by jvierra » Thu May 06, 2010 7:05 am

This is as close as your going to get.

Code: Select all

<html>  
<head>  
<meta name="GENERATOR" content="SAPIEN Technologies PrimalScript 2009">  
<title>Document Title</title>
</head>  
<script language="jscript">  
var key = "HKLMSoftwareInteractive IntelligenceEICNotifier";  

function doit(){  
      
     var t = document.getElementById("out");  
     var Shell = new ActiveXObject("WScript.Shell");  
     var value = Shell.RegRead(key);   
     if (value == "servername1"){       
         t.innerText = "servername1"  
     }else{  
         t.innerText = "servername2"  
     }  
     return false;  
       
}  
</script>  
<body>  
<input type="button" value="click" id="getit" onclick="js:doit()"/>  
<input type="text" id="out" />
</body>  
</html>

Must be run locally from an HTA file or with warnings from an HTML file.
Due to cross-domian restrictions it will probably not run on IE from a web server. To do that you would need to use ASP.NET and some fairly sophisticated techniques to get the registry info.

Locked