Thursday, April 9, 2009

InstallShield Merging Web Sites (Correction)

I found that the redirection in the command line wasn't working correctly. So, I created a DOC batch file to wrap the command line. The InstallScript changes to this:


//---------------------------------------------------------------------------
// GetNextWebSiteNumber
//
// This function returns the next available web site number based on entries
// for current web sites in IIS. The admin script adsutil.vbs is used the
// query current web sites.
// If there is an error, the function returns -1.
//---------------------------------------------------------------------------
function GetNextWebSiteNumber()
NUMBER nResult;
NUMBER nvTempWebSiteNumber;
NUMBER nWebSiteNumber;
NUMBER nvFileHandle;
NUMBER nNumPos;
STRING szProgName;
STRING szProgParams;
STRING szFileDir;
STRING szFileName;
STRING svLine;
STRING svSiteNum;
STRING svNumStr;
begin
nvTempWebSiteNumber = -1;
nWebSiteNumber = nvTempWebSiteNumber;
szFileDir = SUPPORTDIR;
szFileName = "websiteenum.txt";

//
// Run the adsutil.vbs script and get all the web sites. Put the
// output into a file. NOTE - InstallShield doesn't pass the
// redirect through correctly, so the adsutil needs to be called
// from a batch file so the output can be captured.
//
szProgName = WINDIR^"system32\\cmd.exe";
szProgParams = " /c " + SUPPORTDIR^"CmdOutToFile.bat \"" + WINDIR^"system32\\cscript.exe C:\\inetpub\\AdminScripts\\adsutil.vbs ENUM /p W3SVC\" \"" + szFileDir^szFileName + "\"";
StatusBox("Running " + szProgName + szProgParams, DEBUG);
if (LaunchAppAndWait(szProgName, szProgParams, WAIT) >= 0) then
//
// Open the file with the web sites and find the number
// of the last one.
//
OpenFileMode(FILE_MODE_NORMAL);
nResult = OpenFile (nvFileHandle, szFileDir, szFileName);
if (nResult = 0) then
while GetLine (nvFileHandle, svLine) = 0
if (svLine % "W3SVC/") then
StrSub(svSiteNum, svLine, 8, StrLengthChars(svLine) - 9);
StrToNum(nvTempWebSiteNumber, svSiteNum);
if (nvTempWebSiteNumber > nWebSiteNumber) then
nWebSiteNumber = nvTempWebSiteNumber;
endif;
endif;
endwhile;
CloseFile(nvFileHandle);
nWebSiteNumber = nWebSiteNumber + 1;
else
NumToStr(svNumStr, nResult);
StatusBox("Could not open the web site enumeration file " + szFileDir + szFileName + " (Result = " + svNumStr + ")", DEBUG);
endif;
endif;
return (nWebSiteNumber);
end;


Here is the DOS Batch file:

::@echo off
::----------------------------------------------------------------------------
:: CmdOutToFile.bat
::
:: Wrap a command that redirects output to a file. This is to allow the
:: output to be captured when run from a program that doesn't allow this, such
:: as InstallShield.
::
:: Parameters:
:: Parameter 1 = The command to run.
:: Parameter 2 = The file to redirect output to.
::
::----------------------------------------------------------------------------

:: Get the command line
set cmdLine=%1
set outputFile=%2

:: Remove quotes
set cmdLine=%cmdLine:"=%
set outputFile=%outputFile:"=%

:: Run the command
%cmdLine% > %outputFile%


BTW, I noticed that the blogger doesn't scroll horizontally or widen. However, the text is there, so you can copy and paste it into notepad to see it all. I prefer showing it this way as the whitespace is preserved. If I let HTML format it, it strips all that and makes it unpleasant. I will work on finding alternatives.

No comments: