Reputation: 13
how do we convert following vbscript to javascript?
<script type="text/vbscript">
Function SayHello()
MsgBox "Hello"
HKEY_LOCAL_MACHINE = "&H80000002"
uninstallRegKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
stdRegPro = "winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\default:StdRegProv"
Set objReg=GetObject(stdRegPro)
objReg.EnumKey HKEY_LOCAL_MACHINE, uninstallRegKey, arrSubKeys
MsgBox arrSubKeys
End Function
</script>
Any help appreciated.
Thanks, Lok.
Upvotes: 1
Views: 4517
Reputation: 38745
You can, if you use JScript (Microsoft's implementation of Javascript for Windows) and some information e.g.
(found by googling "jscript wmi").
Evidence:
function showUnInstall() {
var HKEY_LOCAL_MACHINE = 0x80000002;
var uninstallRegKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
var stdRegPro = "winmgmts:{impersonationLevel=impersonate}!//./root/default:StdRegProv";
var objReg = GetObject(stdRegPro);
var mEnumKey = objReg.Methods_.Item("EnumKey");
var ipEnumKey = mEnumKey.InParameters.SpawnInstance_();
ipEnumKey.hDefKey = HKEY_LOCAL_MACHINE;
ipEnumKey.sSubKeyName = uninstallRegKey;
var mGetStringValue = objReg.Methods_.Item("GetStringValue");
var ipGetStringValue = mGetStringValue.InParameters.SpawnInstance_();
ipGetStringValue.hDefKey = HKEY_LOCAL_MACHINE;
ipGetStringValue.sValueName = "DisplayName";
var opEnumKey = objReg.ExecMethod_(mEnumKey.name, ipEnumKey);
if (0 === opEnumKey.ReturnValue) {
var aNames = opEnumKey.sNames.toArray();
for ( var i = 0; i < aNames.length; ++i) {
ipGetStringValue.sSubKeyName = uninstallRegKey + "\\" + aNames[i];
var opGetStringValue = objReg.ExecMethod_(mGetStringValue.name, ipGetStringValue);
if (0 === opGetStringValue.ReturnValue) {
WScript.Echo(opGetStringValue.sValue);
} else {
WScript.Echo("ERROR: GetStringValue.ReturnValue =", opGetStringValue.ReturnValue);
}
}
} else {
WScript.Echo("ERROR: EnumKey.ReturnValue =", opEnumKey.ReturnValue);
}
}
output:
cscript 26907078.js
7-Zip 4.65
ActiveState ActiveTcl 8.5.2.0
ERROR: GetStringValue.ReturnValue = 1
Adobe Flash Player 15 Plugin
ERROR: GetStringValue.ReturnValue = 1
CMake 2.8, a cross-platform, open-source build system
Acrobat.com
...
Upvotes: 2
Reputation: 3555
You can't. Javascript does not have access to the registry.
This is not entirely accurate, I remember. A Node.js webserver running on Windows with NPM tools does have access, but only to that on the server it's running on. however, client-side javascript does not have access to the registry.
Upvotes: 1