C#Web服务运行批处理文件或DOS命令? [英] C# web service running batch file or dos command?

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

问题描述

从我的previous问题,执行批处理文件在C#中的Web服务

From my previous question, Executing batch file in C# web service

我已经检查的所有相关的东西的权限,并发现:

I have checked the permission of all related stuff and found that:

批处理文件:权限=完全控制所有用户

batch file: permission = full control for all user

IIS用户= MYUSER

IIS user = myUser

..的win32 \\ cmd.exe的:系统的权限,管理员,MYUSER =读&安培;执行,读取权限的TrustedInstaller(是什么?)=完全控制

..win32\cmd.exe: permission for system, admin, myUser = read&execute, read permission for "TrustedInstaller"(what is it?) = full control

Visual Studio是在管理员模式下运行。

Visual Studio is running under administrator mode.

我没有在互联网上的一些研究,好像我需要与我的机器上的本地策略的东西。不幸的是,我使用Windows Vista家庭premium,这似乎是我无法设置地方政策...我也尝试改变CMD.EXE为完全控制的许可,但它只是不允许我这样做

I did some research on the Internet and it seems like I need to do something with 'Local Policies' on my machine. Unfortunately, I am using Windows Vista Home Premium, which seems like I cannot set local policies... I also try changing permission of cmd.exe to 'Full control', but it just doesn't allow me to do so.

好像我面临着一个无法解决的问题,所以我会解释我在做什么,从而使他人可以给我一个想法做什么。

It seems like I am facing an 'unsolvable' problem, so I will explain what I am doing so that someone may give me an idea what to do.


  • 我已经开发使用BlackBerry黑莓模拟器应用。它是在同一台PC我的web服务上。

  • I have developed Blackberry application using blackberry simulator. It is on the same PC as my web service.

我在C#开发的网络服务,在发表我的本地主机。

I developed web service in C#, published in my localhost.

黑莓应用程序文件上传到Web服务。 Web服务存储在我的电脑上的文件。 (我有这部分没有问题。)

Blackberry app upload a file to web service. Web service stores the file on my PC. (I have no problem with this part.)

还有就是我的PC上的一个程序,我会myprogram.exe调用它。该程序只能运行在DOS。该程序将使用命令myprogram.exe路径\\ oldfile.x路径文件转换一种文件类型为其他文件类型\\ newfile.y newfile.y将被创建并自动存储在我的电脑上。

There is one program on my PC, I will call it myprogram.exe. The program only runs on dos. The program will convert file from one file type to another file type using the command myprogram.exe path\oldfile.x path\newfile.y newfile.y will be created and stored on my PC automatically.

我需要一个从BB发送,现在用于存储本地PC上的文件进行转换,所以我写了含有DOS命令1批处理文件。 Web服务应该执行批处理文件,但它不会。

I need to convert the file that was sent from BB and is now storing on my local PC, so I wrote 1 batch file containing dos command. Web service should execute the batch file, but it wouldn't.

如果我停止试图用批处理文件来上班,有什么方法可以让我来执行这些命令? (或者说我可以运行外部程序的任何方式),请给我一个想法。我已经在互联网上搜索,仍然没有得到任何想法。我不知道现在该做什么。 T_T

If i stop trying to work with batch file, is there any way i can to to execute those command? (or any way that I can run that external program) Please give me an idea. I have searched on the Internet and still doesn't get any idea. I don't know what to do now. T_T

PS。原谅我,如果我的问题是愚蠢的。我只是想尝试一切可能的办法,使项目成功的一部分。

PS. Forgive me if my questions are stupid. I just want to try every possible way to make this part of project success.

推荐答案

所有我能想到的是:


  1. 您ASP.NET网站的默认应用下运行。
    该默认应用只有有限的权利。

  1. Your ASP.NET website runs under the DefaultAppPool. The DefaultAppPool has only limited rights.

为了从您的服务中执行批处理文件
创建一个新的应用程序池。

In order to execute a batch file from within your service create a new application pool.

一)打开Internet信息服务管理器(IIS 7)。
  你会发现互联网信息服务
  经理在Windows Vista开始菜单。

a) Open Internet Information Services Manager (IIS 7). You will find the Internet Information Services Manager in your Windows Vista start menu.

b)在左侧的树中,右键单击应用程序池
  并添加新的应用程序池。

b) In the tree on the left side right click Application Pools and add a new application pool.

c)选择新创建的应用程序池,然后单击
  高级设置。

c) Select your newly created application pool and click Advanced Settings.

d)根据标识选择本地系统。

d) Under identity choose LocalSystem.

e)在树中选择您的网站(例如默认Web站点)。
  选择基本设置,然后选择您所创建的应用程序池。

e) In the tree select your web site (e.g. Default Web Site). Select basic settings and choose your created application pool.

F)重新启动您的web站点(右键点击你的网站,下
  管理你的网站选择重启)。

f) Restart your web site (right click your web site, under Manage your web site select restart).

您应该能够执行批处理文件。
下面是一个例子:

You should be able to execute your batch file. Here is an example:

工艺oProcess =新工艺();

Process oProcess = new Process();

oProcess.StartInfo.UseShellExecute = FALSE;

oProcess.StartInfo.UseShellExecute = false;

oProcess.StartInfo.WorkingDirectory = @C:\\ TEMP \\测试;

oProcess.StartInfo.WorkingDirectory = @"c:\temp\test";

oProcess.StartInfo.FileName = @C:\\ WINDOWS \\ SYSTEM32 \\ cmd.exe的

oProcess.StartInfo.FileName = @"c:\windows\system32\cmd.exe";

oProcess.StartInfo.CreateNoWindow = TRUE;

oProcess.StartInfo.CreateNoWindow = true;

oProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

oProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

oProcess.StartInfo.Arguments = @/ C C:\\ TEMP \\测试\\ mybatch.bat;

oProcess.StartInfo.Arguments = @"/C c:\temp\test\mybatch.bat";

oProcess.Start();

oProcess.Start();

但是,我并不推荐这种方法。

重新考虑你的设计。我会建议使用WCF的服务在东道主
Windows服务来执行批处理文件。
然后,从您的Web服务调用WCF的-服务,以执行
批处理文件像这样(伪code):

Rethink your design. I would recommend using a WCF-Service hosted in a Windows Service to execute your batch file. Then from your web service call the WCF-Service to execute your batch file like so (pseudo code):

VAR wcfClient =新ConverterServiceClient();

var wcfClient = new ConverterServiceClient();

wcfClient.Convert(@C:\\ TEMP \\ oldfile.x,C:\\ TEMP \\ newfile.y);

wcfClient.Convert(@"c:\temp\oldfile.x", "c:\temp\newfile.y");

//此处是您的服务已使用应用程序转换的文件。

// Here your service has converted the file using your application.

如果你是绑在.NET Framework 2.0中,您可以托管
在你的Windows服务应用程序.NET远程服务。

If you are tied to the .NET Framework 2.0 you could host a .NET Remoting service in your Windows Service application.

希望,这有助于。

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

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