Solved

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

Posted on 2010-09-08
4
1,875 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 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