Click here to Skip to main content
16,004,924 members
Home / Discussions / C#
   

C#

 
GeneralRe: classes Pin
sosodev12-Jul-05 22:17
sosodev12-Jul-05 22:17 
GeneralRe: classes Pin
enjoycrack12-Jul-05 22:09
enjoycrack12-Jul-05 22:09 
GeneralRe: classes Pin
sosodev12-Jul-05 23:03
sosodev12-Jul-05 23:03 
GeneralIntegrate WIndows Service and my application project Pin
ksanju100012-Jul-05 20:42
ksanju100012-Jul-05 20:42 
GeneralWindows Service in Windows XP Pin
ksanju100012-Jul-05 20:40
ksanju100012-Jul-05 20:40 
GeneralRe: Windows Service in Windows XP Pin
Dave Kreskowiak13-Jul-05 2:29
mveDave Kreskowiak13-Jul-05 2:29 
GeneralRe: Windows Service in Windows XP Pin
ksanju100013-Jul-05 4:14
ksanju100013-Jul-05 4:14 
GeneralRe: Windows Service in Windows XP Pin
Dave Kreskowiak13-Jul-05 5:06
mveDave Kreskowiak13-Jul-05 5:06 
Wow. Where to begin...

First, you've put this in the the OnStart procedure of your service. This means that it will only run ONCE per start of the service or on startup of Windows. OnStart is meant for you to start your service code, possibly on another thread. The way you have it setup, your code will execute once, then stop.

The error comes up because you have a problem with your code in the OnStart() method. You've got ALOT of problems with this code.
protected override void OnStart(string[] args)
{
    // TODO: Add code here to start your service.

    Process[] aProcesses1;
    if (aProcesses1.Length > 0) 
    {
        if(rd1==true)
        {
            // The below statement is NOT true!  The last Excel process in NOT
            // guaranteed to be the orphaned process!  Whatever you mean by this...
            // The last excel process is the orphaned process which is killed

            // Your code here is killing off the second to last process in the
            // list, WHATEVER this process is, even a System process!  <- BAD!
            // You're not checking to see if it is Excel!
            // On top of that, you're not even retrieving the list of processes.
            // All your doing is creating a process object that doesn't represent
            // any process and trying to call Kill on it.  THIS WILL FAIL!
            aProcesses1[aProcesses1.Length-1].Kill();
            rd1=false;
        }
    }

    int intExcelPID;
    aProcesses1=Process.GetProcessesByName("man");
    string strProc="These are the processes running \n";
    for (int i = 0; i <= aProcesses1.GetUpperBound(0); i++)
    {
        intExcelPID = aProcesses1[i].Id;
        strProc+=intExcelPID.ToString()+ "  ";
    }    

    //Retrive from registry the value of Path
    RegistryKey hklm=Registry.LocalMachine;
    hklm=hklm.OpenSubKey("SOFTWARE\\man");
    Object obp=hklm.GetValue("Path");
    string file=obp.ToString() + "\\man.exe";
    Process.Start(@file);
}

But first, I take it your trying to find Excel processes that are left open by an application? Why?


RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

GeneralProblem in creating objects of derived class Pin
tttyip12-Jul-05 20:28
tttyip12-Jul-05 20:28 
GeneralRe: Problem in creating objects of derived class Pin
S. Senthil Kumar12-Jul-05 21:15
S. Senthil Kumar12-Jul-05 21:15 
GeneralRe: Problem in creating objects of derived class Pin
tttyip13-Jul-05 16:11
tttyip13-Jul-05 16:11 
GeneralIIS Root Path location Pin
Sau Fan Lee12-Jul-05 17:28
Sau Fan Lee12-Jul-05 17:28 
GeneralRe: IIS Root Path location Pin
Expert Coming12-Jul-05 18:02
Expert Coming12-Jul-05 18:02 
GeneralMs Word Field Codes Pin
bootn12-Jul-05 17:05
bootn12-Jul-05 17:05 
GeneralRe: Ms Word Field Codes Pin
ekynox13-Jul-05 19:29
ekynox13-Jul-05 19:29 
GeneralSave as &quot;TXT&quot; File Pin
tatchung12-Jul-05 15:47
tatchung12-Jul-05 15:47 
GeneralRe: Save as &quot;TXT&quot; File Pin
Christian Graus12-Jul-05 17:28
protectorChristian Graus12-Jul-05 17:28 
GeneralRe: Save as &quot;TXT&quot; File Pin
tatchung12-Jul-05 17:36
tatchung12-Jul-05 17:36 
GeneralRe: Save as &quot;TXT&quot; File Pin
Christian Graus12-Jul-05 17:45
protectorChristian Graus12-Jul-05 17:45 
GeneralRe: Save as &quot;TXT&quot; File Pin
tatchung12-Jul-05 17:53
tatchung12-Jul-05 17:53 
GeneralRe: Save as &quot;TXT&quot; File Pin
Christian Graus12-Jul-05 17:55
protectorChristian Graus12-Jul-05 17:55 
GeneralRe: Save as &quot;TXT&quot; File Pin
tatchung12-Jul-05 18:03
tatchung12-Jul-05 18:03 
GeneralRe: Save as &quot;TXT&quot; File Pin
Christian Graus12-Jul-05 18:12
protectorChristian Graus12-Jul-05 18:12 
GeneralRe: Save as &quot;TXT&quot; File Pin
tatchung12-Jul-05 18:23
tatchung12-Jul-05 18:23 
GeneralRe: Save as &quot;TXT&quot; File Pin
Christian Graus12-Jul-05 18:27
protectorChristian Graus12-Jul-05 18:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.