I wanted to add some information to an install log file about the system that I was installing on. I created a separate Log function that can be called from anywhere in the script. It has been very valuable when an install happens in production and there are issues. I added a Log function call to the beginning and end of each function in my script, so I know when the function is being called.
I also added a function to get the computer name.
The creation of the InstallLog.txt file takes place in the OnBegin function with the following code:
// Create a log file on the C drive so that
// the install can log information to it. This is a convenient
// location for tech support to find it.
OpenFileMode(FILE_MODE_APPEND);
CreateFile(g_LogFileHandle, "C:\\", "InstallLog.txt");
Log("--Start - OnBegin()");
Log("Begin Log File");
......
// Write information to the InstallLog.txt file
function Log(strInfo)
NUMBER nvResult;
STRING svResult;
begin
GetSystemInfo (TIME, nvResult, svResult);
strInfo = svResult + " : " + strInfo;
WriteLine(g_LogFileHandle, strInfo);
end;
......
//Send system information to log file
function LogSystemInfo()
STRING svComputerName, svDate, svOS, svOSSP, svWinMajor, svWinMinor;
NUMBER nvDate, nvOS, nvOSSP, nWinMajor, nWinMinor;
begin
Log("--Start - LogSystemInfo()");
//log date
GetSystemInfo (DATE, nvDate, svDate);
Log("Date of Install = " + svDate);
//log computer name
svComputerName = GetComputerName();
Log("Computer Name = " + svComputerName);
// Get the operating system.
nvOS = SYSINFO.nISOSL;
switch (nvOS)
case ISOSL_WIN2000:
svOS = "Windows 2000";
case ISOSL_WINXP:
svOS = "Windows XP";
case ISOSL_WINSERVER2003:
svOS = "Windows 2003 Server";
case ISOSL_WINVISTA:
svOS = "Windows Vista";
default:
svOS = "Invalid OS";
endswitch;
Log("Operating System = " + svOS);
//get windows major version
nWinMajor = SYSINFO.nWinMajor;
NumToStr(svWinMajor, nWinMajor);
Log("OS Major Version = " + svWinMajor);
//get windows minor version
nWinMinor = SYSINFO.nWinMinor;
NumToStr(svWinMinor, nWinMinor);
Log("OS Minor Version = " + svWinMinor);
//get operating system service pack
nvOSSP = SYSINFO.WINNT.nServicePack;
NumToStr(svOSSP, nvOSSP);
Log("OS Service Pack = " + svOSSP);
Log("--End - LogSystemInfo()");
end;
....
//get the name of the computer we are installing on
function string GetComputerName()
string szKey, szName, svValue;
number nvSize, nvType;
begin
szKey = "System\\CurrentControlSet\\Control\\ComputerName\\ComputerName";
szName = "ComputerName";
// Set the default root.
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
// Retrieve the registry key value.
RegDBGetKeyValueEx(szKey, szName, nvType, svValue, nvSize);
return svValue;
end;