WScript RegRead error

sabitarai

Distinguished
Dec 18, 2009
3
0
18,510
can anyone help me with ths error :

I am using the below statement to read the registry for default printer.

var sDefault = ""
var oShell = new ActiveXObject("wscript.Shell");
var sRegVal = 'HKCU\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\Device'

sDefault = oShell.RegRead(sRegVal)
GetDefaultPrinter = sDefault


What would regRead return in case it does not find the registry, I am not able to trap that, instead I am getting a javascript error like unable to read registry key ''HKCU\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\Device'


 

btk1w1

Distinguished
Oct 13, 2008
744
0
19,060
I'm not versed in scripts, but when I export a registry key and view the bat file the path looks like this:

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion]

This is on Win 7 so obviously the registry is laid out different to XP.

There are no double back slashes though and HKCU isn't used, rather it's HKEY_CURRENT_USER

I'm too lazy to fire up XP to have a look at the differences, but have you tried exporting the part of the registry pertaining to your javascript and modifying the path accordingly?

Like I said, I have absolutely no experience with js so excuse me if this post makes it plainly (painfully) obvious :)
 

sabitarai

Distinguished
Dec 18, 2009
3
0
18,510
thank you but what i am looking in this path is default printer which is correct in XP as i see. Also i get to see the output i.e the default printer there.

HKCU is only the abbrv. for HKEY_CURRENT_USER.

can you or anyone help me with this specific error :

var sDefault = ""
var oShell = new ActiveXObject("wscript.Shell" );
var sRegVal = 'HKCU\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\Device'

sDefault = oShell.RegRead(sRegVal)
GetDefaultPrinter = sDefault


What would regRead return in case it does not find the registry, I am not able to trap that, instead I am getting a javascript error like unable to read registry key ''HKCU\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\Device'

 

sabitarai

Distinguished
Dec 18, 2009
3
0
18,510
can anyone help me with this, any idea ?

I am using the below statement to read the registry for default printer.

var sDefault = ""
var oShell = new ActiveXObject("wscript.Shell" );
var sRegVal = 'HKCU\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\Device'

sDefault = oShell.RegRead(sRegVal)
GetDefaultPrinter = sDefault


What would regRead return in case it does not find the registry, I am not able to trap that, instead I am getting a javascript error like unable to read registry key ''HKCU\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows\\Device'