警告用户未签名的可执行文件

发布于 2024-10-15 13:35:04 字数 270 浏览 4 评论 0原文

我有一个充当存根角色的 ClickOnce 应用程序 - 它是一个小型应用程序,只需下载另一个安装程序。它的工作方式是下载有效负载,运行它并关闭。它是用 C# .NET 编写的。我的问题是有效负载是动态的。如果应用程序下载的有效负载未签名,我希望我的 ClickOnce 应用程序向用户显示警告。当启用 UAC 时,此行为会自动出现,但是我的存根在许多不同的操作系统上运行,并且我不知道 UAC 是否已启用。如果我可以简单地调用 Windows 在运行可执行文件时发出的警告,我会很高兴 - 这可能吗?如果没有,你有什么推荐?

I have a ClickOnce application that plays the role of a stub - it's a small application that simply downloads another installer. The way it works is that it downloads the payload, runs it and closes. It's written in C# .NET. My problem is the payload is dynamic. I want my ClickOnce application to display a warning to the user if the payload that the application downloaded is not signed. This behavior is automatically present when UAC is enabled, however my stub is run on many different OS's and I don't know if UAC is enabled or not. I would love it if I could simply invoke the warning that Windows does when an executable is run - is this possible? If not, what do you recommend?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海里的那抹蓝 2024-10-22 13:35:04

我假设您正在谈论运行从网站下载的程序时显示的警告。

您需要将 Zone.Identifier 备用数据流添加到文件中。
您可以使用此库来做到这一点:

var fs = new NTFS.FileStreams(filename)
fs.Add("Zone.Identifier")
using (var writer = new StreamWriter(fs["Zone.Identifier"].Open()) {
    writer.WriteLine("[ZoneTransfer]")
    writer.WriteLine("ZoneID=4")
}

I assume that you're talking about the warning shown when running a program downloaded from a website.

You need to add a Zone.Identifier Alternate Data Stream to the file.
You can do that using this library:

var fs = new NTFS.FileStreams(filename)
fs.Add("Zone.Identifier")
using (var writer = new StreamWriter(fs["Zone.Identifier"].Open()) {
    writer.WriteLine("[ZoneTransfer]")
    writer.WriteLine("ZoneID=4")
}
仙气飘飘 2024-10-22 13:35:04

在Win32中,用于验证Authenticode签名的函数是WinVerifyTrust。没有 .NET BCL 等效项(据我所知),但 pinvoke.net 有一篇关于如何从 C# 使用它的非常好的文章:

http://www.pinvoke.net/default.aspx/wintrust.winverifytrust

In Win32, the function used to verify Authenticode signatures is WinVerifyTrust. There is no .NET BCL equivalent (as far as I know), but pinvoke.net has a pretty good article on how to use it from C#:

http://www.pinvoke.net/default.aspx/wintrust.winverifytrust

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文