原理也就是利用setup.dll啊,我只是进行了一下命令行自动化,有时要打几次包,麻烦得很。
使用方法:
1. 下载附件,解压到任一目录
2. 将你要放安装的所有资源文件和exe放入此目录,修改make.py,将Provider和AppName改为自己的,这里不能出现中文AppName为目录。
3. 如果要改程序快捷方式名,改config/config.txt中chinaname即可。
4. 命令行运行make.py,可以看到编译成功的信息
脚本代码如下:
#coding=utf-8 import os import os.path workpath = os.path.dirname(__file__) Provider = "talkweb" #公司名 不能为中文 AppName = "test" #程序名 不能为中文 SourceDisksNames = "" CopyFiles = "" SourceDisksFiles = "" DestinationDirs = "" Body = "" #cab工具目录,mobile sdk5,6都行 cab_tools = '"D:\Program Files\Microsoft Visual Studio 9.0\smartdevices\sdk\sdktools\cabwiz.exe"' f = open("template.inf") inf_content = f.read() f.close() nIndex = 1 for root, dirs, files in os.walk(workpath): for name in files: if not name.endswith(".inf") and not name.endswith(".CAB") and not name.endswith(".py") : #1=,"Common1",,"C:\workspace\WindowsMobile\InstallCab\" SourceDisksNames += str(nIndex) + '=,\"Common'+str(nIndex)+'",,"'+root+'\\"'+"\n" SourceDisksFiles += '"' + name + '"' + "=" + str(nIndex) + "\n" #Files.Common1=0,"%InstallDir%\config" DestinationDirs += "Files.Common"+str(nIndex)+'=0,"%InstallDir%' if len(root[len(workpath):]) > 0 : DestinationDirs += root[len(workpath):] DestinationDirs += '"'+"\n" #[Files.Common74] #"SetupDLL.dll","SetupDLL.dll",,0 Body += "[Files.Common"+str(nIndex)+"]\n" Body += ('"%s","%s",,0') % (name,name) Body += "\n" nIndex += 1 for x in xrange(nIndex): if x > 0: CopyFiles += "Files.Common"+str(x) if x != (nIndex-1): CopyFiles += "," if __name__ == "__main__": inf_content = inf_content.replace("{Provider}",Provider) inf_content = inf_content.replace("{AppName}",AppName) inf_content = inf_content.replace("{SourceDisksNames}",SourceDisksNames) inf_content = inf_content.replace("{CopyFiles}",CopyFiles) inf_content = inf_content.replace("{SourceDisksFiles}",SourceDisksFiles) inf_content = inf_content.replace("{DestinationDirs}",DestinationDirs) inf_content = inf_content.replace("{Body}",Body) open(AppName+".inf","w").write(inf_content) cmd = cab_tools + " "+AppName+".inf /err CabWiz.log" os.system(cmd)