PrivacyGetZonePreference

Share your advanced PureBasic knowledge/code with the community.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

PrivacyGetZonePreference

Post by SFSxOI »

Nothing really earth shattering super-duper gee whiz, but I got bitten a little today while profiling a bot net varient at work and whipped this up real quick to monitor with when I realized what was happening, basic code below. Simply gets the Privacy Zone setting in Internet Explorer Internet Options on the Privacy Tab. Like I said, nothing earth shattering super-duper gee whiz but someone might use it for something. Tested with Windows 7 x86 only, PB 4.60.

Code: Select all

; privacy zone
Enumeration ; tag#URLZONE
  #URLZONE_INVALID          = -1
  #URLZONE_PREDEFINED_MIN   = 0
  #URLZONE_LOCAL_MACHINE    = 0
  #URLZONE_INTRANET
  #URLZONE_TRUSTED
  #URLZONE_INTERNET
  #URLZONE_UNTRUSTED
  #URLZONE_PREDEFINED_MAX   = 999
  #URLZONE_USER_MIN         = 1000
  #URLZONE_USER_MAX         = 10000
EndEnumeration

; privacy type
#PRIVACY_TYPE_FIRST_PARTY = 0 ; Refers To privacy settings For first party cookies
#PRIVACY_TYPE_THIRD_PARTY = 1 ; Refers To privacy settings For third party cookies.

; privacy template
#PRIVACY_TEMPLATE_NO_COOKIES = 0 ;This is the same As Block All Cookies on the Privacy Preferences slider bar in Internet Options.
#PRIVACY_TEMPLATE_HIGH = 1 ; This is the same As High on the Privacy Preferences slider bar in Internet Options.
#PRIVACY_TEMPLATE_MEDIUM_HIGH = 2 ;This is the same As Medium_High on the Privacy Preferences slider bar in Internet Options.
#PRIVACY_TEMPLATE_MEDIUM = 3 ; This is the same As Medium on the Privacy Preferences slider bar in Internet Options.
#PRIVACY_TEMPLATE_MEDIUM_LOW = 4 ;This is the same As Low on the Privacy Preferences slider bar in Internet Options.
#PRIVACY_TEMPLATE_LOW = 5 ; This is the same As Accept All Cookies on the Privacy Preferences slider bar in Internet Options.
#PRIVACY_TEMPLATE_CUSTOM = 100 ; User-defined. See How To Create a Customized Privacy Import File To understand how To set custom privacy settings.
#PRIVACY_TEMPLATE_ADVANCED = 101 ; User-defined. Advanced options are set in the Advanced Privacy Settings dialog reachable from the Privacy tab in Internet Options.
#PRIVACY_TEMPLATE_MAX = #PRIVACY_TEMPLATE_LOW ; Same As #PRIVACY_TEMPLATE_LOW.

Procedure.s PrivacyGetZonePreferenceW(dwZone, dwType)
  Protected pdwTemplate.i

  Lib_PrivacyGetZonePreferenceW = LoadLibrary_("Wininet.dll")
  
  *Func_PrivacyGetZonePreferenceW = GetProcAddress_(Lib_PrivacyGetZonePreferenceW, "PrivacyGetZonePreferenceW")
  RetVal.i = CallFunctionFast(*Func_PrivacyGetZonePreferenceW,dwZone, dwType, @pdwTemplate, #Null, #Null)
  FreeLibrary_(Lib_PrivacyGetZonePreferenceW)
  
  If RetVal <> 0
    ProcedureReturn "Error getting Internet Privacy Zone Preference = " + Str(RetVal)
  Else
    
    Select pdwTemplate
        Case 0
          ProcedureReturn "Internet Privacy Zone Preference = Block All Cookies (0)"
        Case 1
          ProcedureReturn "Internet Privacy Zone Preference = High (1)"
        Case 2
          ProcedureReturn "Internet Privacy Zone Preference = Medium High (2)"
        Case 3
          ProcedureReturn "Internet Privacy Zone Preference = Medium (3)"
        Case 4
          ProcedureReturn "Internet Privacy Zone Preference = Medium Low (4)"
        Case 5
          ProcedureReturn "Internet Privacy Zone Preference = Low (5)"
        Case 100
          ProcedureReturn "Internet Privacy Zone Preference = User Defined (100)"
        Case 101
          ProcedureReturn "Internet Privacy Zone Preference = User Defined (101) Advanced options set in Advanced Privacy Settings dialog on Privacy tab in Internet Options"
        Default
          ProcedureReturn "Default setting - Internet Privacy Zone Preference = Low (5)"
      EndSelect
  
  EndIf
  
EndProcedure

Debug PrivacyGetZonePreferenceW(#URLZONE_INTERNET, #PRIVACY_TYPE_THIRD_PARTY)
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.