I have a C# program that relies on a service (let's call it myService.exe).
So I wrote a routine that makes sure the service is running:

int iProcessID = IsProcessRunning("myService.exe");
Process myProcess = Process.GetProcessById(iProcessID);

These commands work great (I can post the IsProcessRunning() code if
necessary, but since that's not the issue I thought I'd leave it out).
Here's where the code fails: I check to make sure the process is alive using
this code

while(!bShutdown)
{
myProcess.WaitForExit(500);
if(myProcess.HasExited)
{
break;
}
else
{
// Periodic functions go here...
}
}

On Windows XP the code works great. On Windows Vista the .HasExited property
causes an Access Denied error. I'm sure it has something to do with
permissions, but I haven't figured it out yet. Can anyone help?

Thanks,
John

Re: HasExited() generates an Access Denied error by Josip

Josip
Fri May 02 15:32:22 CDT 2008

To control whether service is running or not, you may want to try

System.ServiceProcess.ServiceController sc =
new System.ServiceProcess.ServiceController("MYSERVICE");
if (sc.Status == System.ServiceProcess.ServiceControllerStatus.Running) {
...

--
Josip Medved


"John" <goondoo27@hotmail.com> wrote in message
news:%23H$tIp8qIHA.5068@TK2MSFTNGP02.phx.gbl..
>I have a C# program that relies on a service (let's call it myService.exe).
>So I wrote a routine that makes sure the service is running:
>
> int iProcessID = IsProcessRunning("myService.exe");
> Process myProcess = Process.GetProcessById(iProcessID);
>
> These commands work great (I can post the IsProcessRunning() code if
> necessary, but since that's not the issue I thought I'd leave it out).
> Here's where the code fails: I check to make sure the process is alive
> using this code
>
> while(!bShutdown)
> {
> myProcess.WaitForExit(500);
> if(myProcess.HasExited)
> {
> break;
> }
> else
> {
> // Periodic functions go here...
> }
> }
>
> On Windows XP the code works great. On Windows Vista the .HasExited
> property causes an Access Denied error. I'm sure it has something to do
> with permissions, but I haven't figured it out yet. Can anyone help?
>
> Thanks,
> John
>
>


Re: HasExited() generates an Access Denied error by John

John
Sat May 03 18:19:38 CDT 2008

Josip,

Thanks for the quick reply! I tried it and it works great. I can't thank you
enough for showing me the right path.

John

"Josip Medved" <jmedved@jmedved.com> wrote in message
news:E8683D80-F9C6-4781-AC43-85220A59FCFD@microsoft.com...
> To control whether service is running or not, you may want to try
>
> System.ServiceProcess.ServiceController sc =
> new System.ServiceProcess.ServiceController("MYSERVICE");
> if (sc.Status == System.ServiceProcess.ServiceControllerStatus.Running) {
> ...
>
> --
> Josip Medved
>
>
> "John" <goondoo27@hotmail.com> wrote in message
> news:%23H$tIp8qIHA.5068@TK2MSFTNGP02.phx.gbl..
>>I have a C# program that relies on a service (let's call it
>>myService.exe). So I wrote a routine that makes sure the service is
>>running:
>>
>> int iProcessID = IsProcessRunning("myService.exe");
>> Process myProcess = Process.GetProcessById(iProcessID);
>>
>> These commands work great (I can post the IsProcessRunning() code if
>> necessary, but since that's not the issue I thought I'd leave it out).
>> Here's where the code fails: I check to make sure the process is alive
>> using this code
>>
>> while(!bShutdown)
>> {
>> myProcess.WaitForExit(500);
>> if(myProcess.HasExited)
>> {
>> break;
>> }
>> else
>> {
>> // Periodic functions go here...
>> }
>> }
>>
>> On Windows XP the code works great. On Windows Vista the .HasExited
>> property causes an Access Denied error. I'm sure it has something to do
>> with permissions, but I haven't figured it out yet. Can anyone help?
>>
>> Thanks,
>> John
>>
>>
>