views:

39

answers:

2

I have a webservice and a webform. A button invokes the webservice which reads a given process name from pid. This works fine in VS2008 but when I publish my project I dont get the name? How can I configure IIS to allow me to do so? or is there an alternative way i.e. wcf or wwf?

Edit:

using System.Diagnostics;

[WebMethod]
        public string GetProcessName()
        {
            Process Process = Process.GetProcessById(1428);
            string ProcessTitle = Process.MainWindowTitle;
            return ProcessTitle;
        }

I used tasklist.exe /v to get the pid of a process which has a window title.

A: 

Given your code:

  • how do you know there's a process with PID = 1428 ??
  • what happens if that process doesn't exist?

If you check out this line of code:

Process process = Process.GetProcessById(1428);

will return NULL, and then you grab the .MainWindowTitle from...... NULL..... that's guaranteed to cause an exception.....

using System.Diagnostics;

[WebMethod]
public string GetProcessName()
{
   string processTitle = string.Empty;

   Process process = Process.GetProcessById(1428);

   if(process != null)
   {     
      processTitle = process.MainWindowTitle;
   }

   return processTitle;
}

And even so - again: how do you know a process with ID = 1428 exists??

marc_s
I used tasklist.exe /v to get the pid of a process which has a window title. I mentioned this under the code. 1428 was my chrome browser (google.com) so I am sure it exits :p
dany
A: 

I can't believe that when I deployed my project to Abyss web server it works like a charm. Thanks all anyways.

dany