Link to home
Start Free TrialLog in
Avatar of wally_davis
wally_davisFlag for United States of America

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-dbwkstns.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.Shell")
11. Set objFSO = CreateObject("Scripting.FileSystemObject")
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=impersonate}!\\" & strComputer & "\root\cimv2")
19.       Set objProcess = objWMIService.Get("Win32_Process")
20.       Set objProgram = objProcess.Methods_("Create").InParameters.SpawnInstance_objProgram.CommandLine = strExe
21.       If objFSO.FolderExists(pvtPath) Then
22.            objShell.CurrentDirectory = pvtPath
23.            Set strShell = objWMIService.ExecMethod("Win32_Process", "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_(...).InParameters.SpawnInstance_objProgram'

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
Avatar of vincem1099
vincem1099
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wally_davis

ASKER

Const INPUT_FILE_NAME = "C:\VBScripts\10-31-dbwkstns.txt"
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.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME, ForReading)
Set objLog = objFSO.CreateTextFile("c:\temp\ReInitPvt.log")

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_ScheduledJob")
            objTaskService.Connect(strComputer)
            
            Set objRootFolder = objTaskService.GetFolder("\")
            Set objTask = objRootFolder.GetTask("PVT_Query")
            
            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.
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.