码迷,mamicode.com
首页 > Windows程序 > 详细

RunAsAdmin in windows 8

时间:2014-12-22 07:03:30      阅读:378      评论:0      收藏:0      [点我收藏+]

标签:

function RunAsAdmin(hWnd: HWND; filename: string; Parameters: string): Boolean;
{
    See Step 3: Redesign for UAC Compatibility (UAC)
    http://msdn.microsoft.com/en-us/library/bb756922.aspx
}
var
    sei: TShellExecuteInfo;
begin
    ZeroMemory(@sei, SizeOf(sei));
    sei.cbSize := SizeOf(TShellExecuteInfo);
    sei.Wnd := hwnd;
    sei.fMask := SEE_MASK_FLAG_DDEWAIT or SEE_MASK_FLAG_NO_UI;
    sei.lpVerb := PChar(‘runas‘);
    sei.lpFile := PChar(Filename); // PAnsiChar;
    if parameters <> ‘‘ then
    	sei.lpParameters := PChar(parameters); // PAnsiChar;
    sei.nShow := SW_SHOWNORMAL; //Integer;

    Result := ShellExecuteEx(@sei);
end;

See Mask values here:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb759784(v=vs.85).aspx

This article will show you how to create a Delphi Application with a manifest to request elevation (run as admin). Read the article, it has a link to Delphi Manifest creator for doing this - very nice ! it will save you a lot of work. So if the program you need to run is written in Delphi and you have the source code then use this method.

http://delphi.about.com/od/delphitips2009/qt/delphi-vista-registry-run-on-startup.htm
https://stackoverflow.com/questions/15319158/use-shell-execute-to-run-cmd-as-admin

RunAsAdmin in windows 8

标签:

原文地址:http://www.cnblogs.com/findumars/p/4177409.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!