Deploy a windows service without Installshield - visual-studio-2012

Is it possible to deploy a windows service without going through Installshield? I have a very basic service which simply probes a database, and wish to deploy it on a server.
I tried using Installsheild LE, but get error 1001 on install, which is hard to troubleshoot, and anyhow Installshield feels like overkill in this case... is there a way can just install the service direct by command line or other method?

Yes.
However, there are options, from best to worst:
There are other tools for writing installers out there. Eg. the full version of install Shield or WiX (which MS created, and is used for the Visual Studio installer).
You could use installUtil having included a type derived from ServiceInstaller in your assembly. (See How to: Install and Uninstall Service.)
You can manually edit the registry.
#3 Is seriously easy to mess up, and won't help you with the event logging and performance counters you should be including.1 #2 is best in development, and will set up event logs and performance counters as well (remember you'll need to elevate to install things, and to attach a debugger to the service when running as a service).
Using a real installer (#1) is best in test (staging) and production environments.
1 When you get asked why it isn't working, you'll want to be able to work out what's going on (or not).

Yes, if your service has an Installer class then, you can install it from command line with installutil.exe
using System.ComponentModel;
using System.Configuration.Install;
using System.ServiceProcess;
[RunInstaller(true)]
public class ServiceInstaller : Installer
{
public ServiceInstaller()
{
ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
ServiceInstaller serviceInstaller = new ServiceInstaller();
//# Service Account Information
serviceProcessInstaller.Account = ServiceAccount.User;
serviceProcessInstaller.Username = "";
serviceProcessInstaller.Password = "";
//# Service Information
serviceInstaller.DisplayName = "Service name"
serviceInstaller.Description = "Service description"
serviceInstaller.StartType = ServiceStartMode.Automatic;
//# This must be identical to the WindowsService.ServiceBase name
//# set in the constructor of WindowsService.cs
serviceInstaller.ServiceName = "Service Name";
this.Installers.Add(serviceProcessInstaller);
this.Installers.Add(serviceInstaller);
}
}

Building and Deploying a Windows Service using IsWiX
The above is a short video I made showing how to use WiX / IsWiX to generate a very clean MSI for installing a service. It's really easy, fast, elegant and free.

You can use the command line tool sc.exe to create and configure a windows service (basically insert the config into registry), assuming you have already deployed the built .exe to disk somewhere on your server.
http://support2.microsoft.com/kb/251192

Related

manageprofiles.sh can't create DEPLOYMENT MANAGER

My goal is to create a Deployment Manager profile in my Websphere on Linux.
Reading tons of documentation pages gives just two methods:
1) using X GUI application WAS_root/bin/ProfileManagement/pmt.sh
In this case, according to manuals, i should choose Management option, click "Next" and choose Deployment Manager server type.
Actually when i run pmt.sh in my WAS installation there is no option to choose Deployment Manager in Management section and only one profile type that i'm able to create is AdminAgent.
2) using manageprofiles.sh script under WAS_root/bin directory.
The manuals say that i can use -serverType DEPLOYMENT_MANAGER option in order to create deployment manager profile.
Actually when i run the script:
./manageprofiles.sh -create -templatePath ../profileTemplates/management/ -ServerType DEPLOYMENT_MANAGER -isDefault -profileName dmgr -adminUserName websphere -adminPassword websphere1
I get the following message:
The following validation errors were present with the command line
arguments:
serverType: The value for this parameter must be within this set of values [ADMIN_AGENT]
That means that i don't have the ability to create Deployment Manager at all.
Please advise what steps i can perform to be able to install Deploy Manager except erase my WAS installation and install it from scratch once again.
Thanks a lot.
You have standalone aka base edition of WebSphere Application Server. To create Deployment Manager you need Network Deployment edition.
Unfortunately you will have to install it from scratch from different installation files (from ND, not base or developers edition).

Does anybody have any advice regarding running PDFlib on a Windows Azure Worker Role?

