473,654 Members | 3,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

openning an application using a shell command

Hi,

I need to open (launch) an external application from my winform application.
The application is not a dot.net application, for example the windows
calculator.

I'm using the System.Diagnost ics.Process class, for example:
....
System.Diagnost ics.Process proc = new System.Diagnost ics.Process();
proc.EnableRais ingEvents = false;
proc.StartInfo. WorkingDirector y = @"C:\WINDOWS\sy stem32\";
proc.StartInfo. Arguments = "some argument";
proc.StartInfo. FileName = "calc.exe";
proc.Start();
....

Is there a better way to do it?
How can I close the application programmaticall y?
Can I close it automatically when my application exits?

Thanks in advance, Ohad

--
Ohad Young
Medical Informatics Research Center
Ben Gurion University
Information System Eng
Office Phone: 972-8-6477160
Cellular Phone: 972-54-518301
E-Mail: oh****@bgumail. bgu.ac.il
Nov 15 '05 #1
4 5665
Inline:

--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
"Ohad Young" <oh****@bgumail .bgu.ac.il> wrote in message
news:OL******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I need to open (launch) an external application from my winform application. The application is not a dot.net application, for example the windows
calculator.

I'm using the System.Diagnost ics.Process class, for example:
...
System.Diagnost ics.Process proc = new System.Diagnost ics.Process();
proc.EnableRais ingEvents = false;
proc.StartInfo. WorkingDirector y = @"C:\WINDOWS\sy stem32\";
proc.StartInfo. Arguments = "some argument";
proc.StartInfo. FileName = "calc.exe";
proc.Start();
...

Is there a better way to do it?
No, not for the kind of control you want, I think; you've got it right.
How can I close the application programmaticall y?
proc.Kill();
Can I close it automatically when my application exits?
Sure, just call Kill() on some unload or exit event.

Thanks in advance, Ohad

--
Ohad Young
Medical Informatics Research Center
Ben Gurion University
Information System Eng
Office Phone: 972-8-6477160
Cellular Phone: 972-54-518301
E-Mail: oh****@bgumail. bgu.ac.il

Nov 15 '05 #2

"Ohad Young" <oh****@bgumail .bgu.ac.il> wrote in message
news:OL******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I need to open (launch) an external application from my winform application. The application is not a dot.net application, for example the windows
calculator.

I'm using the System.Diagnost ics.Process class, for example:
...
System.Diagnost ics.Process proc = new System.Diagnost ics.Process();
proc.EnableRais ingEvents = false;
proc.StartInfo. WorkingDirector y = @"C:\WINDOWS\sy stem32\";
proc.StartInfo. Arguments = "some argument";
proc.StartInfo. FileName = "calc.exe";
proc.Start();
...

Is there a better way to do it?
How can I close the application programmaticall y?
Can I close it automatically when my application exits?

Thanks in advance, Ohad

--
Ohad Young
Medical Informatics Research Center
Ben Gurion University
Information System Eng
Office Phone: 972-8-6477160
Cellular Phone: 972-54-518301
E-Mail: oh****@bgumail. bgu.ac.il


Well certainly im doing the same as you to start a batch file. If you wanted
to stop the process a suggestion would be to move the

System.Diagnost ics.Process proc

to the Class scope and put a listener on the close event of your main
form... so.

this.Closing+=n ew CancelEventHand ler(MainForm_Cl osing);

private void MainForm_Closin g(object sender,
System.Componen tModel.CancelEv entArgs e)

{

proc.Close();

}
Nov 15 '05 #3

"Tam Inglis" <jo***********@ btclick.com> wrote in message
news:br******** **@hercules.bti nternet.com...

"Ohad Young" <oh****@bgumail .bgu.ac.il> wrote in message
news:OL******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

I need to open (launch) an external application from my winform application.
The application is not a dot.net application, for example the windows
calculator.

I'm using the System.Diagnost ics.Process class, for example:
...
System.Diagnost ics.Process proc = new System.Diagnost ics.Process();
proc.EnableRais ingEvents = false;
proc.StartInfo. WorkingDirector y = @"C:\WINDOWS\sy stem32\";
proc.StartInfo. Arguments = "some argument";
proc.StartInfo. FileName = "calc.exe";
proc.Start();
...

