WPF 程序中启动和关闭外部.exe程序
当需要在WPF程序启动时,启动另一外部程序(.exe程序)时,可以按照下面的例子来:
C#后台代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes; namespace WpfApplication2
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
System.Diagnostics.Process.Start(@"C:\Program Files\Microsoft Office\Office14\EXCEL.EXE"); //调用该命令,在程序启动时打开Excel程序
}
}
}
C#后台代码:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows; namespace WpfApplication2
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
protected override void OnExit(ExitEventArgs e) //该重写函数实现在程序退出时关闭某个进程
{
Process []myProgress;
myProgress=Process.GetProcesses(); //获取当前启动的所有进程
foreach(Process p in myProgress) //关闭当前启动的Excel进程
{
if (p.ProcessName == "EXCEL") //通过进程名来寻找
{
p.Kill();
return;
}
}
base.OnExit(e);
}
}
}
说明:在WPF程序中,Application类的作用有:
(1)可以跟踪应用程序的生存周期;
(2)共享应用程序范围的属性和资源;
(3)管理独立应用程序中的窗口;
补充:对于Application类,可以有很多属性、事件和方法供调用。当需要实现自定义功能时,可以override方法(标记为Virtual的方法)。
WPF 程序中启动和关闭外部.exe程序的更多相关文章
- C++启动和关闭外部exe
转载:https://www.cnblogs.com/Sketch-liu/p/7277130.html 1.WinExec( lpCmdLine: LPCSTR; {文件名和参数; 如没指定路径会 ...
- 【UE4 C++】 启动 / 关闭外部exe、开启虚拟键盘
启动/关闭外部exe 引擎自带 FPlatformProcess::CreateProc() FPlatformProcess::TerminateProc() windows api ShellEx ...
- windows下调用外部exe程序 SHELLEXECUTEINFO
本文主要介绍两种在windows下调用外部exe程序的方法: 1.使用SHELLEXECUTEINFO 和 ShellExecuteEx SHELLEXECUTEINFO 结构体的定义如下: type ...
- C#和asp.net执行外部EXE程序
这两天研究下.Net的执行外部EXE程序问题,就是在一个程序里通过按钮或其他操作运行起来另外一个程序,需要传入参数,如用户名.密码之类(实际上很类似单点登录,不过要简单的多的多):总结如下: 1.CS ...
- 查看程序是否启动或者关闭--比如查看Tomcat是否开启!直接用ps命令查看进程就行了啊
1.查看程序是否启动或者关闭--比如查看Tomcat是否开启!直接用ps命令查看进程就行了啊 2.Tomcat服务器和虚拟机的关系,Tomcat启动运行过程要调用系统环境变量的java_home啊,J ...
- c# 调用外部exe程序
c#调用外部exe程序,首先要 using System.Diagnostics; 然后开启一个新process System.Diagnostics.ProcessStartInfo p=null; ...
- IOS在一个程序中启动另一个程序
尽管iPhone不允许同时运行两个应用程序,我们可以从自己的应用程序中启动另一个应用程序,并且可以在应用程序之间共享数据.我们可以使用UIApplication类的openURL:方法从一个应用程序来 ...
- 更改开机默认不显示explorer.exe,直接启动自己写的EXE程序方法
原文:更改开机默认不显示explorer.exe,直接启动自己写的EXE程序方法 更改开机默认不显示explorer.exe,直接启动自己写的EXE程序的函数: bool UpdateWinlogon ...
- delphi 打开和关闭外部exe
一.打开外部exe 1.use文件-SHELLAPI 2.ShellExecute(handle,'open','E:\test.exe','-s','',SW_SHOWNORMAL); 二.关闭外部 ...
随机推荐
- matlab color_rain colorbar
来自http://www.aos.wisc.edu/~dvimont/matlab/Graphics_Tools/color_rain.html Listing of script color_rai ...
- java定时任务接口ScheduledExecutorService
一.ScheduledExecutorService 设计思想 ScheduledExecutorService,是基于线程池设计的定时任务类,每个调度任务都会分配到线程池中的一个线程去执行,也就是说 ...
- mac下烦人的eclipse安装svn插件
eclipse作为一个鸡肋般的java ide,颇有食之无味弃之可惜之感.最近公司统一对电脑做了一些处理,搞的我的eclipse都不能用了.重新安装了一下,各种maven.svn,代码格式什么的依赖神 ...
- ThindPad x230 无法U盘启动
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- Spring + iBatis 的多库横向切分简易解决思路
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- HDU 5433 Xiao Ming climbing dp
Xiao Ming climbing Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/ ...
- LeetCode144:Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary t ...
- PHP中获取中英文混合字符串长度[主要是指个数,而不是字符串长度](转)
今晚在写框架的表单验证类时,需要判断某个字符串长度是否在指定区间内,很自然地,想到了PHP中的strlen函数. $str = 'Hello world!'; echo strlen($str); ...
- 功能丰富的 Perl:轻松调试 Perl
http://www.ibm.com/developerworks/cn/linux/sdk/perl/culture-4/index.html
- 实例源码--Android日历实例源码
下载源码 技术要点: 1.Android基础控件的使用 2.Android应用开发基础框架 3.源码带有非常详细的中文 注释 ...... 详细介绍: 1. Android应用开 发技术 此套 ...