ShellExecuteEx打开、关闭exe
来源:互联网 发布:为数据而生 周涛 pdf 编辑:程序博客网 时间:2024/04/30 08:53
//声明结构体SHELLEXECUTEINFO ShExecInfo;//打开void OpenExe() {ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS ;ShExecInfo.hwnd = NULL;ShExecInfo.lpVerb = NULL;ShExecInfo.lpFile = "adb.exe";ShExecInfo.lpParameters = ""; ShExecInfo.lpDirectory = NULL;ShExecInfo.nShow = SW_SHOW;ShExecInfo.hInstApp = NULL; ShellExecuteEx(&ShExecInfo);}//关闭void CloseExe() {if( ShExecInfo.hProcess != NULL){ TerminateProcess(ShExecInfo.hProcess,0);ShExecInfo.hProcess = NULL;}}
SHELLEXECUTEINFO 结构说明:转自【https://msdn.microsoft.com/en-us/library/aa932861.aspx】
typedef struct _SHELLEXECUTEINFO { DWORD cbSize; ULONG fMask; HWND hwnd; LPCTSTR lpVerb; LPCTSTR lpFile; LPCTSTR lpParameters; LPCTSTR lpDirectory; int nShow; HINSTANCE hInstApp; LPVOID lpIDList; LPCTSTR lpClass; HKEY hkeyClass; DWORD dwHotKey; union { HANDLE hIcon; HANDLE hMonitor; } DUMMYUNIONNAME; HANDLE hProcess; } SHELLEXECUTEINFO, FAR* LPSHELLEXECUTEINFO;
Members
- cbSize
Size of the structure, in bytes.
- fMask
Array of flags that indicate the content and validity of the other structure members. For Windows CE 1.0 and 1.01, fMask flags are unsupported. For Windows CE 2.0 and later,fMask can be a combination of the following values.
Value Description SEE_MASK_FLAG_NO_UI
Does not display an error message box if an error occurs.
SEE_MASK_NOCLOSEPROCESS
Leaves the process running after the ShellExecuteEx function exits. The hProcess member receives the handle to the process.
- hwnd
Window handle to any message boxes that the system may produce while executing this function.
- lpVerb
Long pointer to a string specifying the name of a verb. The verb specifies an action for the application to perform. The set of available verbs depends on the particular file or folder. It includes the commands listed in the context menu and the registry. The following table shows verbs that are usually valid.
Value Description Edit
The function opens an editor.
Find
The function initiates a search starting from the specified directory.
Open
The function opens the file specified by the lpFile parameter. The file can be an executable file or a document file. It can also be a folder. This is the default verb if no verb is specified.
Print
The function prints the document file specified by lpFile.
- lpFile
Long pointer to a null-terminated string that specifies the absolute name of the file to open or print. The function can open an executable file or a document file, but it can only print a document file. Note that the concept of a current directory does not exist in Windows Embedded CE. You must specify the complete file path to specify the absolute file name.
- lpParameters
Long pointer to a null-terminated string that contains the application parameters. The parameters must be separated by spaces. To include double quotation marks, you must enclose the marks in double quotation marks, as in the following example.
sei.lpParameters = "An example: \"\"\"quoted text\"\"\"";
In this case, the application receives three parameters: An, example:, and "quoted text".
If the lpFile member specifies a document file, this member should be NULL.
- lpDirectory
Not supported. Set to zero.
- nShow
Show flags. Can be one of the SW_* values described for the ShowWindow function. If lpFile specifies an executable file, this member specifies how the application is to be shown when it is opened.
- hInstApp
This member is only valid if the function fails, in which case it receives one of the following error values, which are less than or equal to 32.
Value Description SE_ERR_FNF
File not found.
SE_ERR_PNF
Path not found.
SE_ERR_ACCESSDENIED
Access denied.
SE_ERR_OOM
Out of memory.
SE_ERR_DLLNOTFOUND
Dynamic-link library not found.
SE_ERR_SHARE
Cannot share an open file.
SE_ERR_ASSOCINCOMPLETE
File association information not complete.
SE_ERR_DDETIMEOUT
DDE operation timed out.
SE_ERR_DDEFAIL
DDE operation failed.
SE_ERR_DDEBUSY
DDE operation is busy.
SE_ERR_NOASSOC
File association not available.
If the function succeeds, the value of this member should be ignored.
- lpIDList
Ignored.
- lpClass
Ignored.
- hkeyClass
Ignored.
- dwHotKey
Ignored.
- hIcon
Ignored.
- hProcess
Handle to the newly started application. This member is set on return and is always set to NULL if fMask is not set to SEE_MASK_NOCLOSEPROCESS.
Remarks
The verbs available for an object are essentially the items that you find on an object's shortcut menu. To find which verbs are available, look in the registry under
HKEY_CLASSES_ROOT\<object_name>\Shell\<verb>
object_name is the name of the file object and verb is the name of the available verb. The verb subkey contains the data indicating what happens when that verb is invoked.
Each verb corresponds to the command that would be used to launch the application from a console window. The open verb is a good example, because it is commonly supported. For .exe files, open launches the application. However, it is more commonly used to launch an application that operates on a particular file. For instance, .txt files can be opened by Microsoft® WordPad. The open verb for a .txt file corresponds to the following command:
"C:\Program Files\Windows NT\Accessories\Wordpad.exe" "%1"
When you use ShellExecuteEx to open a .txt file, Wordpad.exe is launched with the specified file as its argument. Some commands can have additional arguments, such as flags, that can be added as needed to launch the application properly.
In general, trying to determine the list of available verbs for a particular file is somewhat complicated. In many cases, you can set the lpVerb member to NULL, which invokes the default command for the file class. This procedure is usually equivalent to setting lpVerb to open, but some file classes may have a different default command.
Requirements
- ShellExecuteEx打开、关闭exe
- 用ShellExecuteEx和TerminateProcess打开和关闭文件
- 进程 等待 关闭 ShellExecuteEx WaitForSingleObject
- 打开,关闭 Notepad.exe 进程操作
- windows批处理 打开exe后关闭cmd
- 用ShellExecuteEx打开文件,文件夹
- 用ShellExecuteEx打开文件,文件夹
- C/C++ ShellExecuteEx调用exe可执行文件
- ShellExecuteEx
- ShellExecuteEx
- ShellExecuteEx
- 使用 ShellExecuteEx 打开文件或执行程序
- VB中关闭shell打开的外部EXE程序
- C# 获取网关地址 读取配置文件 打开关闭exe
- VB中关闭shell打开的外部EXE程序
- c# 打开exe文件与关闭exe文件 c#服务打开exe时候默认是没有窗体界面的
- c# 打开exe文件与关闭exe文件 c#服务打开exe时候默认是没有窗体界面的
- 关闭oralce的进程oracle.exe,怎么再重新打开进程oracle.exe
- Power键 和 HOME键 广播监听的问题
- webapp如何从tomcat的conf目录中加载配置?
- DWR入门教程
- CDN(内容分发网络)技术原理
- 解决mac下安卓模拟器不能X86开启(加速模拟器)
- ShellExecuteEx打开、关闭exe
- JavaScript的垃圾回收机制
- 测试接口是否好用,前台后台数据传输问题!
- 火狐Firebug提示:ReferenceError: "sth" is not defined
- Java的一些工具
- TDI 或者NDIS filter 实现进程禁止联网
- C__删除文件操作
- CXF+WS-Security+Spring WebService服务器端+客户端及注意问题
- php框架汇总