Obtaining User and Computer Information

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

The WshNetwork object has three read-only properties that your scripts can use to obtain information about the computer they are running on and the user account under which they are running. These properties are ComputerName, UserDomain, and UserName.

Depending on your needs, you should consider using ADSI to return this same information. WSH is able to return only the SAM account name of a user or computer (for example, kenmyer). ADSI, however, is able to return the distinguished name for these same objects. (For example, cn=ken myer,ou=Human Resources,dc=fabrikam,dc=com.) Using the distinguished name, the script can then directly bind to the object in Active Directory and perform such tasks as enumerate the groups that the user belongs to. With the SAM account name, the script would need to search Active Directory, determine the distinguished name, and then bind to the object.

There might be times, however, when simply knowing the user name, computer name, or domain name is sufficient information for your script to perform its tasks. In those instances, the WshNetwork object will likely suffice. In addition, WSH is installed by default on Windows 98 and Windows NT 4.0 computers, while ADSI is not. Because of this, WSH might be your only option when supporting computers such as those running Windows NT 4.0.

The WshNetwork object is often used in logon scripts that map different network drives, depending on the domain of the user running the script. The script in Listing 3.40 maps drive N to \\fileserver01\accounting if the user s domain is ACT or maps drive N to \\fileserver01\development if the user s domain is DEV.

Listing 3.40   Mapping a Network Drive According to User Domain

1 2 3 4 5 6 7 8 9 10 11 
Set objNetwork = WScript.CreateObject("WScript.Network") strUserDomain = objNetwork.UserDomain If strUserDomain = "ACCOUNTING" Then    objNetwork.MapNetworkDrive "N:", "\\fileserver01\accounting", True ElseIf strUserDomain = "DEVELOPMENT" Then    objNetwork.MapNetworkDrive "N:", "\\fileserver01\development", True Else    Wscript.Echo "User " & objNetwork.UserName & _        "not in ACCOUNTING or DEVELOPMENT. N: not mapped." End If

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net