Re: Weird script issues



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: Netlogon.bat script
    ... >Basically, I'd like it so that when a user logs into the network, their ... >username, ip address and/or computer name, time, and date are displayed on a ... I don't know want the script to be shown ...
    (microsoft.public.windows.server.scripting)
  • Re: [Full-disclosure] SSH brute force blocking tool
    ... And just what on God's earth does "SOMEONE LOGGING IN WITH USERNAME SET ... TO A VALID PASSWORD ENTRY" have to do with this script. ... the classic attack is the symlink attack. ...
    (Full-Disclosure)
  • PHP Access Script (free guide)
    ... he keys in his username and password ... in this case, if John Davis correctly log in, the script ... kick out the user. ... Browser agent to act as an invisible session ID. ...
    (alt.php)
  • Running a script in Windows2000 Server
    ... I am running Windows 2000 server from which this scrip t needs to be run. ... batch file I write a shuttdown.exe file I am recieving a (Loading script ... dim conn, rs, strsql, username, dbline, flag, errdesc ...
    (microsoft.public.windows.server.scripting)
  • Re: WSH Error when running script
    ... I am sorry let me explain further what I am wanting is a more dynamic script ... based only on their username. ... On Error GoTo 0 ... ' Temporarily suspend normal error handling. ...
    (microsoft.public.windows.server.scripting)