GetSecurityZone Method  
 

Returns the security zone identifier for the specified resource.

Syntax

object.GetSecurityZone( FileUrl )

Parameters

FileUrl
A string that specifies the resource URL to check. This parameter must use the http://, https:// or file:// schemes. This method will not accept URLs for other schemes such as ftp:// or sftp://. While this method does not verify that the resource exists, it does require the URL to be syntatically valid. If the host name cannot be resolved to an IPv4 or IPv6 address, the method will return httpZoneNone. If the resource is a local file, it must be a regular file and cannot be the name of a folder or device.

Return Value

An integer value which specifies the security zone for the resource. It may be one of the following values:

Value Description
httpZoneNone The security zone for this resource cannot be determined.
httpZoneLocal The resource is considered to be part of the local computer zone.
httpZoneIntranet The resource originates from the local intranet zone, such as an internal corporate network.
httpZoneTrusted The resource originates from a site in the Trusted Sites zone.
httpZoneInternet The resource originates from the Internet and is treated with caution by Windows.
httpZoneRestricted The resource originates from a site in the Restricted Sites zone, which is used for untrusted content.

Remarks

The GetSecurityZone method is used to determine how a resource should be handled in terms of local security policy before performing a file transfer or download. For example, you may want to determine whether a resource originates from the Internet or local intranet before deciding whether to attach zone metadata, prompt the user, or apply additional security restrictions. It can also be used to implement policy-based rules for accepting or rejecting downloads based on their origin.

If the resource is specified using a file:// URL that refers to a file on a network share (e.g.: file://server/share/file.txt), the method will attempt to access that file across the network. This may cause the application to block while Windows resolves the hostname and establishes a connection to the shared volume. If the network share is unavailable or slow to respond, the method may block until the connection succeeds or the attempt times out.

If this method returns httpZoneNone, this indicates either the resource type is not supported or there was an internal failure when the Internet Security Manager attempted to map the resource URL to a security zone. In most default configurations, this method will return the zone httpZoneInternet for valid URLs unless the host has been explicitly added to the Intranet Zone or Trusted Sites list on the local system.

Security zones are used with Mark of the Web (MOTW) metadata which indicates if a file originated from an external source, such as the Internet or an untrusted network. When a file is downloaded using a web browser or other applications, it may add a Zone.Identifier alternate data stream to the file. This stream contains information such as ZoneId=3, which corresponds to the Internet Zone. Your application can use the GetFileZone method to retrieve this information, which allows you to determine whether a file was downloaded from an external source and what zone Windows has associated with it. This metadata affects how files are handled by Windows security components such as Microsoft Defender, SmartScreen, Office Protected View, and script execution policies in Windows Explorer. If the file has no metadata, it is generally treated as coming from the Local Machine Zone (zone 0). If your application sets or clears this metadata using the SetFileZone method, it can influence how other applications interpret the file's trust level.

It is important to note that this method is used to determine what security zone would be appropriate for a given resource, and it only performs syntactic checks and classification of the URL using the IInternetSecurityManager COM interface. The security zone this method returns is based on the current system and user policy, using zone assignments stored in the registry. Typically this information is managed using Windows settings or Internet options in the control panel. This method does not read the zone identifier metadata which has been assigned to a file.

For more detailed information about the zone identifiers, refer to the ZoneId property.

See Also

ZoneId Property, GetFileZone Method, SetFileZone Method, ValidateUrl Method