Solved

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

Posted on 2010-09-08
4
1,837 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
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 …

832 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