Click here to Skip to main content
15,885,899 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Team,
In vbscript, we have a method
JavaScript
GetStringValue()
which returns the data value for a named value whose data type is REG_SZ.

Is there a similar method in javascript too ?

Any help appreciated.

Thanks,
Lok..
Posted

1 solution

This specific method of VBScript does not work if you are opening a page in internet zone, and that for security reason. Imagine that any web site you browse was able to read your local registry!!!
For the very same - security - reason JavaScript not even have such functionality to read the registry keys (remember that JavaScript was created for the web, where VBScript has dual functionality)...
---
From your question I understood that you have some web application that as part of its functionality reads the registry - that is a very bad behavior and you MUST check your design!
 
Share this answer
 
Comments
RaisKazi 10-Nov-14 10:38am    
My 5 for your Answer.
Kornfeld Eliyahu Peter 10-Nov-14 12:18pm    
Thank you...
Lokesh Zende 11-Nov-14 0:38am    
Yes there is a risk but can't help it. Below is the function in vbscript that I want to convert in javascript. If you can help, would be greatfull.

Function GetWebStationVersion()
const HKEY_LOCAL_MACHINE = &H80000002
const uninstallRegKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
const stdRegPro = "winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\default:StdRegProv";


Set objReg=GetObject(stdRegPro)

objReg.EnumKey HKEY_LOCAL_MACHINE, uninstallRegKey, arrSubKeys

For Each subkey In arrSubKeys
objReg.GetStringValue HKEY_LOCAL_MACHINE, uninstallRegKey & "\" & subkey, "DisplayName", strDisplayName
If InStr(1, strDisplayName, "My webstation", vbTextCompare) > 0 Then
objReg.GetStringValue HKEY_LOCAL_MACHINE, uninstallRegKey & "\" & subkey, "DisplayVersion", strVersion
Exit For
End If
Next
GetWebStationSVersion = strVersion
End Function
Kornfeld Eliyahu Peter 11-Nov-14 1:25am    
If you would run that code in my machine I would kick your ass as bad as I can!!!

There are ways by using ActiveX objects (namely WScript.Shell) to read registry. Fortunately it works only on IE and for new versions this option is disabled by default, so end user have to allow it to run...
All these mean that your code is prone to fail in any case...

var WshShell = new ActiveXObject("WScript.Shell");
var value = WshShell.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");

I would suggest you that instead of try and 'translate' your code, formulate - in human language - the goals of this code and them search solutions for that!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900