Page 1 of 1

Javascript to read Registry Value

Posted: Thu May 06, 2010 3:15 am
by oakguy
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!!!

Javascript to read Registry Value

Posted: Thu May 06, 2010 3:56 am
by jvierra
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

Javascript to read Registry Value

Posted: Thu May 06, 2010 7:05 am
by jvierra
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.