有没有办法从C#应用程序中运行命令提示符命令?如果是这样,我将如何做以下事情:
copy /b Image1.jpg + Archive.rar Image2.jpg
Run Code Online (Sandbox Code Playgroud)
这基本上在JPG图像中嵌入了一个RAR文件.我只是想知道是否有办法在C#中自动执行此操作.
如何从C#执行命令行程序并返回STD OUT结果.具体来说,我想对以编程方式选择的两个文件执行DIFF,并将结果写入文本框.是的,我可以为自己解决这个问题,但肯定有人做过类似的事情,我很懒...
这是我的Windows/.NET安全堆栈:
在我的默认VS2008 DEV环境中,我有这个方法,它从ASP.NET应用程序调用,它工作正常:
private static void StopStartReminderService() {
ServiceController svcController = new ServiceController("eTimeSheetReminderService");
if (svcController != null) {
try {
svcController.Stop();
svcController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(10));
svcController.Start();
} catch (Exception ex) {
General.ErrorHandling.LogError(ex);
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我在生产服务器上运行它时,我从ServiceController收到以下错误:
源:System.ServiceProcess - > System.ServiceProcess.ServiceController - > IntPtr GetServiceHandle(Int32) - > System.InvalidOperationException消息:无法在计算机'.'上打开eTimeSheetReminderService服务.
为什么会发生这种情况,我该如何解决?
编辑:
答案如下,主要是评论,但澄清:
注意:我没有通过web.config模拟,我在代码中执行.请参阅上面的MS KB文章.
我试过System.ServiceProcess.ServiceController System.Diagnostics.Process;
在我的Web表单中控制Windows服务.随着System.ServiceProcess.ServiceController我获得访问被拒绝的例外.
随着System.Diagnostics.Process我什么也没得到.如何使用我的网络表单启动/停止Windows服务,任何想法?