This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- Re: Start Service after install
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 06, 2008
04:19 PM
Start Service after install
Hi,
I am working on a Basic MSI project. I need to start one of the windows services that get installled during my setup, to start running after the installation completed.
I use the following code in my custom action which is after InstallFinalize in the Execute sequence, but my service does not start running. This is the code:
I am not sure what is wrong here! Can somone please help with this?
Thanks
I am working on a Basic MSI project. I need to start one of the windows services that get installled during my setup, to start running after the installation completed.
I use the following code in my custom action which is after InstallFinalize in the Execute sequence, but my service does not start running. This is the code:
Dim sCmdLine
Dim Shell
set shell = CreateObject("WScript.Shell")
sCmdLine = "NET START MyService"
shell.Run sCmdLine, 1, True
I am not sure what is wrong here! Can somone please help with this?
Thanks
(16) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 07, 2008
07:42 AM
Can you use the MSI control-service functionality?
If not, perhaps change your action to run net.exe directly, instead of adding the VBScript layer?
If not, perhaps change your action to run net.exe directly, instead of adding the VBScript layer?
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 07, 2008
12:48 PM
RobertDickau wrote:
Can you use the MSI control-service functionality?
If not, perhaps change your action to run net.exe directly, instead of adding the VBScript layer?
Thanks for the reply. I have tried Control NT Services and Install NT Services. I don't have problems installing. But I cannot make starting the service work.
I also tried to copy the 'net.exe' from windows directory to my INSTALLDIR and then have CA to run it to start MyService...it didn't work either.
There should be an easy to this, I just don't know what I am doing wrong:confused: Please help!
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 07, 2008
01:19 PM
Have you tried running the VBscript manually to see what it is doing or what the output is. You might need to include the path to NET like so.
If this does not work try creating a batch file "StartMyService.bat" that you can execute after the installation.
Dim sCmdLine
Dim Shell
set shell = CreateObject("WScript.Shell")
sCmdLine = "C:\WINDOWS\system32\NET.exe START MyService"
shell.Run sCmdLine, 1, True
If this does not work try creating a batch file "StartMyService.bat" that you can execute after the installation.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 07, 2008
01:39 PM
(As a big aside, it's generally better to avoid VBScript custom actions that touch the target system, esp. since spyware scanners and such often stop VBScript code from running.
It's also generally better to avoid custom actions to duplicate built-in MSI functionality, since built-in functionality handles rollback and so forth. In what way is the Control NT Service functionality not working?)
It's also generally better to avoid custom actions to duplicate built-in MSI functionality, since built-in functionality handles rollback and so forth. In what way is the Control NT Service functionality not working?)
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 07, 2008
02:00 PM
Here is a question, can you use "ServiceStartService" in a MSI project? I know you can use it in an Install Shield Script project without any problems.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 07, 2008
02:22 PM
jchristman wrote:
Have you tried running the VBscript manually to see what it is doing or what the output is. You might need to include the path to NET like so.
Dim sCmdLine
Dim Shell
set shell = CreateObject("WScript.Shell")
sCmdLine = "C:\WINDOWS\system32\NET.exe START MyService"
shell.Run sCmdLine, 1, True
If this does not work try creating a batch file "StartMyService.bat" that you can execute after the installation.
Thanks for the reply. The Script works from outside the MSI. Also I tried to include the whole path to NET..again works from outside the MSI but not within.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 07, 2008
02:24 PM
Yes, you can. However, I think your time would be better served getting the Built-IN MSI ServiceControl pattern. It's simpler and more reliable. The only times you should need a custom action ( in any language ) to start a service is situations where the service has a start dependency that's not yet available ( for example, a DLL in the GAC that isn't published until the commit phase ).
Associate a Service Control action to a component that is being installed, join it to the service using the `internal` service name ( like w3svc ) and set the action flags for what makes sense to you. ( uninstall: stop, install: stop,start ).
Associate a Service Control action to a component that is being installed, join it to the service using the `internal` service name ( like w3svc ) and set the action flags for what makes sense to you. ( uninstall: stop, install: stop,start ).
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 07, 2008
02:25 PM
RobertDickau wrote:
(As a big aside, it's generally better to avoid VBScript custom actions that touch the target system, esp. since spyware scanners and such often stop VBScript code from running.
It's also generally better to avoid custom actions to duplicate built-in MSI functionality, since built-in functionality handles rollback and so forth. In what way is the Control NT Service functionality not working?)
Thanks a lot Robert for the interesting hints. My problem with using Control NT AService is that I get the following error:
Error 1920: Service MyService(MyService) failed to start. Verufy that you have sufficient privileges to start system services.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 07, 2008
02:26 PM
TheTraveler wrote:
Here is a question, can you use "ServiceStartService" in a MSI project? I know you can use it in an Install Shield Script project without any problems.
I am not sure about that!
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 07, 2008
02:30 PM
Are you requiring the user to be an administrator.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 07, 2008
02:31 PM
Hello,
I think I know why it doesn't work within the MSI project. You see, when you run it in a batch file, it uses the system enviroment to run the commands you are issuing. Try this,
You might have to play around with it, but this might work. You see, when you run cmd, it loads in the OS's environment and allows you to run the command of your choice in that environment when you use the "/c" parameter. I hope this helps.
I think I know why it doesn't work within the MSI project. You see, when you run it in a batch file, it uses the system enviroment to run the commands you are issuing. Try this,
"WINSYSDIR\cmd.exe" /c "C:\WINDOWS\system32\NET.exe" START MyService
You might have to play around with it, but this might work. You see, when you run cmd, it loads in the OS's environment and allows you to run the command of your choice in that environment when you use the "/c" parameter. I hope this helps.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 07, 2008
02:32 PM
I need a lot more information to troubleshoot that one:
What OS are you installing on?
If Vista:
Are you using setup.exe? What's it's Required Execution Level set to?
What is the Summary Information Stream Require Admin Priv set to?
For ALL OS:
What account are you installing as?
Is that account a member of the Local Administrators group?
Are you doing a Per-User or Per-Machine Install?
What service are you starting?
What account does the service use to run?
What OS are you installing on?
If Vista:
Are you using setup.exe? What's it's Required Execution Level set to?
What is the Summary Information Stream Require Admin Priv set to?
For ALL OS:
What account are you installing as?
Is that account a member of the Local Administrators group?
Are you doing a Per-User or Per-Machine Install?
What service are you starting?
What account does the service use to run?
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 07, 2008
02:49 PM
Here give this a try i have used it a couple of times with a few minor changes, it is not mine I got off the net from www.activexperts.com
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name='NetDDE'")
For each objService in colServiceList
errReturn = objService.StartService()
Next
Wscript.Sleep 20000
Set colServiceList = objWMIService.ExecQuery("Associators of " _
& "{Win32_Service.Name='NetDDE'} Where " _
& "AssocClass=Win32_DependentService " & "Role=Dependent" )
For each objService in colServiceList
objService.StartService()
Next
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 07, 2008
04:01 PM
I prefer this simpler, reliable and elegant solution. If for some reason there is an absolutely valid reason that MSI can't natively handle your particular scenario, the InstallScript ServiceStartService() function is much cleaner and less fragile method of starting the service without putting dependencies on ActiveScript and WMI ( which often fail ).
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 07, 2008
05:18 PM
Thank you everybody for your hints ans supports. I was truely amazed by all the replys that I got on this post. Thank you so very much.
I was finally able to start the service after the install and stop & delete it on uninstall using 'Control NT Services'. It works like a charm on both Win 2003 and Win 2008 servers. I guess the way I was using it before was not proper (I was using 'Install NT Services' and 'Control NT Services' withing the same component and that was I guess why I was getting error. After I separated these two, my service installs and runs fine).
At this point I don't know how to uninstall and reinstall the service during 'Maintenance' or 'Patch'. I've seen that people duplicate the Installutil.exe from windows to their project and use a CA to run it to uninstall their service during the maintennace. I do not want to use the same strategy...what do you think is the best way to do this?
I welcome all your ideas.
Thanks again.
I was finally able to start the service after the install and stop & delete it on uninstall using 'Control NT Services'. It works like a charm on both Win 2003 and Win 2008 servers. I guess the way I was using it before was not proper (I was using 'Install NT Services' and 'Control NT Services' withing the same component and that was I guess why I was getting error. After I separated these two, my service installs and runs fine).
At this point I don't know how to uninstall and reinstall the service during 'Maintenance' or 'Patch'. I've seen that people duplicate the Installutil.exe from windows to their project and use a CA to run it to uninstall their service during the maintennace. I do not want to use the same strategy...what do you think is the best way to do this?
I welcome all your ideas.
Thanks again.
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎May 07, 2008
08:08 PM
Correct, from a Windows Installer perspective, the ServiceController class invoked by InstallUtil is an antipattern. See: http://blog.deploymentengineering.com/2006/07/msi-vs-net.html
If you look at the picture in the post above... keep in mind that `Install` and `Uninstall` is a bit of a misnomer. It's not equivilant to `Not Installed` and `REMOVE=ALL`, it's equivilant the the component action state that it's associated to ( &Component=3 or &Component=2 ). So from that perspective, you probably want to use the Install Delete and Install Stop attributes since in a patch/upgrade scenario the component is being reinstalled and the existing service will possibly need to be stopped and be deleted then recreated and restarted.
If you look at the picture in the post above... keep in mind that `Install` and `Uninstall` is a bit of a misnomer. It's not equivilant to `Not Installed` and `REMOVE=ALL`, it's equivilant the the component action state that it's associated to ( &Component=3 or &Component=2 ). So from that perspective, you probably want to use the Install Delete and Install Stop attributes since in a patch/upgrade scenario the component is being reinstalled and the existing service will possibly need to be stopped and be deleted then recreated and restarted.