Windows Service properties - c#

How to change the the service name for my windows service in Visual Studio 2012. I'm just new to the windows service, and trying to figure out how to build it.
I've googled and read a a lot about Windows services and how to build them. Everywhere they mention:
In the Properties window for Service1.cs [Design] or Service1.vb [Design], set the ServiceName and the (Name) property for Service1 to MyNewService, if it's not already set.
But for me I can't seem to find where to change the servicename. I rightclicked on service1.cs and and went to properties. Here is a screenshot
It doesn't show me the ServiceName.

You're looking at the properties of the CS file, not the service object itself.
DOuble click it to open in the designer, then you will get actual properties of the service, including ServiceName

It depends on how you install the service. If you use sc.exe you will specify name as command parameter in installation. If you use install util, you can specify name in code.
Also look at this

Related

How to create an installer for a web service without a user interface?

I have created a Web service. I need to add the ability to install it from the command line.
I created the installer for the web service like this:
I created a new Web Setup Project and added my web service to it. An installer user interface has been automatically created. It included a form for entering the parameters "Site", "Virtual directory" and "Application Pool". I added another form for typing two text parameters. Then I created a new project and called it "Deployment". In this project, I created the class "InstallAction". In it, I redefined the Install method to process my text parameters.
Now I need to add the ability to run the installer from the command line (Cmd.exe). The user interface should not be displayed! All parameters (including "Site", "Virtual directory" and "Application Pool") should be passed as parameters to the command. How to do this?
VS Setup Projects: Visual Studio Setup projects are limited. There are many alternative MSI tools. WiX is free and open source. Advanced Installer has great IIS features.
Parameters: I just commented on setup parameters in another question. Essentially your fields in your dialogs should have PUBLIC properties assigned to them (only PUBLIC - or UPPERCASE properties can be set at the command line). You must also mark these properties secure by adding them to the SecureCustomProperties list.
These pre-existing answers contain more detailed descriptions of how to deal with parameter passing:
How to make better use of MSI files
Parameterizing an MSI setup (just overview)
Mock-Up: for your case, maybe something like this:
msiexec.exe /i setup.msi SITE="mysite.com" VIRTUALDIR="mysite.com" APPPOOL="mysite.com" /qn

Installing windows service fails: service already exists

