public class Constants
{
public const int MAX_PATH = 260;
public const int MAX_ZONE_PATH = 260;
public const int MAX_ZONE_DESCRIPTION = 200;
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct ZONEATTRIBUTES
{
public uint cbSize;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = Constants.MAX_PATH)]
public string szDizplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = Constants.MAX_ZONE_DESCRIPTION)]
public string szDescription;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = Constants.MAX_PATH)]
public string szIconPath;
public uint dwTemplateMinLevel;
public uint dwTemplateRecommended;
public uint dwTemplateCurrentLevel;
public uint dwFlags;
}
public enum URLZONEREG
{
URLZONEREG_DEFAULT = 0,
URLZONEREG_HKLM,
URLZONEREG_HKCU
}
[Guid("79eac9ef-baf9-11ce-8c82-00aa004ba90b")]
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInternetZoneManager
{
void GetZoneAttributes(uint dwZone, ref ZONEATTRIBUTES pZoneAttributes);
void SetZoneAttributes(uint dwZone, ref ZONEATTRIBUTES pZoneAttributes);
void GetZoneCustomPolicy(uint dwZone, [In] ref Guid guidKey, ref IntPtr ppPolicy,
ref uint pcbPolicy, URLZONEREG urlZoneReg);
void SetZoneCustomPolicy(uint dwZone, [In] ref Guid guidKey, IntPtr pPolicy,
uint pcbPolicy, URLZONEREG urlZoneReg);
void GetZoneActionPolicy(uint dwZone, uint dwAction, IntPtr pPolicy, uint cbPolicy,
URLZONEREG urlZoneReg);
void SetZoneActionPolicy(uint dwZone, uint dwAction, IntPtr pPolicy, uint cbPolicy,
URLZONEREG urlZoneReg);
void PromptAction(uint dwAction, IntPtr hwndParent, [MarshalAs(UnmanagedType.LPWStr)] string pwszUrl,
[MarshalAs(UnmanagedType.LPWStr)] string pwszText, uint dwPromptFlags);
void LogAction(uint dwAction, [MarshalAs(UnmanagedType.LPWStr)] string pwszUrl,
[MarshalAs(UnmanagedType.LPWStr)] string pwszText, uint dwLogFlags);
void CreateZoneEnumerator(ref uint pdwEnum, ref uint pdwCount, uint dwFlags);
void GetZoneAt(uint dwEnum, uint dwIndex, ref uint pdwZone);
void DestroyZoneEnumerator(uint dwEnum);
void CopyTemplatePoliciesToZone(uint dwTemplate, uint dwZone, uint dwReserved);
}
Public Class Constants
Public Const MAX_PATH = 260
Public Const MAX_ZONE_PATH = 260
Public Const MAX_ZONE_DESCRIPTION = 200
End Class
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure ZONEATTRIBUTES
Public cbSize As UInt32
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=Constants.MAX_PATH)>
Public szDizplayName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=Constants.MAX_ZONE_DESCRIPTION)>
Public szDescription As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=Constants.MAX_PATH)>
Public szIconPath As String
Public dwTemplateMinLevel As UInt32
Public dwTemplateRecommended As UInt32
Public dwTemplateCurrentLevel As UInt32
Public dwFlags As UInt32
End Structure
Public Enum URLZONEREG
URLZONEREG_DEFAULT
URLZONEREG_HKLM
URLZONEREG_HKCU
End Enum
None.
Note that the methods in the interface declaration must appear in the same order as they do in the COM interface, as declared in urlmon.h. That header file also contains some other goodies such as URLZONE values, URLACTION values, etc.
You will probably also want to create an instance of InternetZoneManager and cast it to to the above IInternetZoneManager:
[ComImport, GuidAttribute("7b8a2d95-0ac9-11d1-896c-00c04Fb6bfc4")]
public class InternetZoneManager { }
// ----------- USAGE (error handling omitted): -------------
IInternetZoneManager zoneMgr = (IInternetZoneManager)new InternetZoneManager();