C#我也不熟,仅供参考: Dim procID As Integer Dim newProc As Diagnostics.Process newProc = Diagnostics.Process.Start("CMD /c a.bat >out.txt") procID = newProc.Id newProc.WaitForExit() Dim procEC As Integer = -1 If newProc.HasExited Then procEC = newProc.ExitCode End If //读文件out.txt的内容
或者Dim procID As Integer Dim newProc As Diagnostics.Process newProc = Diagnostics.Process.Start("regsvr32 /s C:\\Users\\wh\\Desktop\\ECCartoExtension.dll") procID = newProc.Id newProc.WaitForExit() Dim procEC As Integer = -1 If newProc.HasExited Then procEC = newProc.ExitCode //procEC==0成功,否则失败 End If
我按照这个修改了一下,但是它不管是否注册成功都都是注册成功。麻烦您再指导指导 if(suffix=="dll") { string commd = "regsvr32 \"" + num+"\""; Process p = new Process(); p.StartInfo.FileName = "cmd.exe";//设定程序名 p.StartInfo.Arguments = ""; p.StartInfo.UseShellExecute = false;//关闭Shell的使用 p.StartInfo.RedirectStandardInput = true;//重定向标准输入 p.StartInfo.RedirectStandardOutput = true;//重定向标准输出 p.StartInfo.RedirectStandardError = true;//重定向错误输出 p.StartInfo.CreateNoWindow = false;//设置不显示窗口 int n; p.Start();//启动 p.StandardInput.WriteLine(@"regsvr32 /s C:\Users\dview\Desktop\zhuc\插件2\GPSubPoints.dll"); n = p.Id; p.StandardInput.WriteLine("exit");//退出DOS,注释后DOS窗体需要手动关闭 p.WaitForExit();//等待管理进程退出(DOS) int pExit = -1; if (p.HasExited) { pExit = p.ExitCode;//proEC==0成功,否则失败 if (pExit == 0) { MessageBox.Show("注册成功"); } } //p.StandardInput.WriteLine(commd);//参数为DOS命令 dll++; } else if (suffix == "ttf")
改为 string commd = "regsvr32 \"" + num+"\""; Process p = new Process(); p.StartInfo.FileName = "regsvr32.exe";//设定程序名 p.StartInfo.Arguments = "/s C:\\Users\\dview\\Desktop\\zhuc\\插件2\\GPSubPoints.dll"; p.StartInfo.UseShellExecute = false;//关闭Shell的使用 p.StartInfo.RedirectStandardInput = false;//重定向标准输入 p.StartInfo.RedirectStandardOutput = false;//重定向标准输出 p.StartInfo.RedirectStandardError = false//重定向错误输出 p.StartInfo.CreateNoWindow = false;//设置不显示窗口 int n; p.Start();//启动 p.WaitForExit();//等待管理进程退出(DOS) int pExit = -1; if (p.HasExited) { pExit = p.ExitCode;//==0成功,否则失败 if (pExit == 0) { MessageBox.Show("注册成功"); } } 再试试?
regsvr32 /s C:\Users\wh\Desktop\ECCartoExtension.dll
if errorlevel 1 echo ERROR!&goto :EOF
echo OK.
试试看。
即shell执行命令
a.bat >out.txt
然后读文件out.txt的内容。或者你先在cmd窗口中执行a.bat看显示啥。
实在不好意思,我太菜了,不知道怎么获取这个输出的信息:“OK”或“ERROR”
Dim procID As Integer
Dim newProc As Diagnostics.Process
newProc = Diagnostics.Process.Start("CMD /c a.bat >out.txt")
procID = newProc.Id
newProc.WaitForExit()
Dim procEC As Integer = -1
If newProc.HasExited Then
procEC = newProc.ExitCode
End If
//读文件out.txt的内容
Dim newProc As Diagnostics.Process
newProc = Diagnostics.Process.Start("regsvr32 /s C:\\Users\\wh\\Desktop\\ECCartoExtension.dll")
procID = newProc.Id
newProc.WaitForExit()
Dim procEC As Integer = -1
If newProc.HasExited Then
procEC = newProc.ExitCode //procEC==0成功,否则失败
End If
if(suffix=="dll")
{
string commd = "regsvr32 \"" + num+"\"";
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";//设定程序名
p.StartInfo.Arguments = "";
p.StartInfo.UseShellExecute = false;//关闭Shell的使用
p.StartInfo.RedirectStandardInput = true;//重定向标准输入
p.StartInfo.RedirectStandardOutput = true;//重定向标准输出
p.StartInfo.RedirectStandardError = true;//重定向错误输出
p.StartInfo.CreateNoWindow = false;//设置不显示窗口
int n;
p.Start();//启动
p.StandardInput.WriteLine(@"regsvr32 /s C:\Users\dview\Desktop\zhuc\插件2\GPSubPoints.dll");
n = p.Id;
p.StandardInput.WriteLine("exit");//退出DOS,注释后DOS窗体需要手动关闭
p.WaitForExit();//等待管理进程退出(DOS)
int pExit = -1;
if (p.HasExited)
{
pExit = p.ExitCode;//proEC==0成功,否则失败
if (pExit == 0)
{
MessageBox.Show("注册成功");
}
} //p.StandardInput.WriteLine(commd);//参数为DOS命令
dll++;
}
else if (suffix == "ttf")
string commd = "regsvr32 \"" + num+"\"";
Process p = new Process();
p.StartInfo.FileName = "regsvr32.exe";//设定程序名
p.StartInfo.Arguments = "/s C:\\Users\\dview\\Desktop\\zhuc\\插件2\\GPSubPoints.dll";
p.StartInfo.UseShellExecute = false;//关闭Shell的使用
p.StartInfo.RedirectStandardInput = false;//重定向标准输入
p.StartInfo.RedirectStandardOutput = false;//重定向标准输出
p.StartInfo.RedirectStandardError = false//重定向错误输出
p.StartInfo.CreateNoWindow = false;//设置不显示窗口
int n;
p.Start();//启动
p.WaitForExit();//等待管理进程退出(DOS)
int pExit = -1;
if (p.HasExited)
{
pExit = p.ExitCode;//==0成功,否则失败
if (pExit == 0)
{
MessageBox.Show("注册成功");
}
}
再试试?