Re: Weird script issues
- From: Phyxious <Phyxious@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 3 Nov 2008 09:54:05 -0800
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
- Follow-Ups:
- Re: Weird script issues
- From: Richard Mueller [MVP]
- Re: Weird script issues
- References:
- Re: Weird script issues
- From: Phyxious
- Re: Weird script issues
- From: Richard Mueller [MVP]
- Re: Weird script issues
- Prev by Date: Re: Weird script issues
- Next by Date: Locate DNS record and create record if its missing
- Previous by thread: Re: Weird script issues
- Next by thread: Re: Weird script issues
- Index(es):
Relevant Pages
|