Real Geek Forums  

Go Back   Real Geek Forums > Archives > Operating Systems > Windows Vista > Windows Vista Security

Notices

Reply

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

 

LinkBack Thread Tools Display Modes
Old 04-03-2007, 11:29 AM   #1 (permalink)
Default 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!

gourmet
Guest
 
Posts: n/a
Reply With Quote  
Old 04-03-2007, 02:40 PM   #2 (permalink)
Default Re: Restarting a Windows Service with C# under Vista when User Account Control is Enabled

"gourmet" <trash@jos.zzn.com> wrote in message
news:1175599768.389379.13120@o5g2000hsb.googlegrou ps.com...
Quote:
> 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".
Quote:
> 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...
Quote:
> 3. If it's not possible at all: Can I find out programmatically
> whether UAC is enabled?
See above.

Willy.

Willy Denoyette [MVP]
Guest
 
Posts: n/a
Reply With Quote  
Old 04-03-2007, 02:53 PM   #3 (permalink)
Default Re: Restarting a Windows Service with C# under Vista when User Account Control is Enabled

"Willy Denoyette [MVP]" <willy.denoyette@telenet.be> wrote in message
news:up02U4fdHHA.1216@TK2MSFTNGP03.phx.gbl...
Quote:
> "gourmet" <trash@jos.zzn.com> wrote in message
> news:1175599768.389379.13120@o5g2000hsb.googlegrou ps.com...
Quote:
>> 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".
>
Quote:
>> 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...
>
Quote:
>> 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.


Willy Denoyette [MVP]
Guest
 
Posts: n/a
Reply With Quote  
Old 04-04-2007, 09:52 AM   #4 (permalink)
Default Re: Restarting a Windows Service with C# under Vista when User Account Control is Enabled

Thank you very much!

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




gourmet
Guest
 
Posts: n/a
Reply With Quote  
Reply

Tags
None

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
user account control Ed43 Windows Vista Networking & Sharing 5 01-02-2008 12:44 AM
When User Account Control is enabled, Vista Games Explorer won't s griz_fan Windows Vista Games 0 06-18-2007 01:00 PM
Which rights does a user need to control an windows service? Olcay Windows Vista Security 2 03-23-2007 02:23 PM
Vista User Account Control Magnus Flysjö Windows Vista Security 1 02-02-2007 02:47 PM
user account does not appear in the user accounts control panel Frank Windows XP Security & Administration 0 07-25-2003 02:35 AM


All times are GMT. The time now is 10:26 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright © 2005 - 2007 RealGeek.com. All rights reserved.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90