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 whe开发者_如何学Cn 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?
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")
}
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
精彩评论