473,387 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Restarting a Windows Service with C# under Vista when User Account Control is Enabled

Hello!

I need to restart the "Windows Audio Service" (audiosrv) via C#. I'm
using the ServiceController Class to do this.
It is no problem under XP and no problem under vista if UAC is
disabled.
But with enabled UAC i'm getting a "access refused" exception.
I also tried to do it via console with "net start ..." but the same
error appears.
Three questions:
1. Is it possible to restart the "windows audio service" if UAC is
enabled ?
2. Why does the exception occur? If I do some other stuff, e.g.
starting regedit via Process.Start() the user gets asked if he really
wants that. I would expect the same behaviour for restarting
services.
3. If it's not possible at all: Can I find out programmatically
whether UAC is enabled?

Thanks and excuse my bad english!

Apr 3 '07 #1
3 3974
"gourmet" <tr***@jos.zzn.comwrote in message
news:11*********************@o5g2000hsb.googlegrou ps.com...
Hello!

I need to restart the "Windows Audio Service" (audiosrv) via C#. I'm
using the ServiceController Class to do this.
It is no problem under XP and no problem under vista if UAC is
disabled.
But with enabled UAC i'm getting a "access refused" exception.
I also tried to do it via console with "net start ..." but the same
error appears.
Three questions:
1. Is it possible to restart the "windows audio service" if UAC is
enabled ?
Yes when running as full "Administrator". That is start the console (cmd interpreter) by
right clicking "Run as Administrator".
2. Why does the exception occur? If I do some other stuff, e.g.
starting regedit via Process.Start() the user gets asked if he really
wants that. I would expect the same behaviour for restarting
services.
The exception occurs because you are running as a standard user, only admins can start, stop
.... services.
If you want the same behavior you'll have to insert a "manifest" in your executable file.

<?xml version="1.0" encoding="utf-8" ?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0"
processorArchitecture="X86"
name="someExecName"
type="win32" />
<description>Program description</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

To add above manifest to the executable assembly, you have to run mt.exe like this;

mt -manifest somename.exe.manifest -outputresource:somename.exe;#1
PS change the someExecName and Program description to suit your needs...
3. If it's not possible at all: Can I find out programmatically
whether UAC is enabled?
See above.

Willy.

Apr 3 '07 #2
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:up**************@TK2MSFTNGP03.phx.gbl...
"gourmet" <tr***@jos.zzn.comwrote in message
news:11*********************@o5g2000hsb.googlegrou ps.com...
>Hello!

I need to restart the "Windows Audio Service" (audiosrv) via C#. I'm
using the ServiceController Class to do this.
It is no problem under XP and no problem under vista if UAC is
disabled.
But with enabled UAC i'm getting a "access refused" exception.
I also tried to do it via console with "net start ..." but the same
error appears.
Three questions:
1. Is it possible to restart the "windows audio service" if UAC is
enabled ?

Yes when running as full "Administrator". That is start the console (cmd interpreter) by
right clicking "Run as Administrator".
>2. Why does the exception occur? If I do some other stuff, e.g.
starting regedit via Process.Start() the user gets asked if he really
wants that. I would expect the same behaviour for restarting
services.
The exception occurs because you are running as a standard user, only admins can start,
stop ... services.
If you want the same behavior you'll have to insert a "manifest" in your executable file.

<?xml version="1.0" encoding="utf-8" ?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0"
processorArchitecture="X86"
name="someExecName"
type="win32" />
<description>Program description</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

To add above manifest to the executable assembly, you have to run mt.exe like this;

mt -manifest somename.exe.manifest -outputresource:somename.exe;#1
PS change the someExecName and Program description to suit your needs...
>3. If it's not possible at all: Can I find out programmatically
whether UAC is enabled?

See above.

Willy.

To further clarify:
save the above manifest in a file called "some.exe.manifest", where someApp is the name of
your executable file.
Say you have "audioCntrl.exe", then you could name your manifest audioCntrl.exe.manifest"
and run mt.exe like:

mt -manifest audioCntrl.exe.manifest -outputresource:audioCntrl.exe;#1

Willy.
PS. type mt /help from the command line for more detailed help on mt.
Apr 3 '07 #3
Thank you very much!

I will try that manifest stuff on friday and will let you know if it
worked for me...


Apr 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dean R. Henderson | last post by:
I have a DTS Package I am able to execute successfully from a Windows Form application, but I cannot get this to work from an ASP.NET Web Service, although the Web Service impersonates the same...
3
by: Saran | last post by:
I have a windows service which instantiates the Powerpoint Application using PIA. When I am running this windows service am not able to open the Microsoft powerpoint application. This problem...
27
by: pisquem | last post by:
I am building an windows service that is to be deployed on a windows server 2003 and I want to have activity written to the event log, I want its own log called ('CustomLog') Below is what I...
3
by: illegal.prime | last post by:
Hi all, I have a service that needs to start a regular windows application. I'm running the service as ServiceAccount.LocalSystem. But, when it starts the process (using Process.Start) the GUI...
5
by: sonali_reddy123 | last post by:
Hello all, I am trying to develop an application which will run as a windows service. The application should have Normal options available with service like start, stop and pause but along...
2
by: =?Utf-8?B?am1hZ2FyYW0=?= | last post by:
I'm trying to get a list of user accounts on the local computer - the same list you see when you are about to log in to Windows XP or Vista. This needs to work on a home computer (not connected to...
5
by: ink | last post by:
Hi all, I cant seem to debug my windows service on my Vista machine. It seems it has something to do with 0 Session. What I would normally do is add the following code to my OnStart() but it...
5
by: DotNetDanny | last post by:
Hello Machine: Windows Vista Business, standalone machine (no domain). Installed an old classic ASP webapplication in IIS7, running under a new app.pool with 'NETWORK SERVICE' account (using...
5
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name?...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.