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.
This topic is 13 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
oakguy
Posts: 1
Last visit: Thu May 06, 2010 3:15 am

Javascript to read Registry Value

Post 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!!!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Javascript to read Registry Value

Post 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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Javascript to read Registry Value

Post 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.
This topic is 13 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked