写了个小控制台程序,这个程序用来注册 / 卸载OCX控件,用在Inno Setup做的安装卸载程序里。
#include
"
stdafx.h
"
#include
<windows.h>
#include
<iostream>
using
std::cout;
using
std::endl;
using
std::cerr;
int
_tmain(
int
argc, _TCHAR*
argv[]) { __try { STARTUPINFO si1
= {
sizeof
(si1)}; PROCESS_INFORMATION pi1; STARTUPINFO si2
= {
sizeof
(si2)}; PROCESS_INFORMATION pi2; WCHAR wCmdLine1[]
= L
"
regsvr32.exe PlayView_OCX.ocx
"
; WCHAR wCmdLine2[]
= L
"
regsvr32.exe PlayBack_OCX.ocx
"
; cout
<< endl <<
"
正在准备注册PlayView_OCX.ocx
"
<<
endl; BOOL bRet1
=
CreateProcessW( NULL, wCmdLine1, NULL, NULL, FALSE,
0
, NULL, NULL,
&
si1,
&
pi1);
if
(FALSE ==
bRet1) { cerr
<< endl <<
"
创建注册进程1失败,请以管理员权限运行!
"
<<
endl; system(
"
pause
"
);
return
-
1
; }
//
等待进程1完成
WaitForSingleObject(pi1.hProcess, INFINITE); cout
<< endl <<
"
正在准备注册PlayBack_OCX.ocx
"
<<
endl; BOOL bRet2
=
CreateProcessW( NULL, wCmdLine2, NULL, NULL, FALSE,
0
, NULL, NULL,
&
si2,
&
pi2);
if
(FALSE ==
bRet2) { cerr
<< endl <<
"
创建注册进程2失败,请以管理员权限运行!
"
<<
endl; system(
"
pause
"
);
return
-
1
; } cout
<< endl <<
endl; CloseHandle(pi1.hThread); CloseHandle(pi1.hProcess); CloseHandle(pi2.hThread); CloseHandle(pi2.hProcess); system(
"
pause
"
);
return
0
; } __except(EXCEPTION_EXECUTE_HANDLER) { cerr
<< endl <<
"
发生异常
"
<<
endl;
return
-
2
; } }