【问题标题】:Impersonation with ManagementClass to launch Remote Process (VB)模拟 ManagementClass 以启动远程进程 (VB)
【发布时间】:2014-06-17 21:18:59
【问题描述】:

此代码远程启动程序。我遇到的问题是访问权限,所以我需要使用模拟来通过程序启动命令/查询传递管理员权限。我不知道如何将模拟包括在内,而且我在 Google 上找不到任何有用的东西。我已经尝试过诸如连接选项之类的东西,但我无法让任何工作。有什么想法吗?

    Dim sCmd As String = "C:\Program Files\Internet Explorer\IEXPLORE.EXE" ' & txtData.Text.Trim

    ' add a reference to System.Management in Solution Explorer

    Dim wmi As ManagementClass
    Dim wmi_in, wmi_out As ManagementBaseObject
    Dim retValue As Integer


    Try
        wmi = New ManagementClass("\\" & "ComputerName" & "\root\cimv2:Win32_Process")
        ' get the parameters to the Create method
        wmi_in = wmi.GetMethodParameters("Create")


        ' fill in the command line plus any command-line arguments
        ' NOTE: the command can NOT be on a network resource!
        wmi_in("CommandLine") = sCmd
        ' do it!
        wmi_out = wmi.InvokeMethod("Create", wmi_in, Nothing)
        ' get the return code.  This not the return code of the
        ' application... it's a return code for the WMI method
        retValue = Convert.ToInt32(wmi_out("returnValue"))
        Select Case retValue
            Case 0
                ' success!
            Case 2
                Throw New ApplicationException("Access denied")
            Case 3
                Throw New ApplicationException("Insufficient privilege")
            Case 8
                Throw New ApplicationException("Unknown failure")
            Case 9
                Throw New ApplicationException("Path not found")
            Case 21
                Throw New ApplicationException("Invalid parameter")
            Case Else
                Throw New ApplicationException("Unknown return code " & retValue)
        End Select
    Catch ex As Exception
        MsgBox("sd" & ": Can't create the process. " & ex.Message)
    End Try

【问题讨论】:

    标签: vb.net wmi remote-access basic


    【解决方案1】:

    试试这个

    dim remoteServer as string = "myServer"
    RemoteStart(remoteServer, {"notepad.exe"})
    
    Function RemoteStart(ByVal Server As String, ByVal sProcess As Object)
        Try
            Dim connOptions As ConnectionOptions = New ConnectionOptions()
            connOptions.Username = domain & "\" & username
            connOptions.Password = password
            connOptions.EnablePrivileges = True
            Dim theScope As ManagementScope = New ManagementScope("\\" & Server & "\root\cimv2", connOptions)
            Dim theClass As New ManagementClass(theScope, New ManagementPath("Win32_Process"), New ObjectGetOptions())
            theClass.InvokeMethod("Create", sProcess)
        Catch
            MessageBox.Show(Err.Description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    
        Return Nothing
    
    End Function
    

    【讨论】:

      猜你喜欢
      • 2010-09-25
      • 2014-12-04
      • 1970-01-01
      • 2017-10-21
      • 2018-05-09
      • 2018-08-16
      • 1970-01-01
      • 2012-01-24
      • 2013-06-15
      相关资源
      最近更新 更多