1

I want to be able to install a windows service using installutil.exe and then run and stop/delete T.myService.exe automatically from innosetup script. I tried the below code

[Run]
Filename: "{dotnet40}\InstallUtil.exe"; WorkingDir: "{app}"; Parameters: "T.myService.exe" ; Flags: runhidden


[UninstallRun]
Filename: "{dotnet40}\InstallUtil.exe"; Parameters: "stop T.myService.exe" ; Flags: runhidden
Filename: "{dotnet40}\InstallUtil.exe"; Parameters: "delete T.myService.exe" ; Flags: runhidden

The above just shows my T.myService.exe in TaskManager/services.msc but the status is "stopped". They don't seem to run automatically. I will have to manually right click on T.myService.exe in task manager to make them run or with the below command in the command prompt

To install a service
<path>\InstallUtil.exe <path to T.myService.exe>

To uninstall a service
<path>\InstallUtil.exe /u <path to T.myService.exe>

But, I want the service to start running automatically once the install completes and when I uninstall all traces of T.myService.exe should be gone. With my innosetup code, it doesn't run and stop/delete automatically. I also enabled [UninstallDelete] to delete my T.myService.exe explicitly which removes all associated files from the app directory but the service is still seen in the task manager/services.msc which is a problem.

What am I missing? What should I be doing to run and stop/delete the service automatically?

jamilia
  • 359
  • 4
  • 14
  • So doesn't the `InstallUtil.exe` display any problem, when executed from Inno Setup, explaining why it is not able to start the service? – Martin Prikryl Oct 19 '17 at 09:41
  • Also it does not seem that [`InstallUtil`](https://learn.microsoft.com/en-us/dotnet/framework/tools/installutil-exe-installer-tool) has `stop` and `delete` keywords. – Martin Prikryl Oct 19 '17 at 09:44
  • When you run `InstallUtil.exe` from command-prompt - does it work even if the service is not installed (but not started) by Inno Setup upfront? + Do you use elevated command prompt for installation? – Martin Prikryl Oct 19 '17 at 09:45
  • When running from CMD prompt with the above cmd it looks for my service, when its not installed, my service isn't there yet so it doesn't work in that scenario. – jamilia Oct 19 '17 at 15:24
  • I also tried to use /u in place of stop and delete but that doesn't seem to work. I need to explicitly uninstall from CMD prompt for it to uninstall but that's not what I need. Why wouldn't this work? – jamilia Oct 19 '17 at 15:28
  • I'm completely lost. If I understand you, you claim that `InstallUtil.exe T.myService.exe`, when run from command prompt does not install the service, but when it is already installed, is starts it. But the same command when executed from Inno Setup does install the server, but does not run it. – Martin Prikryl Oct 19 '17 at 19:28
  • T.myService.exe is part of my application that I'm trying to install. So once my appln is installed, I want my T.myService.exe to run automatically for which I enabled [Run]&[UninstallRun]. So, using cmd prompt when I run the cmd, my T.myService.exe should already be installed else it will throw fileNotFoundRrror. I hope that makes it clear. I think we can ignore the cmd prompt thing if its confusing(tried that as an alternate) & focus only on to how to achieve this through innosetup. My worry is that t.myService.exe still appears in services.msc even after my application is uninstalled. – jamilia Oct 19 '17 at 22:06
  • OK, of course I assumed that the files are there ("installed" if you prefer to call it that way). We should not ignore the prompt, as that's important that it works (?) from the prompt. So again, if you have all files available (no matter how they got there, whether by installer or other), but you never run the `InstallUtil.exe` on them (from Inno Setup or any other way), if you run `InstallUtil.exe` from command prompt, what does it do? Does is create the service? Does it run the service? Is there any difference to running the same command from Inno Setup? – Martin Prikryl Oct 20 '17 at 05:49

2 Answers2

0
  1. Deploy "srvman.exe" to application directory along with your application.
    SRVMAN: http://tools.sysprogs.org/srvman/

  2. add uninstall action in innosetup script

    [UninstallRun]
    Filename: "{app}\srvman.exe"; Parameters: "delete YOUR_SERVICE_NAME"; 
    
Nitin Sawant
  • 7,278
  • 9
  • 52
  • 98
0

Instead of InstallUtil, use SC:

[Run]
Filename: "{app}\T.myService.exe"; Parameters: "-service"; StatusMsg: "Creating services"
Filename: "{sys}\sc.exe"; Parameters: "create ""myServiceName"" start= auto binPath= ""{app}\T.myService.exe"""; Flags: runhidden; StatusMsg: "Creating services"

[UninstallRun]
Filename: "{sys}\sc.exe"; Parameters: "stop ""myServiceName"""; Flags: runhidden; StatusMsg: "Stopping services"
Filename: "{sys}\sc.exe"; Parameters: "delete ""myServiceName"""; Flags: runhidden; StatusMsg: "Deleting services"

Do not forget to copy the T.myService.exe into {app} dir:

[Files]
Source: "T.myService.exe"; DestDir: "{app}";
Rob
  • 26,989
  • 16
  • 82
  • 98