We have a requirement for PDF generation on the fly in our .NET Azure application, and have determined that PDFLib best meets our requirements.
Basic deployment is dll based, and so should be relatively straightforward. While researching the issue, I came across a case-study covering installation of another, similar component (AbcPdf, here), and this led me to wonder if anybody had any similar detailed experience to share regarding getting PDFLib up and running on a cloud service?
Specifically, I'm interested in whether there are any files other than the referenced .dlls which have to be copied with the package, whether I need to install PDFLib to the GAC using a startup command, and if there are any issues getting licensing working in a cloud environment.
We could of course use a VM for this if required, but initially I am looking to use a standard worker role. I am going to ask PDFLib support this question and will share any answer I get here, as I haven't found this topic covered anywhere else on Stackoverflow.
This is what I got back from PDF Lib support, which I think covers everything:
Does the .NET PDFLib require GAC deployment, or can the dlls simply be
copied to the server?
you can simple deploy the pdflib_dotnet dll.
Are there any files other than the referenced dlls which need to be
deployed for PDFLib to work?
no, PDFlib do not have any further dependencies.
How can we authenticate our product license in an environment where we
may not be able to run an installer, and where we may not have access
to the windows registry?
there are multiple ways to to this. The most simple way is to apply the license key in the code. You can also apply a licensefile. Please get in mind, you need for each serve, where PDFlib run in production usage a separate license. For example, when you run the application in a cluster system with 4 nodes (servers), you need 4 licenses.
And, do you have any general guidance on cloud deployments such as this?
we do not have any special comments on this. But I'm sure, you will find a lot of relevant information about the concepts of our PDFlib .NET implementation in the "PDFlib in .NET Howto", which is included in the PDFlib 8 package, and also available on our website:
http://www.pdflib.com/en/developer/technical-documentation/pdflib-in-net-howto/
Let me start with I've not deployed this compment into Azure; however, what follows should be accurate for just about any component you have.
If you can just xcopy deploy this component to a regular server it should just work with a normal deployment package to a Cloud Service; however, if there is an install that is required when you distribute to normal servers (read, NOT your development machine), then you may have some extra steps here. For example, if the install pushes the assembly into the GAC, then you'd have to follow suit.
I'd simply test an xcopy deployment rollout to a regular on premises box that hasn't had an installation of this component before and see if it works. If it does, you're likely just fine to ensure it gets referenced and deployed with your package. If you are concerned that it may need other assemblies to go with it, use something like Reflector, Just Decompile or ILDasm to check out the references the assembly has (careful, using a decompiler on the assembly may be against your EULA).
I know you're asking for actual experience, but I'd say the answer is that this should just work. From http://www.pdflib.com/fileadmin/pdflib/pdf/support/PDFlib-in-.NET-HowTo.pdf:
A process called xcopy deployment is also supported. You can simply
copy the PDFlib assembly (pdflib_dotnet.dll) to the server using the
xcopy command or FTP transfer
I downloaded and PDFLib x64 version and a give a quick try with Windows Azure Web Role. The Library contains only one DLL as PDFlib_dotnet.dll which you can add as reference and set its property "Copy Local As True". After that you can just reference it in your code and use it based on documentation.
Based on my quick test, you really need to modify the code to use Windows Azure Local Storage to create your PDF files and the sync to Windows Azure Blob storage to persist it properly. There may be way to create the PDF directly to Azure Blob storage but I just did not look further.
I created an ASP.NET based webrole with the following code:
PDFlib p;
int font;
p = new PDFlib();
try
{
// This means we must check return values of load_font() etc.
p.set_parameter("errorpolicy", "return");
// Added code to create PDF on Local Storage
LocalResource myStorage = RoleEnvironment.GetLocalResource("myLocalStorage");
string filePath = Path.Combine(myStorage.RootPath, "hello.pdf");
if (p.begin_document(filePath, "") == -1)
{
Console.WriteLine("Error: {0}\n", p.get_errmsg());
return;
}
p.set_info("Creator", "hello.cs");
p.set_info("Author", "Rainer Schaaf");
p.set_info("Title", "Hello, world (.NET/C#)!");
p.begin_page_ext(595, 842, "");
font = p.load_font("Helvetica-Bold", "unicode", "");
if (font == -1)
{
Console.WriteLine("Error: {0}\n", p.get_errmsg());
return;
}
p.setfont(font, 24);
p.set_text_pos(50, 700);
p.show("Hello, world!");
p.continue_text("(says .NET/C#)");
p.end_page_ext("");
p.end_document("");
}
catch (PDFlibException eX)
{
// caught exception thrown by PDFlib
Console.WriteLine("PDFlib exception occurred in hello sample:\n");
Console.WriteLine("[{0}] {1}: {2}\n", eX.get_errnum(),
eX.get_apiname(), eX.get_errmsg());
}
finally
{
if (p != null)
{
p.Dispose();
}
}
}

