VBScript runtime error: Wrong number of arguments or invalid property assignment
I'm trying to get the last known user that logged in using WMI. I've added a few statements to be sure I'm sending the right info but I'm still getting the same error msg: Microsoft VBScript runtime error: Wrong number of arguments or invalid property assignment: 'GetLastUserToLogin'.
Thanks!!
Dim counterDim objWMIService, objComputer, colComputer, strComputerDim Excel, objOU, objFSO, objNtSecurityDescriptor, objUSerFunction DoRecursive(strObjectDN)'Set oneLevelOU= GetObject("LDAP://" & strObjectDN)Set objOU = GetObject("LDAP://" & strObjectDN)objOU.Filter = Array("Computer")Set objUser = GetObject("LDAP://" & strObjectDN) Set objFSO = CreateObject("Scripting.FileSystemObject")For Each objComputer In objOUSet objNtSecurityDescriptor = objComputer.Get("ntSecurityDescriptor") Excel.Cells(counter,1).Value = objComputer.CN Excel.Cells(counter,2).Value = objComputer.OperatingSystem Excel.Cells(counter,3).Value = objNtSecurityDescriptor.owner Excel.Cells(counter,4).Value = objComputer.WhenCreated Excel.Cells(counter,5).Value = GetLastUserToLogin **Error Occurs Here*** counter =counter +1 NextEnd FunctionFunction GetLastUserToLogin(strComputer) If Ping(strComputer) = True Then strUserName = "" On Error Resume Next Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colComputer = objWMIService.ExecQuery _ ("Select UserName from Win32_ComputerSystem") For Each objComputer in colComputer strUserName = objComputer.UserName Next If Err.Number <> 0 Then strUserName = "WMI ERROR" Err.Clear On Error GoTo 0 Else strUserName = "OFFLINE" End If GetLastUserToLogin = strUserNameEnd FunctionFunction Ping(strComputer) Dim objShell, boolCode Set objShell = CreateObject("WScript.Shell") boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True) If boolCode = 0 Then Ping = True Else Ping = False End IfEnd Function
Excel.Cells(counter,5).Val
as below. Not 100% on the syntax herer so you may need to lose the brackets.
Excel.Cells(counter,5).Val
Chris
Open in new window