Thread: WSH Problem

    #1
  1. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,236
    Rep Power
    1469

    WSH Problem


    Okay anyone got an explanation?

    [code=regtest.vbs]
    strRegValue = "HKLM\Software\Microsoft\Windows\CurrentVersion\ProductID"

    Set WshShell = WScript.CreateObject("WScript.Shell")

    strPID = WshShell.RegRead (strRegValue)
    Wscript.Echo strPID

    WshShell.RegDelete strRegValue
    Wscript.Echo "The registry value has been deleted."

    WshShell.RegWrite strRegValue, strPID
    Wscript.Echo "The registry value has been written back."
    [/code]

    Why am I recieving an error when I use the VBScript syntax for the RegRead method (without parenthesis)? The RegWrite and RegDelete methods both work properly, but the RegRead method won't execute without parenthesis.
    Last edited by nilpo; August 12th, 2006 at 05:37 AM.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Posts
    2
    Rep Power
    0
    Hi Nilpo,

    The reason is because the RegWrite and RegDelete routines are Sub routines and are not returning a value.

    The RegRead routine is a Function and does return a value.

    Vbscript syntax requires that a function always is followed by parenthesis even if no value is passed into the function.

    I think this dates to the original coding syntax defined for vbscript.
  4. #3
  5. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,236
    Rep Power
    1469
    RegRead IS a function? That's interesting. It does make sense considering it returns the value it finds in the registry. I wasn't aware of that. Thanks for the heads up.
    Last edited by nilpo; August 17th, 2006 at 02:05 PM.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!

IMN logo majestic logo threadwatch logo seochat tools logo