WMI Problem

Last post 05-15-2008 7:44 AM by aligenius. 0 replies.

Sort Posts:

  • WMI Problem

    05-15-2008, 7:44 AM
    • Loading...
    • aligenius
    • Joined on 04-22-2008, 2:09 AM
    • Posts 92

    hi

    Here is my code:

    Sub Main()

    Dim retValue As String

    Try

    retValue = RunCommand("calc.exe", "ipaddress", "username", "password")

    Console.WriteLine(retValue)

    Console.Read()

    Catch ex As Exception

    Console.WriteLine(ex.Message)

    End Try

     

    End Sub

    Function RunCommand(ByVal strCommand As String, ByVal strMachineName As String, ByVal strUserName As String, ByVal strPassword As String) As String

    Dim options As New System.Management.ConnectionOptions

    options.Username = strUserName

    options.Password = strPassword

    options.Impersonation = Management.ImpersonationLevel.Impersonate

    options.Authentication = Management.AuthenticationLevel.PacketPrivacy

    Dim path As New System.Management.ManagementPath("\\" & strMachineName & "\root\cimv2:Win32_Process")Dim scope As New System.Management.ManagementScope(path, options)

    scope.Connect()

    Dim opt As New System.Management.ObjectGetOptions

    Dim classInstance As New System.Management.ManagementClass(scope, path, opt)

    Dim inParams As System.Management.ManagementBaseObject = classInstance.GetMethodParameters("Create")

    inParams("CommandLine") = strCommand

    ' Execute the method and obtain the return values.

    Dim outParams As System.Management.ManagementBaseObject = classInstance.InvokeMethod("Create", inParams, Nothing) Return "ReturnValue:" & outParams("returnValue") & " Process ID: {0}" & outParams("processId")

    End Function

    This code works fine for exe like (notepad, calc, mspaint) but does not work for user programs

    please tell me how can i modify this code to run my own exe programs.

    thanks

    regards

    ali

Page 1 of 1 (1 items)
Microsoft Communities
Page view counter