Question : run this vbs script as local admin of remote computer

Hello,

I have been running this script from my computer, it seems to work well..  The computers I have problems getting this script to run on are computers where I'm not in the local admin group.  I do know the local admin pw of these computers.

Is there a way I can run this vbs script as local admin of remote computer from my computer?  I would like to continue to use the computers.txt file as the SourceFile.  btw - The local admin of my computer and the computers I'm checking have different pw's.

thank you for your help
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
Const strSourceFile = "computers.txt"
Const strDestFile = "output.csv"
Const ForReading = 1
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSourceFile = objFSO.OpenTextFile(strSourceFile, ForReading)
Set objDestFile = objFSO.CreateTextFile(strDestFile, True)
objDestFile.WriteLine """Computername"",""Service Tag"",""User Name"""
 
Do While Not objSourceFile.AtEndOfStream
	strComputer = objSourceFile.ReadLine
	If Ping(strComputer) Then
		objDestFile.WriteLine """" & strComputer & """,""" & GetSerial(strComputer) & """,""" & GetUsername(strComputer) & """"
	End If
Loop
objDestFile.Close
 
msgbox "done!"
 
Function GetSerial(strComputer)
        Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        'Set colSMBIOS = objWMIService.ExecQuery("Select * from Win32_SystemEnclosure")
        Set colSMBIOS = objWMIService.ExecQuery("Select * from Win32_BIOS")
        
        'GetSerial = ""
        For Each objSMBIOS In colSMBIOS
			'GetSerial = objSMBIOS.SerialNumber
			GetSerial = objSMBIOS.SerialNumber
			Exit For
        Next
End Function
 
Function GetUsername(strComputer)
        Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        Set colComputer = objWMIService.ExecQuery _
        ("Select Username from Win32_ComputerSystem")
        
        'GetSerial = ""
		For Each objComputer In colComputer
			GetUsername = objComputer.Username
			Exit For
		Next
End Function
 
Function Ping(strComputer)
	Dim objPing, objStatus
	Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._  
				ExecQuery("SELECT Replysize FROM Win32_PingStatus WHERE address = '" & strComputer & "'")  
 
	Ping = False
	For Each objStatus in objPing  
		If Not IsNull(objStatus.ReplySize) Then Ping = True
	Next  
End Function

Answer : run this vbs script as local admin of remote computer

you will have to make some modifications, basically, create one script to read the txt file, and for each line of it (each computer) make it execute psexec (with the password parameters and so on) with the execute of the second script.

Basically, to sum up.
1- Create a script that reads the txt file, and for each line executes a command (psexec)
2- Create a script that runs whatever you want on the computers.

Run the first script, which will execute psexec for every computer you want, getting the info you want.

As far as the execute function use '1
As far as the statement to execute per each line of the txt use 2'


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
'1

Function RunLocalCMD(argument)
	
	cmd = "%comspec% /k " & argument
	Set obj2Shell = CreateObject("WScript.Shell")
	obj2Shell.Run cmd
	Set obj2Shell = Nothing
	
End Function

2' 

RunLocalCMD("\\" & strComputer & " -u USERNAME -p PASSWORD cscript SECONDSCRIPT.VBS")
Random Solutions  
 
programming4us programming4us