开发者

Modifying app.config through installscript

How to modify app.config files through installscrip开发者_运维百科t in installshield 2010. I want to modify the sql connection string in app.config file based on user selected server. Early help should be appreciated.


I have written own installscript to change the connection string.

Code snippet :

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