Windows 如何从基于WiX的安装程序安装桌面快捷方式(到批处理文件),该安装程序具有;“以管理员身份运行”;启用?
我正在从基于WiX的安装程序安装桌面快捷方式(到批处理文件)——如何在启用“以管理员身份运行”设置的情况下自动配置此快捷方式?目标操作系统是Windows Server 2008 R2,安装程序正在使用提升的权限运行 更新:Windows 如何从基于WiX的安装程序安装桌面快捷方式(到批处理文件),该安装程序具有;“以管理员身份运行”;启用?,windows,installation,wix,shortcut,Windows,Installation,Wix,Shortcut,我正在从基于WiX的安装程序安装桌面快捷方式(到批处理文件)——如何在启用“以管理员身份运行”设置的情况下自动配置此快捷方式?目标操作系统是Windows Server 2008 R2,安装程序正在使用提升的权限运行 更新: 多亏了@Anders提供的链接,我才得以实现这一目标。我需要在C#CustomAction中执行此操作,下面是C#版本的代码: namespace CustomAction1 { public class CustomAction1 { public bool Ma
多亏了@Anders提供的链接,我才得以实现这一目标。我需要在C#CustomAction中执行此操作,下面是C#版本的代码:
namespace CustomAction1
{
public class CustomAction1
{
public bool MakeShortcutElevated(string file_)
{
if (!System.IO.File.Exists(file_)) { return false; }
IPersistFile pf = new ShellLink() as IPersistFile;
if (pf == null) { return false; }
pf.Load(file_, 2 /* STGM_READWRITE */);
IShellLinkDataList sldl = pf as IShellLinkDataList;
if (sldl == null) { return false; }
uint dwFlags;
sldl.GetFlags(out dwFlags);
sldl.SetFlags(dwFlags | 0x00002000 /* SLDF_RUNAS_USER */);
pf.Save(null, true);
return true;
}
}
[ComImport(), Guid("00021401-0000-0000-C000-000000000046")]
public class ShellLink { }
[ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("45e2b4ae-b1c3-11d0-b92f-00a0c90312e1")]
interface IShellLinkDataList
{
void AddDataBlock(IntPtr pDataBlock);
void CopyDataBlock(uint dwSig, out IntPtr ppDataBlock);
void RemoveDataBlock(uint dwSig);
void GetFlags(out uint pdwFlags);
void SetFlags(uint dwFlags);
}
}
我猜您需要一个自定义操作并自己调用COM接口。查询IShellLinkDataList的IShellLink(或IPersistFile?),然后:
IShellLinkDataList->SetFlags(orgFlagsFromGetFlags | SLDF(u RUNAS)USER)代码>
编辑:Raymond在他的上有完整的示例代码,感谢您发布您的解决方案!我非常需要它。别忘了:使用System.Runtime.InteropServices.ComTypes;如何执行上述代码。现在我要做和你一样的事。请帮助我这是一个powershell脚本?链接是dead@Jody为什么会是PS?我修复了死链接。。。