在C#中的Web服务执行批处理文件 [英] Executing batch file in C# web service

查看:226
本文介绍了在C#中的Web服务执行批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图执行在C#中的Web服务的批处理文件。我相信,该批处理文件没有问题。我现在面临的问题是,该批处理文件将仅在调试模式下执行。它不会产生错误,也不当我与客户连接机器正在执行。我相信,没有什么不妥的连接,因为我可以成功地从客户端发送的东西Web服务。

I am trying to execute a batch file in C# web service. I am sure that the batch file has no problem. The problem I am facing is that the batch file will be executed only in debugging mode. It won't produce error nor being executed when I connect with the client machine. I am sure that there is nothing wrong with the connection since I can successfully send something from client to web service.

下面是code:

        try
        {
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo.FileName = "C:\\mybatch.bat";
            proc.StartInfo.UseShellExecute = true;
            proc.Start(); 

        }
        catch (Exception e)
        {
            return e.ToString();
        }

Visual Studio是在管理员模式下运行,但CMD.EXE下(MYUSER)模式下运行,但我已经完全访问权限给每一个用户。我不知道这是否是一个问题或没有。如果没有,我要补充的东西到code? (

Visual Studio is running under administrator mode, but cmd.exe is running under (myUser) mode, but I have granted full access to every user. I don't know if this is a problem or not. If not, should I add something to the code? :(

请告诉我这个问题,解决方法的可能原因。

Please tell me the possible causes of the problem and the way to solve.

推荐答案

Web服务是不是在正常的桌面运行......它有不同的(=更少)的权限/权利,例如他们通常不访问共享...您可以运行与用户帐户Web服务(很大的安全隐患!)或者需要重新考虑你的设计,因为从Web服务运行批处理文件通常不是什么网络服务做...

A web service is not running in the "normal desktop"... it has different (=less) permissions/rights, for example they usually don't have access to shares... you can either run the web service with your user account (BIG security risk!) or should reconsider your design since running batch files from web services isn't usually something web services do...

如果你真的需要做这个尝试。

IF you really need to do this try

ProcessStartInfo processInfo = new ProcessStartInfo(@"C:\mybatch.bat");
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
Process process = Process.Start(processInfo);
process.WaitForExit();
if(process.ExitCode==0){ // success}

看的http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx

这篇关于在C#中的Web服务执行批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