Solved

Start windows service from vb net

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

773 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