Solved

Start windows service from vb net

Posted on 2012-03-24
2
451 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

751 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