"TeddyBear" <TeddyBear[ at ]discussions.microsoft.com> wrote in message news:29F770C0-20BA-4322-8981-3F27C4FCAAB4[ at ]microsoft.com...
[Quoted Text] >I would like to retrieve the UserID/Username of the user logged on either >on > a network or the local PC. Then I would like to change the case of the > Username to lower case. I would then like to identify who the user is in > my > script and based on who it is take the appropriate action.
We need to know who is running the script and from where.
Is the user running the script, perhaps in a logon script? Are you running the script from another machine?
In a logon script (or a script run by the user), the following VBScript program would retrieve the user Distinguished Name and use this to retrieve the NT Name of the user (the "pre-Windows 2000 logon name"): ============== Set objSysInfo = CreateObject("ADSystemInfo") ' Retrieve current user Distinguished Name. strUserDN = objSysInfo.UserName ' Bind to user object. Set objUser = GetObject("LDAP://" & strUserDN) ' Retrieve NT Name (pre-Windows 2000 logon name). strNTName = objUser.sAMAccountName ' Perform action based on NT Name (lower case). Select Case LCase(strNTName) Case "jimsmith" ' do something. Case "sallyrogers" ' do something. Case "willjohnson" ' do something. End Select ========== If all you need is the NT Name of the user, it can also be retrieved from the wshNetwork object: =========== Set objNetwork = CreateObject("Wscript.Network") strNTName = objNetwork.UserName ' ... -- Richard Mueller Microsoft MVP Scripting and ADSI Hilltop Lab - http://www.rlmueller.net --
|