|
2023/03/20(Mon) 19:08:10 編集(投稿者)
■No101611 (魔界の仮面弁士) に追記 > ちなみにこのコードは、『C# で Mark of The Web を付与する方法』を > Bing Chat 検索に問い合わせることで得られたコードです。
同じアカウントでも、教えてくれたり、教えてくれなかったりするようで、 Bing さんはとても気まぐれなようです。 https://www.vb-user.net/junk/replySamples/2023.03.20.18.58/MarkOfTheWeb.png
API による実装例も教えてくれそうだったのだけれど、 途中で回答が打ち切られてしまいました。
----> 申し訳ありません。私の回答が不十分でした。.NET Framework 4.8.1 で使用する場合、以下のコードを使用して、Mark of the Web を付与することができます。
using System; using System.IO; using System.Runtime.InteropServices;
namespace MarkOfTheWeb { class Program { static void Main(string[] args) { string filePath = @"C:\Users\UserName\Downloads\file.html"; string zoneIdentifier = "Zone.Identifier"; string zoneIdentifierValue = "3";
// Set the Mark of the Web SetZoneIdentifier(filePath, zoneIdentifier, zoneIdentifierValue); }
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern bool DeleteFile(string lpFileName);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern bool SetFileAttributes(string lpFileName, uint dwFileAttributes);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, uint dwFlags);
[DllImport("urlmon.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern uint DeleteUrlCacheEntry(string lpszUrlName);
[DllImport("urlmon.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern uint CoInternetSetFeatureEnabled(uint FeatureEntry, uint dwFlags, bool fEnable);
[DllImport("urlmon.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern uint CoInternetIsFeatureEnabled(uint FeatureEntry, uint dwFlags);
[DllImport("urlmon.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern uint UrlMkSetSessionOption(uint dwOption, IntPtr pBuffer, uint dwBufferLength, uint dwReserved);
[DllImport("urlmon.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern uint UrlMkGetSessionOption(uint dwOption, IntPtr pBuffer, uint dwBufferLength, out uint pdwBufferLength, uint dwReserved);
[DllImport("urlmon.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern uint CoInternetSetZoneMapping(uint dwZone, string lpszPattern, uint dwFlags);
[DllImport("urlmon.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern uint CoInternetGetZoneMapping(uint dwZone, string lpszPattern, out uint pdwFlags);
[DllImport("urlmon.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern uint CoInternetCreateZoneManager(IntPtr pPolicy, out IntPtr ppZoneMgr, uint dwReserved);
[DllImport("urlmon.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern uint CoInternetCreateSecurityManager(IntPtr pPolicy, out IntPtr ppSecMgr, uint dwReserved);
[DllImport("urlmon.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern uint CoInternetCombineUrl(string pwzBaseUrl, string pwzRelativeUrl, uint dwCombineFlags, IntPtr pszResult, uint cchResult, out uint pcchResult, uint dwReserved);
[DllImport("urlmon.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern uint CoInternetParseUrl(string pwzUrl, uint ParseAction, uint dwFlags, IntPtr pszResult, uint cchResult, out uint pcchResult, uint dwReserved);
[DllImport("urlmon.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern uint CoInternetCompareUrl(string pwzUrl1, string pwzUrl2, uint dwFlags);
[DllImport("urlmon.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern uint CoInternetGetSecurityUrl(string pwzUrl, out IntPtr ppwzSecUrl, uint dwReserved);
[DllImport("urlmon.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern uint CoInternetGetSessionOption(uint dwOption, IntPtr pBuffer, uint dwBufferLength, out uint pdwBufferLength, uint dwReserved);
[DllImport("urlmon.dll", CharSet = CharSet.Unicode, SetLastError = true)] private static extern uint CoInternetSetSessionOption(uint dwOption, IntPtr pBuffer, uint dwBufferLength <---- Bing 回答はここで途切れている
|