Is there a better way to do it?
How can I close the application programmaticall y?
Can I close it automatically when my application exits?

Thanks in advance, Ohad

--
Ohad Young
Medical Informatics Research Center
Ben Gurion University
Information System Eng
Office Phone: 972-8-6477160
Cellular Phone: 972-54-518301
E-Mail: oh****@bgumail. bgu.ac.il


Well certainly im doing the same as you to start a batch file. If you

wanted to stop the process a suggestion would be to move the

System.Diagnost ics.Process proc

to the Class scope and put a listener on the close event of your main
form... so.

this.Closing+=n ew CancelEventHand ler(MainForm_Cl osing);

private void MainForm_Closin g(object sender,
System.Componen tModel.CancelEv entArgs e)

{

proc.Close();

}


I stand corrected, kill then close ;-) And probably dispose too on the proc
object if its a closing event.
Nov 15 '05 #4

Hi Ohad,

Thanks for posting in this group.
For simple application such as calculator, the main window stands for its
program life. So you can use Process.CloseMa inWindow to require its main
window to close.
The behavior of CloseMainWindow is identical to that of a user closing an
application's main window using the system menu. Therefore, the request to
exit the process by closing the main window does not force the application
to quit immediately.
If CloseMainWindow fails, you can use Kill to terminate the process. Kill
is the only way to terminate processes that do not have graphical
interfaces.

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1333
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland newsgroups I learned that there is a function in stdlib.h called system. int system(const char *command); First question, is the system command ANSI compliant. Because I include <cstdlib> and write std::system(command.c_str()); it looks like an...
6
2369
by: Ashok | last post by:
hi, i want to know how to make a specific type of file open in an application i developed in python when the user clicks on the file.(in windows) for eg. a .txt file when clicked opens in notepad, a .doc file when clicked opens in MS-word. In the same way i want to make a .xyz file open in the application i developed when clicked. thanks in advance for any advice.
9
5036
by: Tommy Lu | last post by:
Hi, wondering if there is a way to interact the shell command with the C# program? For example, if I type c:\>ver it then suppose to return the version of the OS I am currently using... or c:\>systeminfo
3
1005
by: VJ | last post by:
How do I open a web page from a menu Item click event? Vijay
8
3689
by: jcrouse | last post by:
I am trying to run a command from a command prompt using the shell command. Here is the syntax I want to execute: Shell(lblMameExePath.Text & " -listinfo >" & Application.StartupPath & "\MameGames.cfg", AppWinStyle.NormalFocus, True) The problem is that the parameter Application.StartupPath has spaces (C:\Program Files, for instance) and won't execute from a command prompt without being incased in quotes. I can't figure out the...
0
1672
by: Mac via DotNetMonster.com | last post by:
Hi all, I am attempting to send keystrokes to a telnet application I have opened from my DotNet application. But am having a issue. In my VB.Net app I firstly open the telnet app using the Shell command with the default "MinimisedFocus" behaviour. I then use the AppActivate command to ensure the telnet application is activated and then start using the Sendkeys command.
1
8240
by: ohaqqi | last post by:
Hi guys, I'm still working on my shell. I'm trying to implement a function typefile that will take a command line input as follows: > type <file1> This command will implement a catenation of file1, equal to the command cat <file1> I need to use execvp() and fork() system calls to create a new process that will type/cat any text file. In my code below, the execvp() call in the function at the bottom gets me the following: ...
0
3466
by: Cameron Simpson | last post by:
On 17Aug2008 21:25, John Nagle <nagle@animats.comwrote: Because $HOSTNAME is a bash specific variable, set by bash but NOT EXPORTED! Like $0 and a bunch of other "private" variables, subprocesses do not inherit this value. From "man bash": Shell Variables The following variables are set by the shell:
7
6227
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke this shell script using the Subprocess module. Here is my code: def resultFromRunning_(command):
0
8380
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8296
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8710
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8598
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1928
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1598
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.