M
muradjames
I have a service running on my PC. I want to set the service's PriorityClass
to BelowNormal. I use the following code:
Process process = GetServiceProcess();
// How can I get the user's token (Local System) from the
process, or wherever?
using (WindowsImpersonationContext user =
WindowsIdentity.Impersonate(userToken))
{
process.PriorityClass = Settings.Default.servicePriority;
}
Clearly, this cannot work - I need the userToken.
So, my questions are:
1) Is this the correct approach? I am assuming that the "access denied" is
caused by the fact that my application is running as one user, and the
service is running as local system so I cannot change it? My approach is to
impersonate the local system user while I change the priority class.
2) If this is correct, how can I get the user token *of the service* (i.e.
the Local System token) so that I can impersonate it?
I am using .Net 3.5, by the way...any help gratefully accepted!!!
to BelowNormal. I use the following code:
Process process = GetServiceProcess();
// How can I get the user's token (Local System) from the
process, or wherever?
using (WindowsImpersonationContext user =
WindowsIdentity.Impersonate(userToken))
{
process.PriorityClass = Settings.Default.servicePriority;
}
Clearly, this cannot work - I need the userToken.
So, my questions are:
1) Is this the correct approach? I am assuming that the "access denied" is
caused by the fact that my application is running as one user, and the
service is running as local system so I cannot change it? My approach is to
impersonate the local system user while I change the priority class.
2) If this is correct, how can I get the user token *of the service* (i.e.
the Local System token) so that I can impersonate it?
I am using .Net 3.5, by the way...any help gratefully accepted!!!