Re: Publishing a service

34256 views
Skip to first unread message
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Shaul

unread,
Dec 29, 2010, 9:41:17 AM12/29/10
to
Hi Marc,

I just tried this code, and it executes without any errors - but I don't see the service now in my Services window.
What could be the problem?

Thanks for all your help!
Shaul

On Tuesday, September 9, 2008 9:39:57 AM UTC+3, Marc Gravell wrote:
> You can deploy a service with an msi if you want. Personally, I find
> the simplest mechanism (for my needs) is to make the service self-
> installing through command-line switches (i.e. "-i" to install, "-u"
> to uninstall). I also tend to add a "-c" console mode (which runs the
> main code without bothering with the service layer) - this makes it
> easy to debug etc; or with no switches present it just runs the
> service like normal.
>
> You can use the regular installer code in your main code (as long as
> you run it as an admin), by adding code like below.
>
> Marc
>
> [RunInstaller(true)]
> public sealed class MyServiceInstallerProcess :
> ServiceProcessInstaller
> {
> public MyServiceInstallerProcess()
> {
> this.Account = ServiceAccount.NetworkService;
> }
> }
> [RunInstaller(true)]
> public sealed class MyServiceInstaller : ServiceInstaller
> {
> public MyServiceInstaller()
> {
> this.Description = "Service Description";
> this.DisplayName = "Service Name";
> this.ServiceName = "ServiceName";
> this.StartType =
> System.ServiceProcess.ServiceStartMode.Automatic;
> }
> }
>
> static void Install(bool undo, string[] args)
> {
> try
> {
> Console.WriteLine(undo ? "uninstalling" :
> "installing");
> using (AssemblyInstaller inst = new
> AssemblyInstaller(typeof(Program).Assembly, args))
> {
> IDictionary state = new Hashtable();
> inst.UseNewContext = true;
> try
> {
> if (undo)
> {
> inst.Uninstall(state);
> }
> else
> {
> inst.Install(state);
> inst.Commit(state);
> }
> }
> catch
> {
> try
> {
> inst.Rollback(state);
> }
> catch { }
> throw;
> }
> }
> }
> catch (Exception ex)
> {
> Console.Error.WriteLine(ex.Message);
> }
> }
> }

Shaul

unread,
Dec 29, 2010, 9:55:44 AM12/29/10
to
Oh, never mind, I worked it out - I had the installer processes in the wrong assembly... <blush>

loki.l...@gmail.com

unread,
Mar 23, 2013, 11:29:50 AM3/23/13
to
On Tuesday, September 9, 2008 1:56:25 PM UTC+5:30, Marc Gravell wrote:
> Re installutil - I don't use it ;-p The service literally installs
> itself as though it were an msi.
>
> > Just one more question. When you say
> > you run the service like normal - do
> > you mean you run it as an application
> > or do you start it somehow?
>
> Maybe this'll make it clear... note StartUp and ShutDown are my start/
> stop code - i.e. all my service does in OnStart is call StartUp,
> etc...
>
> Marc
>
> static int Main(string[] args)
> {
> bool install = false, uninstall = false, console = false,
> rethrow = false;
> try
> {
> foreach (string arg in args)
> {
> switch (arg)
> {
> case "-i":
> case "-install":
> install = true; break;
> case "-u":
> case "-uninstall":
> uninstall = true; break;
> case "-c":
> case "-console":
> console = true; break;
> default:
> Console.Error.WriteLine("Argument not
> expected: " + arg);
> break;
> }
> }
>
> if (uninstall)
> {
> Install(true, args);
> }
> if (install)
> {
> Install(false, args);
> }
> if (console)
> {
> Console.WriteLine("Starting...");
> StartUp();
> Console.WriteLine("System running; press any key
> to stop");
> Console.ReadKey(true);
> ShutDown();
> Console.WriteLine("System stopped");
> }
> else if (!(install || uninstall))
> {
> rethrow = true; // so that windows sees error...
> ServiceBase[] services = { new WinService() };
> ServiceBase.Run(services);
> rethrow = false;
> }
> return 0;
> }
> catch (Exception ex)
> {
> if (rethrow) throw;
> Console.Error.WriteLine(ex.Message);
> return -1;
> }
> }

Hi Marc,
I followed your steps, but i don't know from where you are calling Install function, its declared like bool type,If you have Install function, what it contains? can i get that code? and also where i need to pass args values. I want to achieve this task using innosetup? how to achieve this task? can i get any sample??
"Using INNO setup i want to install WCF service into window service and it should start manually, can i get any sample for inno setup and steps for achieving it??

Regards,
Lokesh.J

ryan....@panesofglass.org

unread,
Jan 29, 2014, 7:03:16 PM1/29/14
to
I just found this through one of your SO answers. However, I'm missing something. Has this changed as of Windows Server 2008 R2? When I try to apply what you suggest, I get the "Windows Service Start Failure" that claims, "Cannot start service from the command line or debugger. ..."

Regards,
Ryan Riley

ibnemuh...@gmail.com

unread,
Mar 31, 2015, 8:03:39 AM3/31/15
to
On Tuesday, September 9, 2008 at 11:27:23 AM UTC+5, K Viltersten wrote:
> I published the software i've designed but
> it seems that since it's designed as a
> service, i'm not able to use the usual
> publishing tools in VS05.
>
> When i try to install the software, it
> says i need to run installutil.exe by hand
> and i'd like the installer to do that for
> me.
>
> If that's not possible (for some strange
> reason) - i'd like to get suggestions on
> how to deploy a service well, i.e. how to
> guarantee that all the needed files are
> there. The method i use now is trial and
> error, mostly error, which is painfully
> time consuming.
>
> --
> Regards
> Konrad Viltersten
> ----------------------------------------
> May all spammers die an agonizing death;
> have no burial places; their souls be
> chased by demons in Gehenna from one room
> to another for all eternity and beyond.

Amaizing Sir its amazing.
Reply all
Reply to author
Forward
0 new messages