Can't seem to load a managed dll from Installer during setup?

I'm developing an installer for an application which includes a Windows Service. The service will need a username/password from the user in order to get information from our server, so I'd like to set that during install. We also need to store that info in the Services config file so it has to be encrypted.
So I'd like the installer to call the same .dll the service uses when it encrypts the credentials. I set up custom actions created through the custom action wizard. I set it to "Call a public method in a managed assembly" and picked "Installed with the product" as the Location. I'm able to pick the dll and the target function and set everything up through the wizard. The path it resolves to in the installer log looks correct...
But I'm getting the error:
Unable to load managed custom action assembly
So not sure what to do in order to get this working?
The second part of the question is, what happens if the end user doesn't have .NET 4 installed? I'm going to set the installer to install it... but will there be problems or will we need to force a reboot partway through the install process? If so I might just temporarily store things unencrypted and have the service encrypt them when it first runs... which at this point is probably the easy way, but it doesn't feel like the "correct" way. ;)

How to publish MSHTHML.dll and SHDOCVW.dll to Azure

I have a 3rd party web page screen capture DLL from http://websitesscreenshot.com/ that lets me target a URL and save the page to a image file. I've moved this code into my Azure-based project and when I run it on my local sandboxed dev box and save to the Azure blob, everything is fine. But when I push the bits to my live server on Azure, it's failing.
I think this is because either MSHTML.dll and/or SHDOCVW.dll are missing from my Azure configuration.
How can I get these libraries (plus any dependent binaries) up to Azure?
I found the following advice on an MSFT forum but haven't tried it yet. http://social.msdn.microsoft.com/Forums/en-US/windowsazuredevelopment/thread/0344dcff-6fdd-4479-a3b4-3e89750a92f4/
Hello, I haven't tried mshtml in the cloud. But generally speaking, to
use a native dll in a Web Role, you add the dll to the Web Role
project just like adding a picture (choose add existing items). Then
make sure the Build Action is set to Content. This tells Visual Studio
to copy the dll file to the output package.
Also check dependencies carefully. A lot of problems related to native
code are caused by missing dependencies, such as a particular VC++
runtime dll.
Thought I'd ask here first before I burn a day or two on an unproven solution.
EDIT #1:
it turns out that our problem was not related to MSHTML.dll or SHDOCVW.dll missing from the Azure server. They're there.
The issue is that by default new server instance have the IE security hardening feature enabled, and this was preventing our 3rd party dll from executing script. So we needed to turn off the enhanced IE security configuration settings. This is also a non-trivial exercise.
In the meantime, we just created a server-side version of the feature on our site we need to make screen captures from (e.g. we eliminated JSON-based rendering of UI on the client), and we were able to proceed.
I think the solution mentioned in the MSDN forum thread is correct. You should put them as part of your project files, so that the SDK will package and deploy them to the VM on the cloud.
But if they are COM and need to be registed you'd better call the register command via the Startup feature. Please check http://msdn.microsoft.com/en-us/hh351539
HTH

Setup Project - Allow multiple installation of the same Windows Service

I have a question regarding to Setup Projects in .Net (c# language, Framework 4.0):
I made a setup project for a Windows Service, on the installation wizard, the user must input the name of the Windows Service as it would be installed. The setup program also creates a shortcut to the Uninstall program in case the user wants to remove that Windows Service.
The question is: how to let the user run the same setup program several times specifing different service name?
This behaviour could be required because the windows service is a socket consumer that connects to a server and retrieves data; to take advantage of the server capabilities the user could install the same windows service multiple times pointing to a different port on the server, to perform the data retrieving task much faster. The service is the same, the user just modify the port on the configuration file of the service, so that's why it's not logical to create a new version of the installer each time.
Any clue or suggestion would be appreciated, thanks in advance.
This can be done by using an multiple instances installation. The general approach is:
create a transform for each instance you want available to the user
use a custom EXE bootstrapper which applies a new transform to your MSI package each time a new instance is installed
The transform should change at least the PackageCode, ProductCode and UpgradeCode.
This is not supported by Visual Studio setup projects. So either you do it manually or use a commercial setup authoring tool which supports multiple instances.

Resources