execution of .exe file on a remote machine using WMI objects

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi all,
the code was working fine for four iteration and then it got failed with exeception "not found". i tried to execute the code using step over "F10" option and i found the exeception exactly at "InputParameters = ManagementClass.GetMethodParameters("Create")". my code is copied below. I googled and i got the answer like WMI got corrupted and needs to repair. please suggest me any workaround.
Imports System.Management
Imports System
Imports System.Threading
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim str As String = "C:UsersIometerIometer.exe X:P410IOMeterWindowsedrivenew.icf X:Outputhemanth12373462374jbcjksdcbfs_fsdghhdvf_hjch_2.csv"
Dim targetip As String = "192.168.1.14"
WMI_Installation(targetip, str)
End Sub
Sub WMI_Installation(ByVal strComputer As String, ByVal strs As String)
Dim Options As New System.Management.ConnectionOptions

Options.Username = "Administrator"
Options.Password = "password"
Dim ManagementScope As New System.Management.ManagementScope("\" & strComputer & "rootcimv2", Options)
Dim ManagementPath As New System.Management.ManagementPath("Win32_Process")
Dim ManagementOptions As New System.Management.ObjectGetOptions
Dim ManagementClass As New System.Management.ManagementClass(ManagementScope, ManagementPath, ManagementOptions)
Dim OutputParameters As System.Management.ManagementBaseObject
Dim InputParameters As System.Management.ManagementBaseObject
Try

ManagementScope.Connect()
InputParameters = ManagementClass.GetMethodParameters("Create")
InputParameters("CommandLine") = "net use X:\192.168.1.3C$Atomos Password12 /user:Administrator"
OutputParameters = ManagementClass.InvokeMethod("Create", InputParameters, Nothing)
MessageBox.Show(OutputParameters("returnValue"))
Thread.Sleep(10000)
InputParameters("CommandLine") = strs
OutputParameters = ManagementClass.InvokeMethod("Create", InputParameters, Nothing)
MessageBox.Show(OutputParameters("processId"))
Catch ex As Exception
MsgBox("There was an error connecting to the remote computer." & vbNewLine & ex.Message)
End Try
End Sub

End Class
Thanks

View the full article
 
Back
Top