如何在 installshield 2010 中通过 installscript 修改 app.config 文件。我想根据用户选择的服务器修改 app.config 文件中的 sql 连接字符串。应感谢早期帮助。
问问题
1620 次
1 回答
1
我已经编写了自己的 installscript 来更改连接字符串。
代码片段:
function Update_AppConfig(hMSI)
STRING EXAMPLE_FILE, EXAMPLE_DIR;
STRING svLine;
STRING svContent;
number nvBuff,temp,nvFileHandle ;
string szConnection,szServer,szFileName,szUser,szFilePath;
long cchValueBuf;
long length;
begin
EXAMPLE_FILE = "Example.exe.config";
EXAMPLE_DIR = INSTALLDIR;
cchValueBuf = 2;
MsiGetProperty(hMSI,"IS_SQLSERVER_SERVER",szServer,cchValueBuf);
OpenFileMode (FILE_MODE_NORMAL);
if (OpenFile (nvFileHandle, EXAMPLE_DIR, EXAMPLE_FILE) < 0) then
MessageBox ("OpenFile failed.", SEVERE);
abort;
endif;
while GetLine (nvFileHandle, svLine) = 0
svContent = svContent + svLine + "\r\n";
endwhile;
if (CloseFile (nvFileHandle) < 0) then
MessageBox ("CloseFile failed.", SEVERE);
endif;
StrReplace (svContent, "{{SQLSERVERSETTING}}", szServer, 0);
// Close the file.
OpenFileMode (FILE_MODE_BINARY);
if (OpenFile (nvFileHandle, EXAMPLE_DIR, EXAMPLE_FILE) < 0) then
MessageBox ("OpenFile failed.", SEVERE);
abort;
endif;
length = StrLength (svContent);
if (WriteBytes (nvFileHandle, svContent, 0, length) < 0) then
MessageBox ("WriteBytes failed.", SEVERE);
endif;
if (CloseFile (nvFileHandle) < 0) then
MessageBox ("CloseFile failed.", SEVERE);
endif;
end;
于 2010-08-25T06:16:24.797 回答