WMI,我哪里出错了

funkel1989

新成员
已加入
2017年5月23日
留言内容
2
编程经验
Beginner
我正在尝试使用WMI连接到远程PC并运行补丁脚本。运行程序时,我不会收到任何错误或异常。当我远程进行身份验证并在localhost上运行时,它可以工作。当我在未进行任何更改的情况下添加身份验证时,它将永远不会在远程PC上启动批处理脚本。
我已验证我正在使用的帐户具有访问权限,并且在我们的网络上启用了WMI。
我不确定自己在做什么错。任何帮助检查我的代码并确保其正确的帮助都将非常有用。如果您知道我在做什么错,那就更好了!
很抱歉,代码格式化,不确定如何在reddit上格式化代码。
远程访问类:
C#:
public void RunOnRemotePC(string Application, string RemotePC, string Username, string Password)
        {
            try
            {
                var processToRun = new[] { Application };
                var connection = new ConnectionOptions();
                connection.Authentication = AuthenticationLevel.PacketPrivacy;
                connection.Username = Username;
                connection.Password = Password;
                var WMIScope = new ManagementScope(String.Format(@"\\{0}\root\cimv2", RemotePC), 
connection);
                var WMIProcess = new ManagementClass(wmiScope, new ManagementPath("Win32_Process"), new 
ObjectGetOptions());
                WMIProcess.InvokeMethod("Create", processToRun);
            }
            catch (ThreadAbortException tAe)
            {

                MessageBox.Show(tAe.ToString());
            }

            catch (Exception e)
             {

                 MessageBox.Show(e.ToString());
             }

        }`
正在运行的程序:
C#:
public partial class RemoteShortyWindow : Window
    {
        public string Application;
        public string RemotePC;
        public string Username;
        public string Password;
        public bool handle = true;

    public RemoteShortyWindow()
    {
        InitializeComponent();

        string value = "";
        if (Tmp.InputBox("Username", "Enter your dash account Username:", ref value) == System.Windows.Forms.DialogResult.OK)
        {
            Username = value;
        }

        string value2 = "";
        if (Tmp.InputBox("Password", "Enter your dash account Password:", ref value2) == System.Windows.Forms.DialogResult.OK)
        {
            Password = value2;
        }
    }        

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        this.Close();
    }

    private void GoButton_Click(object sender, RoutedEventArgs e)
    {
        RemotePCAccess remotepc = new RemotePCAccess();
        remotepc.RunOnRemotePC(Application, RemotePC, Username, Password);
    }

    private void ComboBox_DropDownClosed(object sender, EventArgs e)
    {
        if (handle) Handle();
        handle = true;
    }

    private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        ComboBox cmb = sender as ComboBox;
        handle = !cmb.IsDropDownOpen;
        Handle();
    }

    private void Handle()
    {
        switch (ActionSelector.SelectedItem.ToString().Split(new string[] { ": " }, StringSplitOptions.None).Last())
        {
            case "ClearIe":
                Application = @"\\mi\dfs\Apps\Shorty\clearie-v1\clearie.cmd";
                break;
            case "ResetCTI":
                //Handle for the second combobox
                break;
            case "Reboot":
                Application = @"\\mi\dfs\Apps\Shorty\reboot.cmd";
                break;
        }
    }

    private void ComputerNameBox_TextChanged(object sender, TextChangedEventArgs e)
    {
        RemotePC = ComputerNameBox.Text;
    }
}`
 
最佳 底部