📄 setup.rul.in
字号:
AskText(szMessage, svNTPAddress2, svNTPAddress2);
CreateConfigFiles(TWOTIMESOURCES); // create ntp.conf
endif;
if (bNoSourceNTP) then
CreateConfigFiles(NOTIMEYET); // create ntp.conf and ntp.drift
endif;
if (AskYesNo("Do you want to see the NTP configuration file which has\n" +
"been created for this host?\n", YES) = YES) then
// Let them see/edit the files, if they want to:
LaunchAppAndWait("NOTEPAD.EXE", WINDIR ^ "ntp.conf",1);
endif;
end;
/*---------------------------------------------------------------------------*\
*
* Function: CreateConfigFiles
*
* Purpose: Now that we know the domain name, host name, and IP Address,
* create the configuration files for this NTP to be of type
* specified by parameter:
* ONETIMESOURCE
* TWOTIMESOURCES
* NOTIMEYET
*
*
* Need to have filled in:
* svNTPAddress
* svNTPAddress2
*
\*---------------------------------------------------------------------------*/
function CreateConfigFiles(nType)
NUMBER nvFileHandle;
STRING svInAddrArpa;
STRING saveddir;
STRING svIP;
begin
CreateFile(nvFileHandle,WINDIR,"ntp.conf");
WriteLine(nvFileHandle,"#");
WriteLine(nvFileHandle,"# File: ntp.conf");
WriteLine(nvFileHandle,"# Purpose: give the NTP Service its startup parameters and");
WriteLine(nvFileHandle,"# list of startup files.");
WriteLine(nvFileHandle,"# ");
WriteLine(nvFileHandle,"# ");
WriteLine(nvFileHandle,"#");
WriteLine(nvFileHandle,"# Miscellaneous stuff");
WriteLine(nvFileHandle,"#");
WriteLine(nvFileHandle,"driftfile %windir%\\ntp.drift # path for drift file");
WriteLine(nvFileHandle,"# statsdir c:\\var\\ntp\\stats\\ # directory for statistics files");
WriteLine(nvFileHandle,"# filegen peerstats file peerstats type day enable");
WriteLine(nvFileHandle,"# filegen loopstats file loopstats type day enable");
WriteLine(nvFileHandle,"# filegen clockstats file clockstats type day enable");
if (nType != NOTIMEYET) then
WriteLine(nvFileHandle,"# Need to set up time sources...");
WriteLine(nvFileHandle,"# server ip-address");
WriteLine(nvFileHandle,"# ");
WriteLine(nvFileHandle,"# ");
endif;
if (nType = TWOTIMESOURCES) then
WriteLine(nvFileHandle,"# ");
WriteLine(nvFileHandle,"server " + svNTPAddress);
WriteLine(nvFileHandle,"server " + svNTPAddress2);
WriteLine(nvFileHandle,"# ");
WriteLine(nvFileHandle,"# ");
endif;
if (nType = ONETIMESOURCE) then
WriteLine(nvFileHandle," ");
WriteLine(nvFileHandle,"server " + svNTPAddress);
WriteLine(nvFileHandle," ");
WriteLine(nvFileHandle," ");
endif;
CloseFile(nvFileHandle);
CreateFile(nvFileHandle,WINDIR,"ntp.drift");
WriteLine(nvFileHandle,"0 0");
CloseFile(nvFileHandle);
end;
/*---------------------------------------------------------------------------*\
*
* Function: SetupScreen
*
* Purpose: This function will set up the screen look. This includes
* colors, fonts, text to be displayed, etc.
*
\*---------------------------------------------------------------------------*/
function SetupScreen()
INT nDx, nDy;
begin
Enable( DEFWINDOWMODE );
Enable( INDVFILESTATUS );
//----------------------------------------------------------
// If you want to downsize the Blue-fade background:
//
// GetExtents(nDx,nDy);
//
//
// PlaceWindow(BACKGROUND,nDx/2,0,UPPER_LEFT);
// SizeWindow(BACKGROUND,nDx/2,nDy/2);
//
// However will also have to move all the dialogs/bitmaps
// around to make this work correctly...
//----------------------------------------------------------
SetTitle( APP_NAME2 + " Setup", 24, WHITE );
// SetColor( BACKGROUND, BK_BLUE ); // Dark blue.
// SetColor( STATUSBAR, BLUE ); // Bright blue.
SetTitle( "Setup", 0, BACKGROUNDCAPTION ); // Caption bar text.
Enable( BACKGROUND );
Delay( 1 );
// Show the bitmap.
// PlaceBitmap( SUPPORTDIR ^ "NTPNT.BMP",1,10,10,UPPER_RIGHT);
end;
/*---------------------------------------------------------------------------*\
* Function: CheckRequirements
* Purpose: This function will make sure we are on NT, not Win95.
\*---------------------------------------------------------------------------*/
function CheckRequirements()
number nvVersion;
STRING szResult, svVersion;
begin
// Determine the target system's operating system.
GetSystemInfo( OS, nvVersion, svVersion );
if (nvVersion = IS_WINDOWSNT) then
MessageBox("This product can only run on Windows NT", SEVERE);
exit;
endif;
end;
//+---------------------------------------------------------------------------
// Member: ReportError()
//----------------------------------------------------------------------------
function ReportError(n_Err, sz_Message)
begin
switch(n_Err)
case k_PrivilegeErr: sz_Message = "Privilege Error";
case k_CreateKeyErr: sz_Message = "Create Key Failed";
case k_RestoreKeyErr: sz_Message = "Restore Default Key Failed";
case k_ErrUnableToOpenWriteOwner: sz_Message = "Unable to Open and Write Owner Information";
case k_ErrUnableToSetOwner: sz_Message = "Unable to Set Owner Information";
case k_ErrUnableToOpenDAC: sz_Message = "Unable to Open Access Control List";
case k_ErrUnableToWriteDACL: sz_Message = "Unable to Write Access Control List";
case k_OpenKeyError: sz_Message = "Unable to Open Registry Key Entry";
case k_ModifySetAccountFail: sz_Message = "Unable to Setup Account Parameters";
case k_SCMErr: sz_Message = "Unable to Open Service Control Manager Database";
case k_SCMpoErr: sz_Message = "Unable to Open NTP - NT service entries in the Service Control Manager";
case k_DeleteServiceFail: sz_Message = "Unable to delete NTP - NT service";
case k_DeleteKeyFail: sz_Message = "Unable to delete registry key information";
case k_DeleteValueFail: sz_Message = "Unable to delete registry value information";
case k_DirSecurityErr: sz_Message = "Unable to retreive Security information on directory";
case k_DirSetDACLErr: sz_Message = "Unable to add security information on directory";
case k_DirSetSecurityErr: sz_Message = "Unable to set directory security information";
case k_SCMpoStopErr: sz_Message = "Unable to stop the NTP - NT service";
case k_SaveKeyErr: sz_Message = "Unable to save registry key.";
case k_ServiceUnknownErr: sz_Message = "The service control manager could not start the NTP - NT service - please check the event log";
case k_ServiceDependency: sz_Message = "The NTP - NT service depends on several other services which are not installed.";
case k_ServiceDependencyFail: sz_Message = "The NTP - NT service depends on other services which failed to start.";
case k_ServiceLogonFail: sz_Message = "The service manager was unable to login the NTP - NT service - Please check the password and logon as service privilege";
case k_BadPath: sz_Message = "Bad Path Specified.";
case k_AccessDenied: sz_Message = "Access Denied.";
case k_ServiceExists: sz_Message = "NTP - NT service already exists so cannot be re-installed";
case k_createservicefailed: sz_Message = "Creation of the NTP - NT service failed.";
case k_removeservicefailed: sz_Message = "Unable to remove the NTP - NT service.";
case k_ServicenoExists: sz_Message = "NTP - NT service is not installed so cannot be removed.";
default: sz_Message = "Unknown Error";
endswitch;
end;
//+---------------------------------------------------------------------------
//
// Member: RemoveNTP()
//
// Synopsis: Remove the NTP service entry and registry entries
//
//----------------------------------------------------------------------------
function RemoveNTP()
NUMBER n_Result;
begin
dummy = APP_NAME;
SetStatusWindow( 0, "Stopping and removing NTP service..." );
// Remove the NTP service entry & Registry but first stop the service
nReturnValue2 = CallDLLFx(szDllNTPInst,"StopNTPService",nValue,dummy);
if (nReturnValue2 != 0) then
ReportError(nReturnValue2,szMessage);
NumToStr( szTemp, nReturnValue2 );
szMessage = "Unable to Stop the NTP - NT Service. \n" + szTemp + "\nAre you sure it is installed?\n" + szMessage;
MessageBox(szMessage,SEVERE);
exit;
endif;
Delay( 3 ); // delay for xntpd.exe file to free up so delete works
// have to get the currently install directory from the dll by pulling it off of the imagepath param
//if (GetImagePath(svModuleDir) != 0) then
// szMessage = "Unable to retrieve the path to Remove NTP Files \n" + svModuleDir +
// "\nAre you sure it is installed?\n";
// MessageBox(szMessage,SEVERE);
// exit;
//endif;
n_Result = CallDLLFx(szDllNTPInst,"RemoveNTPService",nValue,dummy);
if (n_Result != 0) then
MessageBox("Unable to remove NTP - NT service from the registry.",SEVERE);
exit;
else
if (AskYesNo("Service Removed\n Do you want to delete all the NTP Executables and config files also?\n",
NO) = YES) then
TARGETDIR = WINSYSDIR; // pick off the files we put in the
DeleteFile("ntpdate.exe");
DeleteFile("ntpq.exe");
DeleteFile("ntptrace.exe");
DeleteFile("xntpdc.exe");
DeleteFile("xntpd.exe");
DeleteFile("instsrv.exe");
TARGETDIR = svModuleDir;
DeleteFile("ntpog.wri");
DeleteFile("readme.nt");
DeleteDir(svModuleDir, ONLYDIR);
TARGETDIR = WINDIR;
DeleteFile("ntp.conf");
DeleteFile("ntp.drift");
MessageBox("NTP - NT service and registry entries are removed.\n" +
"All Executable/Config files have been deleted.",INFORMATION);
else
MessageBox("NTP - NT service and registry entries are removed.\n" +
"All Executable/Config files are retained.",INFORMATION);
endif;
endif;
end;
//+---------------------------------------------------------------------------
//
// Member: UpdateModules()
//
//----------------------------------------------------------------------------
function UpdateModules()
STRING szFileSet;
STRING szMessage;
NUMBER nvSize, nvType;
begin
SetStatusWindow( 0, "Updating NTP installation..." );
nReturnValue2 = CallDLLFx(szDllNTPInst,"StopNTPService",nValue,dummy);
if (nReturnValue2 != 0) then
ReportError(nReturnValue2,szMessage);
NumToStr( szTemp, nReturnValue2 );
szMessage = "Unable to Stop the NTP - NT Service. \n" + szTemp + "\nAre you sure it is running?\n" + szMessage;
MessageBox(szMessage,SEVERE);
exit;
endif;
Delay( 3 ); // delay for xntpd.exe file to free up so copy works
// have to get the currently install directory from the dll by pulling it off of the imagepath param
if (GetImagePath(svModuleDir) != 0) then
szMessage = "Unable to retrieve the path to Update NTP Files \n" + svModuleDir +
"\nAre you sure it is installed?\n";
MessageBox(szMessage,SEVERE);
exit;
endif;
InstallNTPFiles(svModuleDir,1);
nReturnValue2 = CallDLLFx(szDllNTPInst,"StartNTPService",nValue,dummy);
if (nReturnValue2 != 0) then
ReportError(nReturnValue2,szMessage);
szMessage = "Unable to start the NTP - NT Service.\n" + szMessage;
MessageBox(szMessage,SEVERE);
exit;
endif;
SetStatusWindow( 100, "Update completed." );
Delay( 2 );
MessageBox("Your Network Time Protocol Server modules have been updated and\n" +
"the service restarted. You should check the event log\n" +
"to make sure everything came back up properly.",INFORMATION);
end;
/*---------------------------------------------------------------------------*\
*
* Function: GetImagePAth
*
* Purpose: Get the given value, under the given key, from the registry.
* l. kahn
\*---------------------------------------------------------------------------*/
function GetImagePath(svValue)
NUMBER nvSize;
NUMBER nvType;
begin
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
if (RegDBGetKeyValueEx(SERVICE_ENTRY,
"ImagePath",nvType,svValue,nvSize) < 0) then
return -1;
endif;
StrSub(svValue,svValue,0,nvSize - 10); // trim to REAL length
return 0;
end;
function CheckForService()
STRING temp;
NUMBER nvSize;
NUMBER nvType;
begin
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
if (RegDBGetKeyValueEx(SERVICE_ENTRY,
"ImagePath",nvType,temp,nvSize) < 0) then
return 0;
endif;
return -1;
end;
/*---------------------------------------------------------------------------*\
*
* Function: LaunchAppAndWait
*
* Purpose: replace predefined function in more expensive InstallShield
* with C function.
* l. kahn
\*---------------------------------------------------------------------------*/
function LaunchAppAndWait(svApp, svData, waitval)
STRING tstring;
begin
nValue = waitval;
tstring = svApp+" "+svData;
nReturnValue2 = CallDLLFx(szDllNTPInst,"LaunchApp",nValue,tstring);
return 0;
end;
/*---------------------------------------------------------------------------*\
*
* Function: FixDirectory
*
* Purpose: put the double slashes in the directory
* l. kahn
\*---------------------------------------------------------------------------*/
function FixDirectory(svOut,svIn)
INT len;
INT ctr;
NUMBER letter;
INT i;
begin
len = StrLength(svIn) - 1;
ctr = 0;
for i = 0 to len
GetByte(letter,svIn,i);
if (letter = 92)
then
SetByte(svOut,ctr,letter);
ctr = ctr + 1;
endif;
SetByte(svOut,ctr,letter);
ctr = ctr + 1;
endfor;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -