Solved

VBScript runtime error: Wrong number of arguments or invalid property assignment

Posted on 2010-09-08
4
1,797 Views
Last Modified: 2012-06-27
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 counter

Dim objWMIService, objComputer, colComputer, strComputer

Dim Excel, objOU, objFSO, objNtSecurityDescriptor, objUSer



Function 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 objOU

Set 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    



Next

End Function



Function 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 = strUserName

End Function



Function 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 If

End Function

Open in new window

0
Comment
Question by:JB4375
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
mcskarthikeyan earned 500 total points
ID: 33630675
GetLastUserToLogin function expects and parameter and it not supplied in you coding. I guess yo need to modify the line like below.

Excel.Cells(counter,5).Value = GetLastUserToLogin(objComputer)
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 33630682
Try using :

    Excel.Cells(counter,5).Value = GetLastUserToLogin  (objComputer)
as below.  Not 100% on the syntax herer so you may need to lose the brackets.

    Excel.Cells(counter,5).Value = GetLastUserToLogin  objComputer

Chris
Dim counter

Dim objWMIService, objComputer, colComputer, strComputer

Dim Excel, objOU, objFSO, objNtSecurityDescriptor, objUSer



Function 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 objOU

Set 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  (objComputer)

    counter =counter +1    



Next

End Function



Function 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 = strUserName

End Function



Function 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 If

End Function

 

Open in new window

0
 
LVL 1

Author Comment

by:JB4375
ID: 33630833
Close Enough!! This line works:
Excel.Cells(counter,5).Value = GetLastUserToLogin(strComputer)
Thanks!!
0
 
LVL 1

Author Closing Comment

by:JB4375
ID: 33630857
Thanks for the help,

JB
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now