Solved

Start windows service from vb net

Posted on 2012-03-24
2
444 Views
Last Modified: 2012-06-21
I've installed a windows service in a windows 2003 server. It start manually succesfully but if I run it from another application return an error.
The running code is this:
Dim myController As ServiceController
myController = New ServiceController("WinSUpdateProdDate")
If Not myController.Status = ServiceControllerStatus.Running Then myController.Start()

...returned error is (in italian debug...)
? ex.Message
"Impossibile avviare il servizio WinSUpdateProdDate sul computer '.'."
? ex.InnerException.ToString
"System.ComponentModel.Win32Exception (0x80004005): Accesso negato"

In connection properties of the service default option is selected: local user account.
What can I do to solve?
0
Comment
Question by:fantamen
2 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 500 total points
Comment Utility
There are two ways you can fix this.  You can elevate the privileges of the code calling the servicecontroller, or you can give rights to the user to manage the service.

Method 1 will bring up a User Access Control prompt.  Method 2 should be transparent.

Method 1, either run program as administrator (right click and "run as"--should bring up the UAC prompt)  or add a manifest with the elevation request, which will cause the UAC prompt on start up.

To add a manifest, open project properties and click "View Windows Settings"  in VS2010 or add "Application Manifest File" to your project in VS2008.  

change  <requestedExecutionLevel level="asInvoker" uiAccess="false" /> to
 <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

Explanation of this file here:
Step 6: Create and Embed an Application Manifest (UAC)
http://msdn.microsoft.com/en-us/library/bb756929.aspx


Method 2
I've never done this, but I believe this would be the best way.  Sounds like it's a little tricky:
Set permissions on a specific service (Windows)
https://msmvps.com/blogs/erikr/archive/2007/09/26/set-permissions-on-a-specific-service-windows.aspx
0
 

Author Comment

by:fantamen
Comment Utility
Your indications are very useful. Thank you.
I've tried both. Onestly method two is not very clear. First is more simple.
Starting application UAC message ask for confirmation and I can't change UAC level.
Searching on the internet I've found this utility: subinacl.exe (component of Resource Kit) You can download from Microsoft web site.
I've changed permission for the service using this command:
SUBINACL /SERVICE <service name> /GRANT=<user name>=TO
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now