启动程序(三种方式)

三种启动方式:winexec、shellexecute、createprocess

// excute_exe.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <Windows.h>

BOOL WinExe_Test(char *pszExePath, UINT uiCmdShow);
BOOL ShellExecute_Test(char *pszExePath, UINT uiCmdShow);
BOOL CreateProcess_Test(char *pszExePath, UINT uiCmdShow);


int _tmain(int argc, _TCHAR* argv[])
{
	BOOL bRet = FALSE;
	bRet = WinExe_Test("C:\\Program Files (x86)\\EditPlus\\editplus.exe", SW_HIDE);
	if (bRet)
	{
		printf("editplus.exe Run Success (WinExe_Test)!\n");
	}
	else
	{
		printf("editplus.exe Run Failed (WinExe_Test)!\n");
	}

	bRet = ShellExecute_Test("C:\\Program Files (x86)\\EditPlus\\editplus.exe", SW_HIDE);
	if (bRet)
	{
		printf("editplus.exe Run Success (ShellExecute_Test)!\n");
	}
	else
	{
		printf("editplus.exe Run Failed (ShellExecute_Test)!\n");
	}

	bRet = CreateProcess_Test("C:\\Program Files (x86)\\EditPlus\\editplus.exe", SW_HIDE);
	if (bRet)
	{
		printf("editplus.exe Run Success (CreateProcess_Test)!\n");
	}
	else
	{
		printf("editplus.exe Run Failed (CreateProcess_Test)!\n");
	}

	system("pause");
	return 0;
}

BOOL WinExe_Test(char *pszExePath, UINT uiCmdShow)
{
	UINT uiRet = 0;
	uiRet = WinExec(pszExePath, uiCmdShow);
	if (31 < uiRet)
	{
		return TRUE;
	}
	return FALSE;

}

BOOL ShellExecute_Test(char *pszExePath, UINT uiCmdShow)
{
	HINSTANCE hInstance = 0;
	hInstance = ShellExecuteA(NULL, NULL, pszExePath, NULL, NULL, uiCmdShow);
	if (32 < (DWORD)hInstance)
	{
		return TRUE;
	}
	return FALSE;

}

BOOL CreateProcess_Test(char *pszExePath, UINT uiCmdShow)
{
	STARTUPINFOA si = { 0 };
	PROCESS_INFORMATION pi;
	BOOL bRet = FALSE;
	si.cb = sizeof(si);
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = uiCmdShow;
	bRet = CreateProcessA(NULL, pszExePath, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi);
	if (bRet)
	{
		CloseHandle(pi.hThread);
		CloseHandle(pi.hProcess);
		return TRUE;

	}
	return TRUE;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值