Re: Weird script issues

Tech-Archive recommends: Fix windows errors by optimizing your registry




"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: Trying to compare usernmae to a group membership
    ... If InStr(sMembers, sUserName) 0 Then ... is using that script in say, ... I can't do the above; It won't let me compare the "dsget..." ... So I'm trying to compare the %USERNAME% to ...
    (microsoft.public.windows.server.scripting)
  • Re: Escape Characters
    ... Is your issue in how to get the username or how to map the drive? ... So, if you want to do both, get the username and map a drive to a share ... Dim oNetwork, sUsername, sRemotePath ... Set oNetwork = CreateObject ...
    (microsoft.public.scripting.vbscript)
  • Re: Username = NULL -- Why?
    ... Why the username is intermittent is driving me crazy. ... Dim oWMI, colProc, oProcess, sUser, sDomain ... If lRet = 0 Then ... torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.scripting.wsh)
  • Re: Escape Characters
    ... > Is your issue in how to get the username or how to map the drive? ... > So, if you want to do both, get the username and map a drive to a share ... > Dim oNetwork, sUsername, sRemotePath ... >> get my script to map to a share a hidden share. ...
    (microsoft.public.scripting.vbscript)
  • Understanding the formveiw ItemInserting Bug ASP.Net 2.0?
    ... I don't quite under stand this event in a formview. ... UserName that has to be updated before the isert happens. ... Now I stopped the code and verified that the sUserName had a value and ...
    (microsoft.public.dotnet.framework.aspnet)