Set the StartType property to Automatic from the drop-down list. When you're finished, the Properties windows should look like the following figure:. Set the Account property to LocalSystem from the drop-down list.
The LocalSystem account has broad permissions, including the ability to write to the event log. Use this account with caution, because it might increase your risk of attacks from malicious software.
For other tasks, consider using the LocalService account, which acts as a non-privileged user on the local computer and presents anonymous credentials to any remote server. This example fails if you try to use the LocalService account, because it needs permission to write to the event log.
For more information about installers, see How to: Add installers to your service application. Before you decide to add startup parameters, consider whether it's the best way to pass information to your service.
Although they're easy to use and parse, and a user can easily override them, they might be harder for a user to discover and use without documentation.
Generally, if your service requires more than just a few startup parameters, you should use the registry or a configuration file instead. A Windows service can accept command-line arguments, or startup parameters. When you add code to process startup parameters, a user can start your service with their own custom startup parameters in the service properties window.
However, these startup parameters aren't persisted the next time the service starts. To set startup parameters permanently, set them in the registry. Under each service's subkey, use the Parameters subkey to store information that your service can access.
You can use application configuration files for a Windows service the same way you do for other types of programs. For sample code, see ConfigurationManager. Select Program. In the Main method, change the code to add an input parameter and pass it to the service constructor:.
In MyNewService. This code sets the event source and log name according to the startup parameters that the user supplies. If no arguments are supplied, it uses default values. To specify the command-line arguments, add the following code to the ProjectInstaller class in ProjectInstaller. Typically, this value contains the full path to the executable for the Windows service. For the service to start up correctly, the user must supply quotation marks for the path and each individual parameter.
A user can change the parameters in the ImagePath registry entry to change the startup parameters for the Windows service. However, a better way is to change the value programmatically and expose the functionality in a user-friendly way, such as by using a management or configuration utility. Program , or Sub Main for Visual Basic projects. Now that you've built the Windows service, you can install it. The output of. There's also a new "PublishProfilePath" field in the properties window when "PublishItemsOutputGroup" is selected which allows for the creation of self contained.
NET Core 3 installers. More details to come. NET Core What's new in 0. Visual Studio Code for Windows. Download Visual Studio Code. Highlights Free code editor Built on open source and runs everywhere Hundreds of programming languages supported. Visual Studio Code for Mac. NET Experience a fast and fluid, modern. Visual Studio Code for Linux. Download Visual Studio Code Linux x Highlights Free code editor Built on open source.
Runs everywhere Hundreds of programming languages supported. Visual Studio for Windows. Professional Enterprise Highlights Free for individual use Code faster, test, debug, deploy any app from one place Visual Studio built-in features empower full development cycle. I think I'd need to install Visual Studio on them for that, which I'd prefer not to. Is there a quicker way? Thank you for the responses. I now have a solution. This is a one-off task. Once the service is working, to update it I just need to stop it, upload the new myService.
Further information about settings you're using for the serviceProcessInstaller1 and serviceInstaller1 files will be needed to debug this issue, as the error raised by the installer is a generic error. An alternative way of doing this is to use Topshelf , which is a framework for hosting services written using the.
NET framework. It simplifies the creation of services, allowing developers to create a simple console application that can be installed as a service using Topshelf.
The reason for this is simple: It is far easier to debug a console application than a service. And once the application is tested and ready for production, Topshelf makes it easy to install the application as a service. Alternatively, you could use InstallUtil.
0コメント