远程调用 SchTasks 来删除任务失败,并出现来自 C# 的多连接错误
在 C# 代码中,我调用 schtasks 来删除一些计划任务。我进行第一次调用并返回此错误:
错误:不允许同一用户使用多个用户名与服务器或共享资源进行多个连接....
这是运行该过程的代码:
Process stProc = new Process();
stProc.StartInfo.UseShellExecute = false;
stProc.StartInfo.FileName = "SCHTASKS.exe";
stProc.StartInfo.RedirectStandardError = true;
stProc.StartInfo.RedirectStandardOutput = true;
stProc.StartInfo.CreateNoWindow = true;
stProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
stProc.StartInfo.Arguments = args;
stProc.Start();
stProc.BeginOutputReadLine();
stProc.BeginErrorReadLine();
stProc.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
stProc.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived);
stProc.WaitForExit();
stProc.Close();
stProc.Dispose();
我的参数是正确的:http://msdn.microsoft.com/en-us/library/bb736357(v=vs.85).aspx
只是为了确保我的连接不会挂起,我创建在每次删除调用之前杀死它的新进程:
StartProcess(args);
Process x = new Process();
x.StartInfo.FileName = "cmd";
x.StartInfo.Arguments = @" net use \\servername\ipc$ /delete";
x.StartInfo.CreateNoWindow = true;
x.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
x.Start();
不确定这里发生了什么。可能是其他人正在使用这台机器,所以我的电话无法接通?
任何想法表示赞赏!
谢谢!!
From c# code I call schtasks to delete some scheduled tasks. I make the first call and I get this error returned:
ERROR: Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed....
Here's the code that runs the process:
Process stProc = new Process();
stProc.StartInfo.UseShellExecute = false;
stProc.StartInfo.FileName = "SCHTASKS.exe";
stProc.StartInfo.RedirectStandardError = true;
stProc.StartInfo.RedirectStandardOutput = true;
stProc.StartInfo.CreateNoWindow = true;
stProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
stProc.StartInfo.Arguments = args;
stProc.Start();
stProc.BeginOutputReadLine();
stProc.BeginErrorReadLine();
stProc.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
stProc.ErrorDataReceived += new DataReceivedEventHandler(p_ErrorDataReceived);
stProc.WaitForExit();
stProc.Close();
stProc.Dispose();
My arguments are correct as per: http://msdn.microsoft.com/en-us/library/bb736357(v=vs.85).aspx
Just to make sure that my connection is not hanging around, I create a new process to kill it before every delete call:
StartProcess(args);
Process x = new Process();
x.StartInfo.FileName = "cmd";
x.StartInfo.Arguments = @" net use \\servername\ipc$ /delete";
x.StartInfo.CreateNoWindow = true;
x.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
x.Start();
Not sure what's up here. Might it be someone else that's using this machine and so my calls can't get through?
Any ideas appreciated!
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是这样的: http://support.microsoft.com/kb/938120
我使用了机器的IP地址。
The answer is this: http://support.microsoft.com/kb/938120
I used the IP address of the machine.