1

我正在使用以下代码在 Delphi 中创建快捷方式。我想在快捷方式的权限级别属性中选中“以管理员身份运行此程序”框来创建快捷方式。有没有办法做到这一点?

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;
4

1 回答 1

4

您需要使用IShellLinkDataList::SetFlags()传递SLDF_RUNAS_USER

我手头没有任何代码示例。但基本方法是这样的:

sldl := s as IShellLinkDataList;
flags := sldl.GetFlags();
sldl.SetFlags(flags or SLDF_RUNAS_USER);
于 2012-09-29T17:00:37.267 回答