Solved

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

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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
A hard and fast method for reducing Active Directory Administrators members.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

632 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