wally_davis
asked on
VBScript objProcess.Methods error
Good day everyone,
I'm in the middle of writing a VBScript to connect to remote XP Professional workstations and start buy running an executable called TaskDeletor.exe that will delete Scheduled Task jobs when I run this script from my XP Professional Workstation. Here's the code:
1. Const INPUT_FILE_NAME = "C:\VBScripts\10-31-dbwkst ns.txt"
2. Const pvtPath = "C:\Program Files\platform validation tool"
3. Const ForReading = 1
4.
5. Dim objWMIService, objProcess, objTaskDeletor
6. Dim objShell, strShell, objProgram, strComputer, strExe
7.
8. strExe = "TaskDeletor.exe"
9.
10. Set objShell = CreateObject("WScript.Shel l")
11. Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
12. Set objFile = objFSO.OpenTextFile(INPUT_ FILE_NAME, ForReading)
13. strComputers = objFile.ReadAll
14. objFile.Close
15.
16. arrComputers = Split(strComputers, VbCrLf)
17. For Each strComputer In ArrComputers
18. Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper sonate}!\\ " & strComputer & "\root\cimv2")
19. Set objProcess = objWMIService.Get("Win32_P rocess")
20. Set objProgram = objProcess.Methods_("Creat e").InPara meters.Spa wnInstance _objProgra m.CommandL ine = strExe
21. If objFSO.FolderExists(pvtPat h) Then
22. objShell.CurrentDirectory = pvtPath
23. Set strShell = objWMIService.ExecMethod(" Win32_Proc ess", "Create", objProgram)
24. objShell.Run chr(34) & pvtPath & "\TaskDeletor.exe" & Chr(34), 1 , False
25. Else WScript.Echo "Folder does not exist."
26. End If
27. Next
Line # 20 is giving me the following error:
reinitpvt.vbs(20, 2) Microsoft VBScript runtime error: Object doesn't support this property or method:
'Methods_(...).InParameter s.SpawnIns tance_objP rogram'
I'm not sure if the method or property is out of date or just not syntactically correct.
Any help is most appreciated. I really need to get this part of the script working before moving onto next steps.
Thank you,
Wally
I'm in the middle of writing a VBScript to connect to remote XP Professional workstations and start buy running an executable called TaskDeletor.exe that will delete Scheduled Task jobs when I run this script from my XP Professional Workstation. Here's the code:
1. Const INPUT_FILE_NAME = "C:\VBScripts\10-31-dbwkst
2. Const pvtPath = "C:\Program Files\platform validation tool"
3. Const ForReading = 1
4.
5. Dim objWMIService, objProcess, objTaskDeletor
6. Dim objShell, strShell, objProgram, strComputer, strExe
7.
8. strExe = "TaskDeletor.exe"
9.
10. Set objShell = CreateObject("WScript.Shel
11. Set objFSO = CreateObject("Scripting.Fi
12. Set objFile = objFSO.OpenTextFile(INPUT_
13. strComputers = objFile.ReadAll
14. objFile.Close
15.
16. arrComputers = Split(strComputers, VbCrLf)
17. For Each strComputer In ArrComputers
18. Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
19. Set objProcess = objWMIService.Get("Win32_P
20. Set objProgram = objProcess.Methods_("Creat
21. If objFSO.FolderExists(pvtPat
22. objShell.CurrentDirectory = pvtPath
23. Set strShell = objWMIService.ExecMethod("
24. objShell.Run chr(34) & pvtPath & "\TaskDeletor.exe" & Chr(34), 1 , False
25. Else WScript.Echo "Folder does not exist."
26. End If
27. Next
Line # 20 is giving me the following error:
reinitpvt.vbs(20, 2) Microsoft VBScript runtime error: Object doesn't support this property or method:
'Methods_(...).InParameter
I'm not sure if the method or property is out of date or just not syntactically correct.
Any help is most appreciated. I really need to get this part of the script working before moving onto next steps.
Thank you,
Wally
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Actually, having just noticed, the PSEXEC is the other part of the equation and is what helped me get connected to run the .exe from the workstations so I'll give the 300 points to Vincem1099 and 200 to Chandru.
ASKER
Const pvtPath = "C$\Program Files\platform validation tool"
Const ForReading = 1
Dim objWMIService, objProcess, objTaskDeletor
Dim objShell, strShell, objProgram, strComputer, strExe
strExe = "TaskDeletor.exe"
Set objShell = CreateObject("WScript.Shel
Set objFSO = CreateObject("Scripting.Fi
Set objFile = objFSO.OpenTextFile(INPUT_
Set objLog = objFSO.CreateTextFile("c:\
strComputers = objFile.ReadAll
objFile.Close
arrComputers = Split(strComputers, VbCrLf)
For Each strComputer In ArrComputers
'WScript.Echo strComputerWScript.Echo "\\" & strComputer & "\" & pvtPath
If Ping(strComputer) Then
If objFSO.FolderExists("\\" & strComputer & "\" & pvtPath) Then
WScript.Echo "psexec.exe \\" & strComputer & " ""c:\Program Files\platform validation tool\TaskDeletor.exe"""
objShell.Run "psexec.exe \\" & strComputer & " ""c:\Program Files\platform validation tool\TaskDeletor.exe""", 1
WScript.Sleep(3000)
WScript.Echo "psexec.exe \\" & strComputer & " ""c:\Program Files\platform validation tool\TaskCreator.exe"""
objShell.Run "psexec.exe \\" & strComputer & " ""c:\Program Files\platform validation tool\TaskCreator.exe""", 1
WScript.Sleep(3000)
Set objTaskService = CreateObject("Win32_Schedu
objTaskService.Connect(str
Set objRootFolder = objTaskService.GetFolder("
Set objTask = objRootFolder.GetTask("PVT
Set objWMIService
Else
objLog.WriteLine(Now & vbTab & strComputer& vbTab & "Folder path or File does not exist")
End If
Else
objLog.WriteLine(Now & vbTab & strComputer & vbTab & "Workstation is UNREACHABLE.")
End If
Next
I actually had to re-write some of the code and it took a while after researching a few other resources. This code works but I will also give you half the points for responding. The way you wrote it, where you have to wrap one of the lines of code (Line 20) actually helps but doesn't isn't able to find the file.
Thank you though.