C# 如何在Inno安装程序中为带有数据库的.NET应用程序创建安装文件?
我找不到任何例子,所以我不确定这是否可行。我想做的是: 我想安装带有数据库的.NET C#windows服务。因此,我的要求是在客户机上安装.NETFramework和SQLServer2008 所以,它必须是这样的:C# 如何在Inno安装程序中为带有数据库的.NET应用程序创建安装文件?,c#,.net,database,sql-server-2008,inno-setup,C#,.net,Database,Sql Server 2008,Inno Setup,我找不到任何例子,所以我不确定这是否可行。我想做的是: 我想安装带有数据库的.NET C#windows服务。因此,我的要求是在客户机上安装.NETFramework和SQLServer2008 所以,它必须是这样的: 检查是否有.NET Framework 4.0和SQL Server 2008 如果找不到SQL Server,请让客户端选择路径或离开 最终安装.NETFramework 4.0 登录SQL Server,并(从脚本)创建表、过程等 从cmd行安装wnd服务。在这一点上,我还必
我想在Inno设置中这样做。可能吗 Inno setup将所有安装文件合并并压缩为单个可执行文件。运行此可执行文件时,它将提取inno安装程序中包含的所有文件。我认为它不会自动运行setup.exe中包含的可执行文件
或者,也可以使用创建设置。Wix安装程序也可以为.net framework 4.0构建。好的,我可以帮助您设置1和3 要检查.NET framework,可以使用以下方法(如果需要,还将安装.NET framework)。我目前使用它来检查.NET2.0,但您可以将它查找的版本更改为检查4.0
[Files]
Source: Files\dotnetfx.exe; DestDir: {tmp}; Flags: ignoreversion; Check: NeedsFramework
[Run]
Filename: {tmp}\dotnetfx.exe; Parameters: "/q:a /c:""install /l /q"""; WorkingDir: {tmp}; Flags: skipifdoesntexist; StatusMsg: Installing .NET Framework if needed. This may take several minutes.
[Code]
// .NET install helpers
// Indicates whether .NET Framework 2.0 is installed.
function IsDotNET20Detected(): boolean;
var
success: boolean;
install: cardinal;
begin
success := RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727', 'Install', install);
Result := success and (install = 1);
end;
//RETURNS OPPOSITE OF IsDotNet20Detected FUNCTION
//Remember this method from the Files section above
function NeedsFramework(): Boolean;
begin
Result := (IsDotNET20Detected = false);
end;
//IF SETUP FINISHES WITH EXIT CODE OF 0, MEANING ALL WENT WELL
//THEN CHECK FOR THE PRESENCE OF THE REGISTRY FLAG TO INDICATE THE
//.NET FRAMEWORK WAS INSTALLED CORRECTLY
//IT CAN FAIL WHEN CUST DOESN'T HAVE CORRECT WINDOWS INSTALLER VERSION
function GetCustomSetupExitCode(): Integer;
begin
if (IsDotNET20Detected = false) then
begin
MsgBox('.NET Framework was NOT installed successfully!',mbError, MB_OK);
result := -1
end
end;
请注意,此解决方案源自。您可以从microsoft网站下载dotnetfx for.NET 4.0
至于步骤4,我建议您创建一个安装在用户机器上的工具/脚本,然后根据需要从Run部分调用它
第二步很棘手,但显然并非不可能。阅读一段时间后,似乎可以将自定义UI页面添加到InnoSetup。有关方法,请参阅帮助。我不确定你能在实际的UI页面上做多少工作
值得注意的是,在InnoSetup中使用Pascal脚本,您或多或少可以完全访问Win32函数,还可以实例化COM对象,这可能是公开COM接口的.NET库……?这是我使用命令行oracle sqlplus执行sql脚本的示例代码 1.示例代码
[Dirs]
; Create folders at user side
Name: {app}\ScriptLog;
[Code]
///////////////////////////////////////////////////////////
//// Modify Sql function
//// TagName: the script line you want to modify tag name,
//// OldString: the old string,
//// NewString: the new string,
//// StringArr: the script strings array
///////////////////////////////////////////////////////////
function ModifySql(var TagStr, OldStr, NewStr: String; const StringArr: array of String): Boolean;
var
batPath: String;
tmpStr: String;
ResultCode: Integer;
i: Integer;
begin
result := false;
for i:= 0 to GetArrayLength(StringArr)-1 do
// if TagStr and OldStr are in the same line
if ( (StringArr[i] <> '') and (Pos(TagStr, StringArr[i]) > 0) and (Pos(OldStr, StringArr[i]) > 0) ) then
//replace OldStr with NewStr
StringChange(StringArr[i], OldStr, NewStr);
end;
///////////////////////////////////////////////////////////
//// Search ORA- Error function
//// the script exec result, for example : Error or ORA-xxxxx
///////////////////////////////////////////////////////////
function Check_Exec_Script_Result(var ErrStr, LogFile: String): Boolean;
var
LogFileLines: TArrayOfString;
ResultCode: Integer;
i: Integer;
begin
//assign sql file
//load strings and store to SqlFileLines
LoadStringsFromFile(LogFile, LogFileLines);
result := false;
for i:= 0 to GetArrayLength(LogFileLines)-1 do
// if TagStr and OldStr are in the same line
if ( (LogFileLines[i] <> '') and (Pos(ErrStr, LogFileLines[i]) > 0) ) then
MsgBox('Err' + LogFileLines[i] , mbError, MB_OK);
end;
///////////////////////////////////////////////////////////
//// execute Script with Sqlplus
///////////////////////////////////////////////////////////
procedure Exec_Script_Sqlplus(var dbTns, dbUser, dbPwd, scriptPath, batFileName: String);
var
batPath: String;
tmpStr: String;
ResultCode: Integer;
LogFileName: String;
ErrStr: String;
begin
// generate bat file
batPath := ExpandConstant('{tmp}\' + batFileName + '.bat');
tmpStr := 'cd \' + ''#13''#10;
SaveStringToFile(batPath, tmpStr, False);
//tmpStr := 'quit | sqlplus ' + dbUser + '/' + dbPwd + '@' + dbTns + ' @' + scriptPath + ''#13''#10;;
tmpStr := 'echo quit | sqlplus ' + dbUser + '/' + dbPwd + '@' + dbTns + ' @' +'"'+ scriptPath +'"'+ ''#13''#10;
SaveStringToFile(batPath, tmpStr, True);
// set log file path
LogFileName := ExpandConstant('E:\123\' + batFileName + '.txt');
//MsgBox(batPath, mbError, MB_OK);
if Exec(batPath, ' > "' + LogFileName + '"', '', 1, ewWaitUntilTerminated, ResultCode) then
begin
// handle success if necessary; ResultCode contains the exit code
if (ResultCode = 0) then begin
ErrStr := 'ORA';
Check_Exec_Script_Result(ErrStr, LogFileName);
// open ScriptLog file
ShellExec('', ExpandConstant(LogFileName),'', '', SW_SHOW, ewNoWait, ErrorCode)
//MsgBox('OK', mbError, MB_OK);
//result := true;
end;
end
else begin
MsgBox('Exec:' + scriptPath + 'fail,please check parameters setting', mbError, MB_OK);
//handle failure if necessary; ResultCode contains the error code
end;
end;
///////////////////////////////////////////////////////////
//// 1. Set Sql Script Parameters ,ex: DB TNS,Account,PWD
//// 2. Call function ModifySql, to modify Sql Script
//// 3. Call function Exec_Script_Sqlplus, to exec Sql Script with sqlplus
///////////////////////////////////////////////////////////
procedure SetSql_ExecSqlScript();
var
SqlFile: String;
OldString: String;
NewString: String;
TagName: String;
batFileName: String;
SqlFileLines: TArrayOfString;
LocalInfoPath: String;
LocalInfoLines: TArrayOfString;
LocalInfoStr: String;
i: Integer;
begin
//assign sql file
//========================start of 1_Sample_system.sql========================
SqlFile := WizardDirValue() + '\SQL\1_Sample_system.sql';
//create bat file
batFileName := '1_Sample_system';
//load strings and store to SqlFileLines
LoadStringsFromFile(SqlFile, SqlFileLines);
//set modify parameters
TagName := 'CREATE USER';
OldString := 'Sample';
NewString := DBAppUser;
ModifySql(TagName, OldString, NewString, SqlFileLines);
TagName := 'GRANT CREATE';
OldString := 'Sample';
NewString := DBAppUser;
ModifySql(TagName, OldString, NewString, SqlFileLines);
TagName := 'GRANT CONNECT';
OldString := 'Sample';
NewString := DBAppUser;
ModifySql(TagName, OldString, NewString, SqlFileLines);
TagName := 'ALTER USER';
OldString := 'Sample';
NewString := DBAppUser;
ModifySql(TagName, OldString, NewString, SqlFileLines);
TagName := 'IDENTIFIED';
OldString := '1234abcd';
NewString := DBAppPwd;
ModifySql(TagName, OldString, NewString, SqlFileLines);
//save modified strings to file
SaveStringsToFile(SqlFile, SqlFileLines, False);
//Exec Script with Sqlplus
Exec_Script_Sqlplus(DBSystemTNS, DBSystemUser, DBSystemPwd, SqlFile , batFileName);
//========================end of 1_Sample_system.sql========================
//========================start of 2_Sample_create_schema.sql========================
SqlFile := WizardDirValue() + '\SQL\2_Sample_create_schema.sql';
//create bat file
batFileName := '2_Sample_create_schema';
//Exec Script with Sqlplus
Exec_Script_Sqlplus(DBAppTNS, DBAppUser, DBAppPwd, SqlFile , batFileName);
//========================end of 2_Sample_create_schema.sql========================
//========================start of 3_Sample_insert_data.sql========================
SqlFile := WizardDirValue() + '\SQL\3_Sample_insert_data.sql';
//create bat file
batFileName := '3_Sample_insert_data';
//Exec Script with Sqlplus
Exec_Script_Sqlplus(DBAppTNS, DBAppUser, DBAppPwd, SqlFile , batFileName);
//========================end of 3_Sample_insert_data.sql========================
//========================start of 4_Sample_drop_schema.sql========================
SqlFile := WizardDirValue() + '\SQL\4_Sample_drop_schema.sql';
//create bat file
batFileName := '4_Sample_drop_schema';
//load strings form file
LoadStringsFromFile(SqlFile, SqlFileLines);
//set modify parameters
TagName := 'DROP USER';
OldString := 'Sample';
NewString := DBAppUser;
ModifySql(TagName, OldString, NewString, SqlFileLines);
//save modified strings to file
SaveStringsToFile(SqlFile, SqlFileLines, False);
//Exec Script with Sqlplus
//Exec_Script_Sqlplus(DBSystemTNS, DBSystemUser, DBSystemPwd, SqlFile , batFileName);
//========================end of 4_Sample_drop_schema.sql========================
end;
[Dirs]
; 在用户端创建文件夹
名称:{app}\ScriptLog;
[守则]
///////////////////////////////////////////////////////////
////修改Sql函数
////标记名:要修改标记名的脚本行,
////旧弦:旧弦,
////新字符串:新字符串,
////StringArr:脚本字符串数组
///////////////////////////////////////////////////////////
函数ModifySql(var-TagStr,OldStr,NewStr:String;const-StringArr:String数组):布尔;
变量
蝙蝠路径:字符串;
tmpStr:字符串;
结果代码:整数;
i:整数;
开始
结果:=假;
对于i:=0到GetArrayLength(StringArr)-1 do
//如果TagStr和OldStr在同一行中
如果((StringArr[i]'')和(Pos(TagStr,StringArr[i])>0)和(Pos(OldStr,StringArr[i])>0),则
//用NewStr替换OldStr
StringChange(StringArr[i]、OldStr、NewStr);
结束;
///////////////////////////////////////////////////////////
////搜索错误函数
////脚本执行结果,例如:Error或ORA-xxxxx
///////////////////////////////////////////////////////////
函数检查执行脚本结果(var ErrStr,LogFile:String):布尔值;
变量
日志文件行:TArrayOfString;
结果代码:整数;
i:整数;
开始
//分配sql文件
//加载字符串并存储到SqlFileLines
LoadStringsFromFile(日志文件,日志文件行);
结果:=假;
对于i:=0到GetArrayLength(LogFileLines)-1 do
//如果TagStr和OldStr在同一行中
如果((LogFileLines[i]'')和(Pos(ErrStr,LogFileLines[i])>0),则
MsgBox('Err'+日志文件行[i],mbError,MB_OK);
结束;
///////////////////////////////////////////////////////////
////使用Sqlplus执行脚本
///////////////////////////////////////////////////////////
过程执行脚本Sqlplus(var dbTns、dbUser、dbPwd、scriptPath、batFileName:String);
变量
蝙蝠路径:字符串;
tmpStr:字符串;
结果代码:整数;
LogFileName:String;
ErrStr:String;
开始
//生成bat文件
batPath:=ExpandConstant('{tmp}\'+batFileName+'.bat');
tmpStr:=“cd\”+“13”#10;
SaveStringToFile(batPath、tmpStr、False);
//tmpStr:='quit | sqlplus'+dbUser+'/'+dbPwd+'@'+dbTns+'@'+scriptPath+''13'#10;';;
tmpStr:=“echo quit”| sqlplus“+dbUser++”/“+dbPwd++”@“+dbTns++”@“++”“+scriptPath++”“++”13”#10;
SaveStringToFile(batPath、tmpStr、True);
//设置日志文件路径
LogFileName:=ExpandConstant('E:\123\'+batFileName+'.txt');
//MsgBox(batPath,mbError,MB_OK);
如果Exec(batPath,“>”+“日志文件名+”,“,”,1,EWAitUnFilterminated,ResultCode),则
开始
//必要时处理成功;ResultCode包含退出代码
如果(ResultCode=0),则开始
ErrStr:='ORA';
检查执行脚本结果(ErrStr,LogFileName);
//打开脚本日志文件
ShellExec(“”,ExpandConstant(日志文件名),“”,“”,“”,SW_SHOW,ewNoWait,错误代码)
//MsgBox(“正常”,mbError,MB_正常);
//结果:=真;
结束;
结束
否则开始
MsgBox('Exec:'+scriptPath+'失败,请检查参数设置',mbError,MB_OK);
//必要时处理故障;ResultCode包含错误代码
结束;
结束;
///////////////////////////////////////////////////////////
//// 1. 设置Sql脚本参数,例如:DB TNS、帐户、PWD
//// 2. 调用函数ModifySql,修改Sql脚本
//// 3. 调用函数Exec_Script_Sqlplus,使用Sqlplus执行Sql脚本
///////////////////////////////////////////////////////////
程序SetSql_ExecSqlScript();
变量
SqlFile:String;
旧字符串:字符串;
新闻字符串:字符串;
标记名:字符串;
文件名:字符串;
SqlFileLines: