Solved

Start windows service from vb net

Posted on 2012-03-24
2
449 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
No Data for DropDown List 2 32
Help with opening combobox using VB.NET. 3 34
Code enhancement 4 32
VB.net Excel VSTO Add-in version compatability 2 13
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

713 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