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.
Related
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
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
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.
I created an installer and custom actions for a service.
On first install I managed to install the service , but when I tried running the service I got
an Error :Windows installer service cant start Error 193:0xc2
I have tried deleting this service in myriad of ways, yet on install I am still getting an error message 1001 The specified service already exists.
I deleted the service directly from the registry , but this does not seem to have worked.
I have tried
sc delete [service] --> The specified service does not exist as an installed service.
The service is not showing up in the registry nor is it present in installed services.
Any other thoughts or options would be appreciated
I have used this commands in a bat file that runs every time reinstalling. Try this and see.
set path=%path%;%SystemRoot%\Microsoft.NET\Framework\vXXX
InstallUtil /u YourService.exe
InstallUtil /i YourService.exe
net start "Service name"
If you want to delete/uninstall/remove a Windows service, perhaps left from an incomplete installer, you can use the sc command from an Administrator control prompt:
sc delete [servicename]
"sc delete" Deletes a service subkey from the registry. If the service is running or if another process has an open handle to the service, then the service is marked for deletion.
EDIT
I have tried sc delete [service] The specified service does not exist
as an installed service.
Probably restarting the machine would fix this.
sc.exe stop serviceName
sc.exe delete serviceName
and reboot the your VM\PC
This complaint may be coming from the installer, not from Windows.
I had this same issue earlier this year, I installed a service from an MSI file, which fouled up somewhere along the line. I uninstalled the package and tried reinstalling through the installer and got the same message as you did, that the service already existed. Frustrating. It didn't show up as an installed package at all anymore, nor did it show up in the service list.
It ended up that the MSI file did not clean up after itself properly during uninstall, but that I could manually manipulate this database and remove the information myself using MSIZap.exe. You need the Windows SDK to get at this program. There may be other ways, but I don't know of them.
You will need the package guid of your installation package to remove it using MSIZap. In the same directory as MsiZap.exe, you will find another application, MsiDb.exe. Run that, point it at your MSI file, point it to some empty directory to store some exports select the "Property" table, select the "Export" radio button and hit the "OK" button. Open the "Property.idk" file that was generated by MsiDb.exe in any text editor. Look in your text for a line that says "ProductCode". The GUID that follows is what you will feed into MsiZap, brackets and all. Now you will simply (bwahaha... yeah right) enter:
msizap T {product code}
Where "{product code}" is replaced by the GUID you found. This removes all traces of your product from the MSI database in windows, which should shut the installer up.
I realize that all of this is a ridiculous pain in the butt. I don't understand why finding a product code is such a trial. But, I suppose if the uninstaller worked, you wouldn't have to do its job for it now. There really might be a simpler way to do all of this, but I haven't found one. Once I found something that worked, I was over it.
As a final note, what caused this error for me was leaving the services list open during uninstall. An uninstaller which isn't paying attention could ignore some exceptions and leave pieces of itself lying about. I was lucky, the poorly behaving uninstaller was my own. And by the way, to appreciate just how much garbage is left over from uninstallation, check out this article.
I'm not sure if I had the same problem that you had, but if so, I hope this helps. If you need clarification, ask and I'll update the answer. If I'm up a tree and this has nothing to do with your problem, I apologize.
Try with Powershell and Wmi:
(gwmi win32_service -filter "name='yourservicename'").delete()
Make sure services.msc window is closed. Sometime that messes up the service deletion. I am not sure if this will help, you should not have touched the registry!
Perhaps you tried to delete the service while it's running? In that case you might need to reboot to clear things up.
How can I have code-sharing between two projects without making a dll?
The issue is: I have a tool that syncs users & groups from LDAP to a database.
Now the tool is a windows service, but testing it as such is very difficult and time consuming.
Which is why I made a console application where I can test the LDAP syncing, and then just copy the respective sourcecode-files over to the service project.
But... keeping the common files in sync is a bit of a problem.
I don't want to make a dll, because this probably creates me a problem with
the 3rd project, a windows installer (for the service) where I have to use ExecutingAssembly path...
Is there a way to share the code without making a separate dll?
Automagic statical linking, so to say ?
How about adding a file as a link.
In Visual Studio right click on your console test app project -> select add existing file -> in the file add dialog navigate to files in your actual windows service project -> select the files you want to share -> and on add button select add as link option.
You can add a file to a project as a link. On the Add Existing Item dialogue the Add button has a drop down on its right. Use this to select "Add as Link":
Put the file as a solution item and add as a link to each project.
How about hand-modify the project files to point to the same source file?
Another option - put both projects in the same folder. Add a class to one, then in the other project add existing class and point to the class just created.
You could:
maintain the shared code in a separate project that produces a DLL and then use a tool such as ILMerge to turn the DLL & EXE into one assembly.
share the source-files between multiple projects, either by tweakiing your project files or doing something funky with your source-tree layout.
All that said, the best approach would be to bite the bullet and store the shared code in a shared assembly (DLL). What happens when you decide to, for example, expose this code via a WCF service? It starts getting more complicated then as you have 3 places that reference the same code files. Don't just think about what makes your life easiest now, think about what'll make your life (and that of anyone else who has to maintain the code) easier in the future as well! =)
Necromancing - As per Visual Studio 2017:
You can create a shared project, and then reference the shared project in another project.
It will use the framework-version and libraries from the project you reference the shared-project from. You can also use the same shared project in multiple projects, provided you get no conflict.
This is basically statical linking on a source-code level.
This also works with HTML&JavaScript-files (specifically, it works with publishing), but with HTML & JS files, you will run into problems while debugging...
It's under "Classical Windows Desktop", but you can also use it for .NET Core etc.
If you want to share functionality, you should use a DLL or similar.
Since what you want to share is the source, what you are essentially sharing is file sharing. So you can do that by making your projects reference external sources or you can have your source control do this for you.
If you are using Visual SourceSafe, you can make a link between two folders. VSS will make sure that they are treated as the same file.
I'm going to describe the setup we use to manage and test our Windows Service projects. While this doesn't answer the question of "sharing code without a DLL" (Unmesh's answer takes care of that), I think the OP probably doesn't realize how easy this is with a DLL. In any case, I'm hoping it will help someone.
Create a solution, LDAPSync. Create three projects in this solution:
LDAPSyncLib
LDAPSyncSvc
LDAPSyncTest
LDAPSyncLib is a DLL project that contains all of your business logic and main functionality.
LDAPSyncSvc is a Windows Service project that contains two classes, a service controller class that inherits from ServiceBase, and an Installer class for your service. This project has a "project reference" to LDAPSyncLib.
LDAPSyncTest is either a GUI application (WinForms, WCF, etc.) or a console application, depending on your needs. This project also has a "project reference" to LDAPSyncLib. Its sole purpose is to provide some interface which allows you to easily make the required calls into your business logic for testing purposes. In Visual Studio, set this as your "StartUp Project".
Now, when you run in debug via Visual Studio you will get a nice little GUI or command window that you can use to manually make test calls. When you install it as a Windows Service, the LDAPSyncSvc project's controller class will take over and handle all of the necessary service requests (start, stop, pause, etc.)
We have around 30 in-house Windows Service projects that we've been continuously managing, developing and testing for over a decade and this workflow has proved invaluable in quickly finding and fixing bugs when they arise. Best of luck with your project and I hope this helps some future Googlers.