WScript RegRead error

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'
3 answers Last reply
More about wscript regread error
  1. 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 :)
  2. 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'
  3. 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'
Ask a new question

Read More

Windows NT Microsoft Registry Windows XP