开发者

Calls to SchTasks remotely to delete tasks fails with multi connection error from C#

开发者 https://www.devze.com 2023-04-05 05:52 出处:网络
From c# code I call schtasks to delete some scheduled tasks. I make the first call and I get this error returned:

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 开发者_如何学Pythonthrough?

Any ideas appreciated!

Thanks!!


The answer is this: http://support.microsoft.com/kb/938120

I used the IP address of the machine.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号