#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Posts
    65
    Rep Power
    15

    Bizzare problem - finding username


    Hi,

    Though I can easily get around this issue but I am baffled and looking for an explanation as to why this is happening...using Windows 7...below I have included 2 different ways of identifying the username but the first one (a.k.a. GOOD) works and second one (a.k.a. BAD) does NOT...any ideas why? Obviously, the only different is the name of the object WSH between GOOD & BAD, but it shouldn't matter...!

    GOOD
    Code:
    Set oWSH = CreateObject("WScript.Shell")
    sUserName = oWSH.ExpandEnvironmentStrings("%UserName%")
    MsgBox "User is " & sUserName
    BAD
    Code:
    Set WSH = CreateObject("WScript.Shell")
    sUserName = WSH.ExpandEnvironmentStrings("%UserName%")
    MsgBox "User is " & sUserName
    ERROR
    Microsoft Line 1, char1, VBScript run time error: Wrong number of arguments or invalid property assignment: 'WSH'

    Thanks!
  2. #2
  3. Type Cast Exception
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    OAKLAND CA | Adam's Point (Fairyland)
    Posts
    14,954
    Rep Power
    8617
    I would assume that WSH (Windows Script Host) is a reserved word. Probably the interpreter holds it for backward compatibility or such, I don't honestly know but this would seem to be where the evidence points.
    medialint.com

    “Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss
  4. #3
  5. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,005
    Rep Power
    9398
    WSH is a (deprecated it seems) name for WScript.
    Code:
    MsgBox TypeName(WSH) ' Object
    MsgBox WSH ' Windows Script Host
    You can Dim it to get your own copy.
    Code:
    Dim WSH
    Set WSH = CreateObject("WScript.Shell")

    Comments on this post

    • medialint agrees : Yes that's what I was concluding too
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Posts
    65
    Rep Power
    15
    Thanks guys...appreciate your time!

IMN logo majestic logo threadwatch logo seochat tools logo