_declspec(dllexport)
int WINAPI icePub_runByAdmin(char *strAppPathName,char *strSuParam);
//以管理员身份运行指定程序 visual c++
int runByAdmin(void)
{
int retCode=-1;
typedef int (WINAPI ICEPUB_RUNBYADMIN)(char *strAppPathName,char *strSuParam);
ICEPUB_RUNBYADMIN *icePub_runByAdmin = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
icePub_runByAdmin = (ICEPUB_RUNBYADMIN *)GetProcAddress(hDLLDrv, "icePub_runByAdmin");
if(icePub_runByAdmin)
retCode=icePub_runByAdmin("E:\\c++\\IsAdmin\\setup.bat","");
if(hDLLDrv)
FreeLibrary(hDLLDrv);
if(retCode == 0)
exit(0);
if(retCode == -1)
AfxMessageBox("以管理员启动失败,请手动启动");
return retCode;
}
icePubDll.dll 下载地址:
http://www.pudn.com/downloads369/sourcecode/windows/detail1598958.html
本文介绍了一个使用C++实现的方法,该方法通过调用名为icePubDll.dll的动态链接库中的函数来以管理员权限运行指定的应用程序。示例中具体展示了如何加载dll文件并调用icePub_runByAdmin函数,以管理员身份运行位于特定路径下的setup.bat批处理文件。

3万+

被折叠的 条评论
为什么被折叠?



