【问题标题】:Create a forms app to restart a remote PC创建表单应用以重新启动远程 PC
【发布时间】:2018-09-28 09:49:14
【问题描述】:

我只需要创建一个工具来重新启动我们城市办公室中的特定 Windows 设备。这将始终在192.168.cityID.33 中我找到了一种方法来检测 IP 的城市代码部分并在 GetIPMethod 中添加 33。

你提到的设备有不同的用户名和密码我在将重启命令传递给 cmd 时遇到问题

PS:我不是全职开发人员,我只是试图减少日常工作量的网络管理员 :)

提前致谢

public void Command1()
{
    String IP = GetIPAddress().ToString();
    string NewIP = IP.Substring(0, IP.LastIndexOf("."));
    string TOPIP = NewIP + ".33";

    Process process = new Process();
    process.StartInfo.FileName = "cmd.exe";
    process.StartInfo.CreateNoWindow = true; 
    process.StartInfo.RedirectStandardInput = true;
    process.StartInfo.RedirectStandardOutput = true;
    process.StartInfo.UseShellExecute = false;
    process.StandardInput.WriteLine("NET USE \\" + TOPIP + "\receiver /USER:GenusDS G3nu5DS");
    process.StandardInput.WriteLine("shutdown /m \\" + TOPIP + " /r /f -t 00");
    process.Start();
    process.StandardInput.Flush();
    process.Close();
    process.WaitForExit();
    Console.WriteLine(process.StandardOutput.ReadToEnd());
    Console.ReadKey();
    string strCmdText;
    strCmdText = "NET USE \\" + TOPIP + "\receiver /USER:GDS G3nS";
    System.Diagnostics.Process.Start("CMD.exe",strCmdText);
}

public static IPAddress GetIPAddress()
{
    IPAddress ip = Dns.GetHostAddresses(Dns.GetHostName()).Where(address =>
    address.AddressFamily == AddressFamily.InterNetwork).First();
    return ip;
}

【问题讨论】:

  • 我遇到了问题请描述得更详细些!
  • @TaW 只需在按下按钮时将上面给定的命令传递给 cmd
  • 此评论是否有效:"NET USE \\" + TOPIP + "\receiver G3nu5DS /USER:GenusDS"
  • “我只是一个试图减少日常工作量的网络管理员”,你最好看看 Powershell。 techrepublic.com/article/… 根据您的需要查看第 3 条
  • @phuzi 实际上这些电脑不在域或 powershell 中

标签: c# remote-server windows-console


【解决方案1】:

我通常会做类似下面的事情:

Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C net use \\[My IP] [My Password] /USER:[My Username]";
process.StartInfo = startInfo;
Process.Start(startInfo);

this question 展示了如何在一个进程中运行多个命令。

希望对您有所帮助。

【讨论】:

  • 我会在星期一早上尝试这个作为第一件事,然后回复你,谢谢:)
【解决方案2】:
var proc1 = new ProcessStartInfo();
            string Command;
            proc1.UseShellExecute = true;
            Command = "net use " + slash + TOPIP + "\\receiver /user:GenusDS G3nu5DS&shutdown /m " + slash + TOPIP + " /r /f -t 00";
            proc1.WorkingDirectory = @"C:\Windows\System32";
            proc1.FileName = @"C:\Windows\System32\cmd.exe";
            /// as admin = proc1.Verb = "runas";
            proc1.Arguments = "/c " + Command;
            proc1.WindowStyle = ProcessWindowStyle.Maximized;
            Process.Start(proc1);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-18
    • 2021-11-21
    相关资源
    最近更新 更多