Re: Weird script issues



During logon you can retrieve the name of the current user from the
wshNetwork object or the ADSystemInfo object. There is no need to use WMI.
For example:
=============
' Retrieve the "pre-Windows 2000 logon" name of the current user.
' This is also called the NT name of the user.
Set objNetwork = CreateObject("Wscript.Network")
strNTName = objNetwork.UserName

' Retrieve the Distinguished Name of the current user.
Set objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.UserName

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"Phyxious" <Phyxious@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:24802FA2-1363-44E0-9737-C16742A13FBE@xxxxxxxxxxxxxxxx
I also have the script as a logon script, so each time a user logs in it
will
run. I even get the error when a user logs in, so .UserName should not be
NULL.

"Richard Mueller [MVP]" wrote:


"Phyxious" <Phyxious@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:048E1ED5-3E47-4551-AED3-3FE9C67BE812@xxxxxxxxxxxxxxxx
I can not find the machine that was causing this issue so I can not give
you
the exact error that was occuring. But here is portion of my code:

sComputer = InputBox("Enter IP Address", "IP Address", "150.142.")
Set oWMIService =
GetObject("winmgmts:{impersonationlevel=impersonate}!\\"
&
sComputer & "\root\cimv2")
'On Error Resume Next
' Call Win32_ComputerSystem class to get information about the pc
Set cComputerSystem = oWMIService.ExecQuery("SELECT * FROM
Win32_ComputerSystem")

' Loop through the collection and store data in variables
For Each oComputerSystem In cComputerSystem
With oComputerSystem
If InStr(.Manufacturer, "Hewlett") > 0 Then
sProductNumber = ProductNumber(sComputer)
sManufacturer = "HP"
sModel = Mid(.Model, InStr(.Model, "Compaq"), 13)
Else
sManufacturer = "Dell"
sModel = .Model
End If

aUserName = Split(.UserName, "\")
sPCName = .Name
End With
Next

sDomain = aUserName(0)
sUserName = aUserName(1)

It would fail at the line aUserName = Split(.UserName, "\") because
.UserName is NULL. Now at the time I ran the script I verified that a
user
is
logged on by using SysInternals psloggedon application, so really I do
not
understand why it would come back NULL


The only time I get the error "Invalid use of Null: 'Split'" is when no
one
is logged into the computer. I assume that you get a value for sPCName,
so
you know that the script successfully connected to the remote computer.
If
so, that means you can retrieve .Name but not .UserName, which cannot be
explained.

Since in general you will not know if someone is logged in (or you
wouldn't
be retrieving .UserName) it would make sense to check for the Null
condition. Perhaps similar to:
==========
With oComputerSystem
sName = .UserName
If Not IsNull(sName) Then
aUserName = Split(sName, "\")
sDomain = aUserName(0)
sUserName aUserName(1)
Else
sDomain = "none"
sUserName = "none"
End If
End With
=======
I did not bother to check if UBound of aUserName is greater than 0, as in
my
tests there is always a "\" in the value of .UserName, even if the user
is
local.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
End With





.



Relevant Pages

  • Re: Login Script to Garther Information
    ... A VBScript logon script should be able to retrieve this information. ... One issue is that all of the items are machine specific except AD UserName. ... The other items you mention require WMI. ...
    (microsoft.public.windows.server.scripting)
  • Re: Getting GROUPS from Active Directory by inputing an AD username
    ... But whan i want to do is to have a textbox and when i input a AD username ... i would like to retrieve the groups they belong to. ... WindowsIdentity that hangs off Context.User... ... I'm thinking of doing the same but against Active Directory. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: How to retrieve User- name and group via VBA???
    ... > group that he / she belongs to ... CurrentUserwill get you the username. ... can use to retrieve the group information. ... which are accessing forms that the User Usergroup ...
    (microsoft.public.access.security)
  • Re: user name variable
    ... In VBScript you can retrieve the current username from the wshNetwork ... script, ... Set objShell = CreateObject ... Username does not work ... ...
    (microsoft.public.scripting.vbscript)

Loading