想要使用asp.net执行DOS命令 [英] want to execute dos commands using asp.net

查看:107
本文介绍了想要使用asp.net执行DOS命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi

我想使用在ASP.NET(C#/VB)中开发的Web服务运行一些DOS命令.

我的DLL Interop.ExecuteApp.dll可以在32位计算机上正常工作,但是我的计算机具有64位操作系统,并且显示错误.

hi

I want to run few DOS commands using my web service which developed in ASP.NET (C#/VB).

I have DLL Interop.ExecuteApp.dll its work fine with 32 bit machine, but my machine has 64bit OS, and its showing error.

System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {5846D149-4160-4BCC-A19A-507442F24B03} failed due to the following error: 80040154.


预先感谢.


Thanks in advance.

推荐答案

您的Interop.ExecuteApp.dll未在64位计算机中注册,因此它给出错误0x80040154.因此,要在64位计算机上注册Interop.ExecuteApp.dll,必须创建一个64位dll,然后才能对其进行注册.
your Interop.ExecuteApp.dllis not registered in 64 bit machine because of which it is giving error 0x80040154. So for registering Interop.ExecuteApp.dll ina 64 bit machine you have to create a 64 bit dll and then you can register it.




我自己解决了问题
通过使用代码..

公共无效ExecuteCommandSync(对象命令)
{
试试
{
//使用"cmd"作为要运行的程序,并使用"/c"作为参数来创建ProcessStartInfo.
//顺便说一句,/c告诉cmd我们希望它执行后面的命令,然后退出.
System.Diagnostics.ProcessStartInfo procStartInfo =新的System.Diagnostics.ProcessStartInfo("cmd","/c" +命令);
//需要以下命令来重定向标准输出.
//这意味着它将被重定向到Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
//不要创建黑色窗口.
procStartInfo.CreateNoWindow = true;
//现在,我们创建一个流程,分配其ProcessStartInfo并启动它
System.Diagnostics.Process proc =新的System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();

//将输出转换成字符串
字符串结果= proc.StandardOutput.ReadToEnd();

//显示命令输出.
Console.WriteLine(result);
}
catch(Exception objException)
{
//记录异常
}
}


i have solved problem myself
by using code ..

public void ExecuteCommandSync(object command)
{
try
{
// create the ProcessStartInfo using "cmd" as the program to be run, and "/c " as the parameters.
// Incidentally, /c tells cmd that we want it to execute the command that follows, and then exit.
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command);
// The following commands are needed to redirect the standard output.
//This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();

// Get the output into a string
string result = proc.StandardOutput.ReadToEnd();

// Display the command output.
Console.WriteLine(result);
}
catch (Exception objException)
{
// Log the exception
}
}


这篇关于想要使用asp.net执行DOS命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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