cancel
Showing results for 
Search instead for 
Did you mean: 

Create and Register a Windows Service through Custom Code

Create and Register a Windows Service through Custom Code

Summary

This article discusses how to create and register a Windows service through Custom Code.

Synopsis

This article discusses how to create and register a Windows service through Custom Code.

Discussion

Here is a sample Custom Code snippet:
public void install(InstallerProxy ip) throws InstallException 
{	
	try 
	{ 
		String myUserInstallDir = ip.substitute("$USER_INSTALL_DIR$"); 

		Win32Service win32Service = (Win32Service) ip.getService(Win32Service.class); 
		NTServiceConfig config = new NTServiceConfig(); 
		config.setDisplayName("TrainingService"); 
		config.setStartType(NTServiceConfig.SERVICE_AUTO_START); 
		config.setErrorControl(NTServiceConfig.SERVICE_ERROR_NORMAL); 
		JOptionPane.showMessageDialog(null,"USER_INSTALL_DIR="+myUserInstallDir+"\\TrainingService.exe"); 
		config.setCommand(myUserInstallDir+"\\TestService.exe"); 
		win32Service.createNTService("TestService", config); 
	} 
	catch (ServiceException ex) 
	{ 
		JOptionPane.showMessageDialog(null, ex); 
	} 
}

Note: This is only sample Custom Code, which is strictly for example purposes. The Custom Code should be customized and thoroughly tested before deployment into production.

Additional Information

For more information about Custom Code, click here.

For documentation for the InstallAnywhere Custom Code API, click here.

Start or Stop a Windows Service Using Custom Code

How to Check the Status of a Windows Service
Labels (1)
Was this article helpful? Yes No
No ratings
Comments
I cannot find which jar/zip file defined the Win32Service class. I know the main package used by Installanywhere is IAClasses.zip. But I cannot find this class in IAClasses.zip