I am using the following code to make shortcuts in Delphi. I want to make a shortcut with “Run this program as an administrator” box checked in Privilege Level properties of shortcut. Is there any way to do this?
function MakeShortcut(Dst, Src: String; Desc: String = ''; Arg: String = ''; WorkDir: String = ''; Icon: String = ''; IconI: Integer = 0; Show: Integer = SW_SHOWNORMAL; HotKey: Word = 0): Boolean;
var
u: IUnknown;
s: IShellLink;
f: IPersistFile;
p: WideString;
begin
try
u := CreateComObject(CLSID_SHELLLINK);
s := u as IShellLink;
f := u as IPersistFile;
s.SetPath(PChar(Src));
if (WorkDir = '') then WorkDir := ExtractFileDir(Src);
s.SetWorkingDirectory(PChar(WorkDir));
if (Icon = '') then Icon := Src;
s.SetIconLocation(PChar(Icon), IconI);
s.SetDescription(PChar(Desc));
s.SetArguments(PChar(Arg));
s.SetShowCmd(Show);
s.SetHotkey(HotKey);
p := Dst;
Result := Succeeded(f.Save(PWChar(p), False));
except
Result := False;
end;
end;
You need to use
IShellLinkDataList::SetFlags()passingSLDF_RUNAS_USER.I don’t have any code samples at hand. But the basic approach will be like this: