If statement 启动RDP并登录并保持运行?
我需要一个脚本,可以运行一个RDP文件在登录,并保持运行 等待用户从远程会话注销,然后重新启动RDP文件 我想在任务列表中查找mstsc.exe,如果它正在运行或未运行,则使用IF语句 任何帮助都将不胜感激 编辑:代码:If statement 启动RDP并登录并保持运行?,if-statement,desktop,If Statement,Desktop,我需要一个脚本,可以运行一个RDP文件在登录,并保持运行 等待用户从远程会话注销,然后重新启动RDP文件 我想在任务列表中查找mstsc.exe,如果它正在运行或未运行,则使用IF语句 任何帮助都将不胜感激 编辑:代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Diagnostics; na
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;
namespace RDPv1
static void Main(string[] args)
{
RDP();
while(true)
{
foreach (Process clsProcess in Process.GetProcesses())
{
if (!clsProcess.ProcessName.Contains("mstsc.exe"))
{
RDP();
break;
}
}
Thread.sleep(300);///Use any value which is confortable with you're request
}
}
private static void RDP()
{
Process rdp = new Process();
rdp.StartInfo = new ProcessStartInfo(@"C:\RDP.rdp");
rdp.Start(); `
以下是您需要的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Diagnostics;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please don't close this box!");
RDP();
while (true)
{
if (Process.GetProcessesByName("mstsc").Length == 0)
{
RDP();
Thread.Sleep(1000);
}
}
}
private static void RDP()
{
Process rdp = new Process();
rdp.StartInfo = new ProcessStartInfo("C:\\RDP\\rdp.rdp");
rdp.Start();
}
}
}
基本上,它启动rdp,然后进入无限循环,检查进程是否正在运行,如果没有,则再次启动
要将其放入VS just open VS C,请启动一个新的控制台应用程序并将上述内容粘贴到中。然后按下绿色三角形,它将运行程序,要找到它的EXE,它通常位于Documents\visualstudio\Projects\Your Project Name\Your Project Name\bin\Debug中
感谢科迪早些时候帮助编写了这个脚本对不起,我只使用过BAT和VBS。。。我很高兴使用您的解决方案,但我不知道如何使用!好的,如果您使用BAT,您可能会执行以下操作:如果%ERRORLEVEL%==0 echo rdp仍在运行其他rdppath,则tasklist/FI IMAGENAME eq mstsc.exe。然后你可以把它放进一个for循环?我还没有批量完成多少,但可能是为了/?会有帮助的you@fairm010如果您想使用C代码,那么只需安装Visual Studio 2010 Express即可免费将代码放入并编译,如果您需要任何帮助,请立即下载Visual Studio。。。会让你知道的!很酷,确保你用C版本,有不同版本的C++和VB