Re: user and workstation name
From: Richard Mueller [MVP] (rlmueller-NOSPAM_at_ameritech.NOSPAM.net)
Date: 11/25/04
- Next message: martin: "Re: user and workstation name"
- Previous message: Lanwench [MVP - Exchange]: "Re: Script to set local ip address in router with dynamic ip chang"
- In reply to: martin: "user and workstation name"
- Next in thread: martin: "Re: user and workstation name"
- Reply: martin: "Re: user and workstation name"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 25 Nov 2004 09:57:41 -0600
martin wrote:
> i have some simple script what is using:
>
> set Net = CreateObject("WScript.Network")
> uname = LCase(Net.UserName)
> wname = LCase(Net.ComputerName)
>
> Sometimes i get both correct information, sometimes only one and sometimes
> nothing.
Hi,
Your code snippet looks fine. It should work as written on any client with
Windows 2000 or above, and on any NT, Windows 98, or Windows 95 client with
DSClient installed.
However, the user must be logged into a domain in order to retrieve
Net.UserName. An error is raised if the user is not authenticated to a
domain. If you have "On Error Resume Next", this error is ignored but uname
is blank. The script will continue and retrieve Net.ComputerName. I cannot
think of a way for Net.ComputerName to return nothing unless you have a
client with no machine name.
If this code snippet is in a logon script, it will work as written on any
client with NT or above (if the NT client has DSClient). On Windows 95 and
Windows 98 Net.UserName will most likely be blank, but this can be fixed.
The problem in a logon script is that the user has not yet been
authenticated when the script runs. This can be fixed by using a loop to
continually retrieve Net.UserName until it is not blank. For example, I use
the following in a logon script that will run on Windows 95/98. I make sure
the Wscript version is greater than 5 because the Sleep command requires
version 1.5. The Sleep is recommended because it prevents cpu usage going to
100%.
------------------
Set objNetwork = CreateObject("Wscript.Network")
' Loop required for Win9x clients during logon.
strNTName = ""
On Error Resume Next
Do While strNTName = ""
strNTName = objNetwork.userName
Err.Clear
If Wscript.Version > 5 Then
Wscript.Sleep 100
End If
Loop
On Error GoTo 0
-------------------
I hope this helps.
Richard Mueller
Hilltop Lab - http://www.rlmueller.net
- Next message: martin: "Re: user and workstation name"
- Previous message: Lanwench [MVP - Exchange]: "Re: Script to set local ip address in router with dynamic ip chang"
- In reply to: martin: "user and workstation name"
- Next in thread: martin: "Re: user and workstation name"
- Reply: martin: "Re: user and workstation name"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|