This information comes from the network, I just summarize.
VS Create Project, project type Select Window Service
To create a setup program for a service
1. Return to the Design view of the Service1.
2: Click the background of the designer to select the service itself, not any of its contents.
3. In the Properties window, click the Add Installer link in the gray area below the list of properties.
By default, a component class that contains two installers is added to your project. Name the component
ProjectInstaller, which contains the Setup program for the service and the installation of the service associated process, respectively
Order.
4. Visit the Design view of the ProjectInstaller, and then click ServiceInstaller1.
5. In the Properties window, set the ServiceName property to MyNewService.
6: Set the StartType property to Automatic.
7. In the designer, select ServiceProcessInstaller1 (for Visual Basic projects),
or ServiceProcessInstaller1 (for Visual C # projects). Set the Account property to
LocalService. This will cause the service to be installed and running on the local service account. For more information, see
The Serviceprocessinstaller.account property.
Security Note the LocalService account acts as a non-privileged user on the local computer, to any remote service
The device displays anonymous credentials. Use other accounts with special care, so they have higher privileges and increase your
Be at risk of malicious code attacks.
set the service to "allow service to interact with the desktop"
To set the 7th step in the "Allow service to interact with desktop" section above: the account attribute must be set to LocalSystem, Then overload Onafterinstall in the ProjectInstaller class in ProjectInstaller.cs, with the following code:
[Runinstaller (true)] Public Partial classProjectInstaller:System.Configuration.Install.Installer { Public ProjectInstaller() {InitializeComponent (); }protected Override void Onafterinstall(IDictionary savedstate) {Try{Base. Onafterinstall (savedstate); System.Management.ManagementObject MyService =NewSystem.Management.ManagementObject (string. Format ("Win32_service.name= ' {0} '", This. Serviceinstaller1.servicename)); System.Management.ManagementBaseObject Changemethod = Myservice.getmethodparameters ("Change"); changemethod["DesktopInteract"] =true; System.Management.ManagementBaseObject Outparam = Myservice.invokemethod ("Change", Changemethod,NULL); }Catch(Exception) { } } }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C # writes the Windows service and sets it to "allow service to interact with the desktop"