A Windows Vista forum. Vista Banter

Welcome to Vista Banter.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to ask questions and reply to others posts, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

Go Back   Home » Vista Banter forum » Microsoft Windows Vista » Security and Windows Vista
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Security and Windows Vista A forum for discussion on security issues with Windows Vista. (microsoft.public.windows.vista.security)

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



 
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old April 3rd 07, 11:29 AM posted to microsoft.public.windows.vista.security,microsoft.public.dotnet.languages.csharp
gourmet
external usenet poster
 
Posts: 2
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!

  #2 (permalink)  
Old April 3rd 07, 02:40 PM posted to microsoft.public.windows.vista.security,microsoft.public.dotnet.languages.csharp
Willy Denoyette [MVP]
external usenet poster
 
Posts: 2
Default Restarting a Windows Service with C# under Vista when User Account Control is Enabled

"gourmet" wrote in message
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" /
descriptionProgram 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.

  #3 (permalink)  
Old April 3rd 07, 02:53 PM posted to microsoft.public.windows.vista.security,microsoft.public.dotnet.languages.csharp
Willy Denoyette [MVP]
external usenet poster
 
Posts: 2
Default Restarting a Windows Service with C# under Vista when User Account Control is Enabled

"Willy Denoyette [MVP]" wrote in message
...
"gourmet" wrote in message
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" /
descriptionProgram 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.


  #4 (permalink)  
Old April 4th 07, 09:52 AM posted to microsoft.public.windows.vista.security,microsoft.public.dotnet.languages.csharp
gourmet
external usenet poster
 
Posts: 2
Default 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...




 




Thread Tools
Display Modes

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

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



All times are GMT. The time now is 09:00 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.Search Engine Optimization by vBSEO 3.0.0 RC6
Copyright ©2004-2024 Vista Banter.
The comments are property of their posters.