近來手上有個項目,需要使用ocx控件
(ocx是什麼? [url]http://baike.baidu.com/view/393671.htm[/url])
在生産過程中我遇到了如下問題.
1. 如何讓 ocx 自動安裝?
a) 如何簽名?
b) 如何打包?
c) 如何安裝到指定目錄?
2. 如何讓 ocx 自動更新?
下面是我解決這些問題的方法.(該項目已釋出,所有代碼都可正常運作.)
一、ocx 簽名
購買及使用:
[url]http://verisign.itrus.com.cn/html/fuwuyuzhichi/changyongwendang/411.html[/url]
非購買的我沒有發一現個可用的 -_-
注:OCX與 CAB包都要簽名
二、 打包成CAB包
這裡我嘗試了二個方法
a) Cabarc (該方法在我把系統更新為 win7 64後出錯,原因沒能找到.)
運作 > CMD
cd C:\CAB
cabarc n ocx.cab -s 6144 -m LZX:21 ocx.ocx 1.dll 2.dll 1.lang ocx.inf
n ocx.cab 新生成 ocx.cab 包
-s 6144 Reserve space in cabinet for signing (e.g. -s 6144 reserves 6K bytes)
-m LZX:21壓縮模式 最高壓縮 Set compression type [LZX:<15..21>|MSZIP|NONE], (default is MSZIP)
ocx.ocx 1.dll 2.dll 1.lang ocx.inf 是目前目錄下 你要找進CBA包的 檔案
b) MakeCAB (上個方法被廢了後改用該方法,感覺比上個方法好用)
運作 > CMD
cd C:\CAB
MakeCAB /F list.txt /d compressiontype=lzx /d compressionmemory=21 /d cabinetnametemplate= ocx.cab
/F list.txt 将要打包的檔案目錄内容如下
ocx.ocx
1.dll
2.dll
1.lang
ocx.inf
/d compressiontype=lzx /d compressionmemory=21壓縮模式 最高壓縮
/d cabinetnametemplate= ocx.cab 打包後的檔案名 我在目前目錄 disk1 下打到了該檔案
三、 安裝(ocx.inf)
ocx.inf 決定了,你檔案的版本 安裝目錄等許多重要資訊
關于inf檔案細節 大家可以看下
[url] http://wenku.baidu.com/view/c136df4633687e21af45a97f.html[/url]
下面給出一個簡單的執行個體
[version]
signature="$CHICAGO$"
AdvancedINF=1,0,0,4
[DefaultInstall]
CopyFiles=install.files
RegisterOCXs=RegisterFiles
[RInstallApplicationFiles]
DelFiles=install.files
CopyFiles=install.files
RegisterOCXs=RegisterFiles
[DestinationDirs]
install.files=30,Program Files\XOCX
[SourceDisksNames]
1=%DiskName%,ocx.cab,1
[install.files]
ocx.ocx 1.dll 2.dll 1.lang
[ocx.ocx]
file-win32-x86=thiscab
RegisterServer=yes
clsid={917179C9-F725-4484-BADD-6D19A3DE5D82}
FileVersion=1,0,0,3
DestDir=30,Program Files\XOCX
[1.dll]
RegisterServer=yes
DestDir=30,Program Files\XOCX
[2.dll]
RegisterServer=yes
DestDir=30,Program Files\XOCX
[1.lang]
RegisterServer=yes
DestDir=30,Program Files\XOCX
[RegisterFiles]
%30%\Program Files\XOCX\ocx.ocx
四、 自動安裝與自動更新
<object name="ocx" id="ocx" classid="clsid:917179C9-F725-4484-BADD-6D19A3DE5D82" style="width:100%; height: 100%; " codebase="ocx.cab#version=1,0,0,3"></object>
codebase 指明要從那裡下載下傳 該ocx.
#version=1,0,0,3 目前頁面使用ocx的版本,如果與 ocx.inf中 [ocx.ocx] FileVersion=1,0,0,3一緻. 不一緻會要求使用者重複安裝.
當ocx更新後應該
修改基本版本
修改 ocx.inf中 [ocx.ocx] FileVersion=1,0,0,3 中的值
修改 <object> 中的值
這樣當使用者再次該頁面時會自動安裝最新版本的ocx控件