RunAsAdmin in windows 8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步