|
Next: Registering REG Files
|
| Author |
Message |
External

Since: Apr 03, 2007 Posts: 2
|
(Msg. 1) Posted: Tue Apr 03, 2007 4:29 am
Post subject: Restarting a Windows Service with C# under Vista when User Account Control is Enabled Archived from groups: microsoft>public>windows>vista>security, others (more info?)
|
|
|
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! |
|
| Back to top |
|
 |  |
External

Since: Apr 03, 2007 Posts: 2
|
(Msg. 2) Posted: Tue Apr 03, 2007 4:40 pm
Post subject: Re: Restarting a Windows Service with C# under Vista when User Account Control is Enabled [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
"gourmet" <trash.RemoveThis@jos.zzn.com> wrote in message
news:1175599768.389379.13120@o5g2000hsb.googlegroups.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. |
|
| Back to top |
|
 |  |
External

Since: Apr 03, 2007 Posts: 2
|
(Msg. 3) Posted: Tue Apr 03, 2007 4:53 pm
Post subject: Re: Restarting a Windows Service with C# under Vista when User Account Control is Enabled [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
"Willy Denoyette [MVP]" <willy.denoyette DeleteThis @telenet.be> wrote in message
news:up02U4fdHHA.1216@TK2MSFTNGP03.phx.gbl...
> "gourmet" <trash DeleteThis @jos.zzn.com> wrote in message
> news:1175599768.389379.13120@o5g2000hsb.googlegroups.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. |
|
| Back to top |
|
 |  |
External

Since: Apr 03, 2007 Posts: 2
|
(Msg. 4) Posted: Wed Apr 04, 2007 2:52 am
Post subject: Re: Restarting a Windows Service with C# under Vista when User Account Control is Enabled [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Thank you very much!
I will try that manifest stuff on friday and will let you know if it
worked for me... |
|
| Back to top |
|
 |  |
| Related Topics: | How to get the user name of a process when Vista UAC open? - I can get the user name of a process in Windows XP by following code: GetCurrentProcess(); GetSecurityInfo(handle,SE_KERNEL_OBJECT,OWNER_SECURITY_INFORMATION,&pSidOwner,NULL,NULL,NULL,&pSD);LookupAccountSid(NULL, pSidOwner,..
Vista no enabled user in administrators group?? - I was trying to help someone resolve a problem on their newer Dell computer today with Vista Home Premium installed. The user was having problems with Peachtree and up to a short time everything worked fine. The computer still works well as long as th...
how to activate windows vista business - Hi. I had just installed windows vista business and I can't activate the firewall. The computer is configured in a domain, but I'm the administrator of the domain. Regards, Marco
How to save a file in Vista's Windows Folder - I have Excel VB code that saves a tiny ini file in the Windows Directory. Worked a treat on XP for years. It won't run on Vista because of the security permissions for the Windows folder. I can work around it for new files but all the hundreds of existin...
A thought on improving Vista security. - Hello everyone, I have an idea that I think would really help improve Vista security. At the same time, it would make Vista run faster and take up less space, and it would make things more difficult for malicious hackers. Could someone tell me the.... |
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|