从 C# 以编程方式创建快捷方式并设置“以管理员身份运行”财产
我已经知道如何使用 IWshRuntimeLibrary
和 WshShellClass
从 C# 应用程序以编程方式创建快捷方式。或者我可以使用 IShellLink
。
现在,如果用户的电脑运行的是 Windows Vista 或 Windows 7,我希望能够以编程方式设置该快捷方式的“以管理员身份运行”属性。
这可能吗?如果是这样,怎么办?
I already know how to create shortcuts programmatically from my C# applications using IWshRuntimeLibrary
and WshShellClass
. Or I could use IShellLink
.
Now, if the user's PC is running Windows Vista or Windows 7, I would like to be able to set the "Run as administrator" property of that shortcut programmactically as well.
Is that possible? If so, how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
此示例使用 PowerShell,但使用与 C# 相同的对象和类。
使用以下代码获取要激活的字节号:
我得到字节号 21,其值为 34。
这是我用户的脚本:
This example is in PowerShell, but is uses the same objects and classes as C#.
Use the following code to get the byte number to activate:
I got byte number 21 and its value was 34.
So this is the script I user:
虽然 Doug 的答案是此问题的正确解决方案,但它不是此特定问题的答案...
要在 .lnk 上设置该属性,您需要使用 IShellLinkDataList COM 接口。伟大的 Raymond Chen 在他的博客上c++ 示例代码为此
While Doug's answer is the correct solution to this problem, it is not the answer to this specific question...
To set that property on a .lnk, you need to use the IShellLinkDataList COM interface. The great Raymond Chen has c++ sample code on his blog for this
使用此方法,您可以创建一个设置了“以管理员身份运行”属性的快捷方式:
首先,您需要添加对“Windows Script Host Object Model”库的引用,它是一个COM库,因此在项目中,右键单击该引用转到COM部分,然后添加该库。
以管理员身份运行部分的功劳属于 此处
With this method you can create a shortcut that its “Run as administrator” property is set:
first, you need to add a reference to the "Windows Script Host Object Model" library, it is a COM library, so in the project, right-click on the reference go to the COM section, and add the library.
Credit for run as admin section belongs to here
您需要为您的应用程序创建一个清单文件,以便让它请求以管理员权限运行。 这是一个不错的教程,您可以遵循。
尽情享受!
You will need to create a manifest file for your application in order to get it to request run as an administrator privileges. Here is a nice tutorial you can follow.
Enjoy!