开发者

SDelete called from asp.net page

开发者 https://www.devze.com 2023-01-07 18:57 出处:网络
I want to use SDelete after some code is run on an asp.net page. SDelete is a command line tool. My specific question is has anyone been able to run this SDelete from an asp.net page? More generic que

I want to use SDelete after some code is run on an asp.net page. SDelete is a command line tool. My specific question is has anyone been able to run this SDelete from an asp.net page? More generic question would be, how do you run a command line utility from开发者_StackOverflow an asp.net page?

thanks


You can run a command line utility using the Process Class

Process myProcess = new Process();

myProcess.StartInfo.UseShellExecute = false;
// You can start any process, HelloWorld is a do-nothing example.
myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();

One more example closer to asp.net, that I wait to end, and read the output.

        Process compiler = new Process();

        compiler.StartInfo.FileName = "c:\\hello.exe";

        compiler.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8;

        compiler.StartInfo.UseShellExecute = false;
        compiler.StartInfo.CreateNoWindow = false;

        compiler.StartInfo.RedirectStandardError = true;
        compiler.StartInfo.RedirectStandardOutput = true;
        compiler.StartInfo.RedirectStandardInput = true;

        // here I run it
        compiler.Start();

        compiler.StandardInput.Flush();
        compiler.StandardInput.Close();

        // here I get the output
        string cReadOutput = compiler.StandardOutput.ReadToEnd();

        compiler.WaitForExit();
        compiler.Close();


Aristos' answer will work in cases where user privs are in order and the SysInternals EULA is acknowledged. By that, I mean the sdelete.exe utility from SysInternals will be run under the Asp.Net account assigned in IIS. If that account doesn't have the proper permissions and hasn't accepted the popup EULA, the file isn't deleted. I'm facing that very issue right now.

You can specify the domain/user/password used to run the process. That is outlined here: http://social.msdn.microsoft.com/Forums/hu-HU/netfxbcl/thread/70b2419e-cb1a-4678-b2ae-cedcfe08d06f The author of that thread had similar problems, which he cleared up by changing the ownership of the sdelete.exe file.

This thread also has some information about logging in as the user used to execute the process and accepting the SysInternals EULA: sdelete.exe is not working with cfexecute

However that isn't feasible if you plan on using the built-in Asp.Net system accounts since those user accounts don't allow typ login. I may be forced to create a separate user that I can login with and accept the EULA, then specify those credentials to run the process. Unfort in my case, though, I may not have the option of creating users on my production server.

There are ways to force the EULA accept with a command line param, or a simple registry entry. But I think that only works for "regular" users--not the built in system users.

0

精彩评论

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