Search This Blog

Thursday, November 20, 2014

Creating and installing Windows Service in a development enviroment.

I hadn't worked on a Windows Service in 4 years so I forgot some of the fun necessary to create a new Windows Service.

Useful References
SC.exe - http://technet.microsoft.com/en-us/library/cc754599.aspx

Using SC.exe 

Settings Description for Service:


Steps to create a new Windows service
(Using Windows 7 Pro and Visual Studio 2013 Ultimate)

  • Add new project to solution
  • Select C# Windows, Windows Service template
  • Name project SoftwareUpdaterService and create.
      Note: VS 2013 template creates the necessary service base code to be a functional service:

     public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
        }

        protected override void OnStop()
        {
        }

   

  •  Build project and confirmed ..\SoftwareUpdaterService\bin\Debug\ SoftwareUpdaterService.exe
  • (I forgot this step) use SC to install the service
  • Open VS 2013 command prompt, switch to  bin\debug folder
  • Run this command:
SC create MergeSoftwareUpdater displayname= "Merge Healthcare Software Updater Service" binpath= "C:\CAP30\Tools\Software Updater Service\SoftwareUpdater\SoftwareUpdaterService\bin\Debug\SoftwareUpdaterService.exe" start= auto


  Creates registry entry for service:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services

MergeSoftwareUpdater <= service key.


  • Open Services manager and service should appear.
  • Added Installer class to service project (lifted it from an existing project)
  • Now InstallUtil.exe will install the project as a service.
     InstallUtil.exe SoftwareUpdaterService.exe
(Added) using System.Net;
              using System.ServiceProcess;
        private void InitializeComponent()
        {
            this.serviceProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
            this.serviceInstaller = new System.ServiceProcess.ServiceInstaller();
            // 
            // deliveryServiceProcessInstaller
            // 
            this.serviceProcessInstaller.Password = null;
            this.serviceProcessInstaller.Username = null;
            // 
            // deliveryServiceInstaller
            // 
            this.serviceInstaller.ServiceName = "Merge Healthcare Software Updater Service";
            this.serviceInstaller.Description = "Allows software updates to be scheduled and run automatically.";
            this.serviceInstaller.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
            // 
            // ProjectInstaller
            // 
            this.Installers.AddRange(new System.Configuration.Install.Installer[] {
                                                                                      this.serviceProcessInstaller,
                                                                                      this.serviceInstaller});
        }

        public override void Install(IDictionary stateSaver) 
        {                    
            if (Context.Parameters["user"] != null && Context.Parameters["user"].Length != 0 && Context.Parameters["password"].Length != 0 && Context.Parameters["password"] != null) 
            {
                string user = Context.Parameters["user"];
                // if the user starts with . then we want to replace that with the local machine's actual hostname
                if (user.StartsWith(".")) 
                {
                    user = Dns.GetHostName() + user.Substring(1, user.Length - 1);
                }
                serviceProcessInstaller.Username = user;
                serviceProcessInstaller.Password = Context.Parameters["password"];
                serviceProcessInstaller.Account = ServiceAccount.User;
            } 
            else 
            {
                serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
            }
            
            base.Install(stateSaver);
        }




Saturday, November 15, 2014

File sharing rant

Recently, I solved file sharing dilemma for (DRC 3.0)
I started a write up that included a short review/rant of file sharing which I am re-posting here.

  • DropBox - Limits free shares to a daily download limit.  Very poor security from the get go and I am still not convinced they have solved all of their security woes.  I would never use DropBox for any extremely important. 
  • OneDrive (SkyDrive); Microsoft has really grown this product well except they seem to want to exclude normal application developers from using these shares. Size limits, poorly published API which is only convenient for mobile device developers.  It has a very cool integration for Windows 8+ which I make good use of but it makes a very poor direct download file share.
  • Google Drive: Google also provides a decent online file share.  Microsoft has caught up and passed Google though.  Typical Google launch a really good idea then cut back the development staff supporting it unless it is essential to this quarter's earnings.  Google needs a new mission statement... Don't be evil was a good start (although they have strayed from this). Better mission would be support what you create and people actually use and don't be stupid.  iGoogle, Blogger, Web Search API are just 3 things that jump mind.  Google Drive makes it difficult to do direct downloads.
  • NetGear - The fine people that brings us the routers, DSL and cable modems most of us use. Even they have a file sharing solution.  Problem here is using the latest router, I can't share using SSL because THESE GENIUSES WON'T FIX THE ROOT CERTIFICATE ISSUES WITH MYNETGEAR.COM.  Very cool USB device shares would be a very cool way of sharing files on the down-low only works with https but I could not get a proper certificate through NetGear.  Not sure what the issue: just stupid (don't discount this just look into you uPnP feature on your router; btw  DO NOT USE UPNP  the feature) or unwilling to provider the correct solution.  Either I use Netgear, I do not trust netgear.