Solved

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

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

[b]Ok so now I will show you how to add a user name to the description at login. [/b] First connect to your DC (Domain Controller / Active Directory Server) SET PERMISSIONS FOR SCRIPT TO UPDATE COMPUTER DESCRIPTION TO USERNAME 1. Open Active …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
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 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 …

920 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

15 Experts available now in Live!

Get 1:1 Help Now