程序调用ShellExecuteEx打开其他程序(兼容UAC获取管理员权限)

    xiaoxiao2021-03-25  59

    参考文章:http://blog.csdn.net/xmnathan/article/details/39498431

    // ConsoleApplication1.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <Windows.h> #pragma warning(disable: 4996) //检查系统版本是否是Vista或更高的版本 bool IsOsVersionVistaOrGreater() { OSVERSIONINFOEX ovex = { sizeof(OSVERSIONINFOEX), 0 }; if (!GetVersionEx((LPOSVERSIONINFO)(&ovex))) { return false; } //通过版本号,判断是否是vista及之后版本 if (ovex.dwMajorVersion > 5) { return true; } else { return false; } } //检查并根据系统版本选择打开程序方式 void MyShellExecuteEx(LPCTSTR lpFile, LPCTSTR lpParameters) { if (IsOsVersionVistaOrGreater()) { SHELLEXECUTEINFO sei = { sizeof(SHELLEXECUTEINFOW), 0 }; sei.fMask = SEE_MASK_NOCLOSEPROCESS; sei.nShow = SW_SHOWNORMAL; sei.lpFile = lpFile; sei.lpParameters = lpParameters; sei.lpVerb = _T("runas"); ShellExecuteEx(&sei); } else { ShellExecute(NULL, _T("open"), lpFile, lpParameters, NULL, SW_SHOWNORMAL); } } int _tmain(int argc, _TCHAR* argv[]) { MyShellExecuteEx(_T(".\\Setup.exe"), _T("/S")); return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-40479.html

    最新回复(0)