从 asp.net 页面调用 SDelete

发布于 2024-09-09 08:35:44 字数 139 浏览 0 评论 0原文

我想在 asp.net 页面上运行一些代码后使用 SDelete。 SDelete 是一个命令行工具。我的具体问题是有人能够从 asp.net 页面运行这个 SDelete 吗?更一般的问题是,如何从 ASP.NET 页面运行命令行实用程序?

谢谢

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 an asp.net page?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

缱绻入梦 2024-09-16 08:35:44

您可以使用 进程类

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();

还有一个更接近 asp.net 的示例,我等待结束,然后读取输出。

        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();

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();
留蓝 2024-09-16 08:35:44

Aristos 的答案将在用户权限正常并且 SysInternals EULA 得到认可的情况下起作用。我的意思是 SysInternals 中的 sdelete.exe 实用程序将在 IIS 中分配的 Asp.Net 帐户下运行。如果该帐户没有适当的权限并且未接受弹出的 EULA,则不会删除该文件。我现在正面临这个问题。

您可以指定用于运行该进程的域/用户/密码。这里概述了这一点:
http://social. msdn.microsoft.com/Forums/hu-HU/netfxbcl/thread/70b2419e-cb1a-4678-b2ae-cedcfe08d06f
该线程的作者也有类似的问题,他通过更改 sdelete.exe 文件的所有权来解决这个问题。

该线程还包含一些有关以用于执行进程的用户身份登录并接受 SysInternals EULA 的信息:
sdelete.exe 无法与 cfexecute 一起使用

但这是不可行的如果您打算使用内置的 Asp.Net 系统帐户,因为这些用户帐户不允许典型登录。我可能被迫创建一个单独的用户,我可以使用该用户登录并接受 EULA,然后指定这些凭据来运行该过程。但就我而言,不幸的是,我可能无法选择在生产服务器上创建用户。

有多种方法可以通过命令行参数或简单的注册表项强制 EULA 接受。但我认为这只适用于“常规”用户,而不适用于内置系统用户。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文