I'm trying to reinstall a service I've written using C#.
The first time this worked. I used installutil to handle the install and the service showed up in the list of services and I could start it.
Then I made some updates to the code and uninstalled the service. After figuring out I had to close the services window, the service seemed to have disappeared (i.e. successfully uninstalled).
However, upon trying to install the service again I got the message saying:
System.ComponentModel.Win32Exception: The specified service already exists
This seemed strange as I couldn't see it in the services window. I finally thought I found the problem after deleting a registry key regarding my service, but unfortunately this didn't solve anything.
Also, uninstalling again doesn't do much to solve the problem as this results in the contradictory message:
System.ComponentModel.Win32Exception: The specified service does not exist as an installed service
What should I believe? Does or doesn't the service exists? I feel like a physicist trying to figure out whether the cat is dead or alive. I hope someone here knows something to help solve this problem.
A related SO-answer finally pointed me in the right direction (why I didn't find that in Google or SO's own search I don't know).
Anyway, apparently the Designer.cs generated by Visual Studio also creates a process- and service-installer. Which of course install services with the same name as my manually created installers.
Removing my own installers solved the problem.
Actual issue is that you have added the object of serviceProcessInstaller & serviceInstaller multiple times in your code ..
It should only be added once..
Open the designer.cs file of projectinstaller you will see it is already added there...
I was also getting the same error, so to resolve, what I did was:
Open the ProjectInstaller.cs from solution Explorer
Go into view designer mode by right clicking, if code view is there
You will see a new installer apart from defaults 2, i.e. serviceprocessInstaller1 and ServiceInstaller1.
Just remove that installer which was automatically generated. Now build and install, it will work.
Check the Service Name Property in Service Installer.
I have tried all solution mentioned above. But my service was installed with some different name in registry. So just try to delete that registry.
Open below link in registry
Hkey_Local_Macine>System>CurrentControlSet>Service>
But I didnt find my service under this path. So I tried to find it out in registry. Just press ctrl + F and give the name of your service. or some guess name. You will get the exact location.
Just delete it. It will work.
Need to remove "Me.Installers.AddRange(New System.Configuration.Install.Installer() {Me.ServiceInstaller1, Me.ServiceProcessInstaller1})" line if same line is there already in designer, then it will get installed.
ServiceProcessInstaller1 is name in my project.

How to get a Web Service to use a Fixed Port Number When Using the Visual Studio Development Server?

I have an asp.net website and a windows form application.
My Webservice's Location is : http://localhost:12312/MyWebSiteFolder/WSFile.asmx
Problem is : the port number keeps changing, if I reopen the solution, its going to change to something else:
http://localhost:11122/MyWebSiteFolder/WSFile.asmx
Is there a way so I won't have to update the location of the file in my windows form application everytime I reopen the website's solution?
(assuming Visual Studio 2010)
Under the Web tab of the properties for the project, change the "Auto-assign Port" option to "Specific port" and enter the port you want to always use.
Alternately, if possible, you can choose the option to use your local IIS server.
Update:
If you're using a "Web Site" project instead of "Web Application," the setting is located in the properties window of the project instead of the properties dialog. Note the "Use dynamic ports" option here:
How does your web application look on the Solution explorer - does it show
<drive>:\<some directory>
or
does it show the name of your web application with no path.
or
does it show http:/// <something>
In case 1 you should be able to see properties. But you wont get it for the rest

Installed Win Service not displaying in Service Manager

I have a Windows Service created in c#.
It's relatively simple compared to some of the other ones that I've worked on.
I built a setup project to install it for some testing.
I added the primary output from the service project and all the dependencies were added correctly.
I went to View > Custom Actions and added my Primary output to Install, Commit, Rollback, and Uninstall.
The project built and I right clicked the project and clicked Install.
The installation came back successful, I can view the service on the control panel under Add/Remove programs, but when I go into the Service Manager... nothing...
Can anyone provide some insite or anything else that may cause a successfuly installed service to NOT display on the Service Manager.
Forgive me if this goes without saying, but you haven't mentioned what code you are executing in your custom actions. Your service assembly must have a class which derives from System.Configuration.Install.Installer, and that class must have the [RunInstaller(true)] attribute on it. Within that class, you will need to create an instance of System.ServiceProcess.ServiceInstaller and System.ServiceProcess.ServiceProcessInstaller, set the appropriate parameters on those instances, and add them to the Installers collection. The ServiceInstaller and ServiceProcessInstaller MSDN pages have a very basic example, but it should be enough to get you there if this is what is needed.
Make sure you had provided some value in "Display name" property.
Use the following command "sc query <service_name>" from command prompt to see whether your windows service got properly installed. If you are not sure on the service name use the following command "sc query state= all >c:\ServicesList.txt" after executing this command search the ServicesList.txt in your C:\ drive.
If that too doesn't work try looking for the service name in registry under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
You said you added your primary output to Install, etc. But did you create an Installer derived class to do the actual installing of the windows service? I'm not talking the setup project itself, but in your project there should be an installer class that actually does the service install for you.
I had a post on my blog about creating a framework for easy installable services, it has examples on creating the isntaler class.
http://blackrabbitcoder.net/archive/2010/10/07/c-windows-services-2-of-2-self-installing-windows-service-template.aspx
In my case, solution of the problem was simple, i forgot to add access modifier 'Public' to the class. After adding access modifier, service is visible now in services list.

How can i start windows service automatically

i try to develop a windows service. My win service must run if windows 7 stars up. How can i do?
Change the startup type of the service to Automatic.
You should create an installer application for your service (if you haven't already) and you can set this option in there so when its installed it is pre-configured this way. See Walkthrough: Creating a Windows Service Application in the Component Designer
Set the startup type to "Automatic".
You set service startup to "Automatic" in service control manager. Not a programming question, by the way.
Actually make sure your installer sets the startup type on Automatic ;) Add dependencies as needed so that you start after dependent services.
If you want to set this programmatically (i.e. during the development phase) then this is set in the properties for the Installer (StartType), which you will also need.
You could configure the service through the command line using the "SC" utility provided by Windows; it comes with XP and later.
sc create MyServiceName binPath= <path
to service exe file> start= auto
DisplayName= MyServiceDisplayName
sc description MyServiceName "This is
my service's description"
The spaces after arguments (like binPath= ) are important.

Categories

Resources