Solved

Start windows service from vb net

Posted on 2012-03-24
2
448 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
ID: 37761091
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
ID: 37761254
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 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