0

I call another form exe file into my main form but i did not want to show up it need to be visible. then i need to close the exe file when clicking the button .

i call my another form exe use of the code

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "C:\\Users\\server.exe";
Process.Start(startInfo);

please help me how it run visible?

the when i need to close that exe i use

Process.Kill();

An object reference is required for the non-static field, method, or property 'Process.Kill()'

I get this error.

help me how to open another exe as visible? and how to close it when button click?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Divi
  • 49
  • 1
  • 8
  • If you call Process.Start, the exe will be started and if that exe has a window, the window will be visible. –  Jun 29 '16 at 13:20

2 Answers2

1

To answer your second question:

Kill() is an instance method of Process, but you try to call it like a static method.

You need to use the Process instance returned by Process.Start() and call Kill() on that instance:

Process myProcessInstance = Process.Start(startInfo);
//...
myProcessInstance.Kill(); 

For your first question: I don't fully understand your problem? Do you want the window to appear or not? Should it be visible or invisible? And what is happening (do you see it or not) when you run your current code?

You may have a look at ProcessStartInfo.CreateNoWindow and ProcessStartInfo.WindowStyle properties.

If you don't want to see the form created by the *.exe you started you unfortunatly cannot trigger that simply via the ProcessStartInfo. You will have to use the Windows API to enumerate the windows of the started process and access these windows through that API. Here is a starting point.

If the server.exe is created by you, you may think about giving it some command line arguments to tell it not to show the forms.

Community
  • 1
  • 1
René Vogt
  • 43,056
  • 14
  • 77
  • 99
1

You need to store you Process in a variable:

Process process = Process.Start(startInfo);

process.Kill();
Jan Wiesemann
  • 455
  • 2
  • 16