-
February 7th, 2008, 03:33 AM
#1
Problem in Adding URL in Trusted Zone
Hi,
I am trying to run code from the follwoing link to add an url in trusted security zones.
http://www.codeguru.com/forum/showthread.php?t=368335
Code given by CorithMalin
here in visual studio, i am creating win32 console application.
i am unable to run this code. It is asking for /clr for compilation. I have changed the project properties and gave clr option.
now I am getting clr option is incompatible for this project.
could any one running successfully this code...please help me..
its very urgent to me.... pleaseeeee
-
February 7th, 2008, 11:18 PM
#2
Re: Problem in Adding URL in Trusted Zone
Nothing in those code snippets need .Net. Have you tried with the following removed ?
Code:
using namespace System;
using namespace System::Runtime::InteropServices;
-
February 7th, 2008, 11:47 PM
#3
Re: Problem in Adding URL in Trusted Zone
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace SetSecurityZone
{
public class Program
{
static void Main(string[] args)
{
const UInt32 URLZONE_LOCAL_MACHINE = 0;
const UInt32 URLZONE_INTRANET = URLZONE_LOCAL_MACHINE + 1;
const UInt32 URLZONE_TRUSTED = URLZONE_INTRANET + 1;
const UInt32 URLZONE_INTERNET = URLZONE_TRUSTED + 1;
const UInt32 URLZONE_UNTRUSTED = URLZONE_INTERNET + 1;
//const UInt32 URLZONE_ESC_FLAG = 0x100;
const UInt32 SZM_CREATE = 0x00000000;
const UInt32 SZM_DELETE = 0x00000001;
Guid CLSID_InternetSecurityManager = new Guid("7b8a2d94-0ac9-11d1-896c-00c04fb6bfc4");
Guid IID_IInternetSecurityManager = new Guid("79eac9ee-baf9-11ce-8c82-00aa004ba90b");
IInternetSecurityManager _ism; // IInternetSecurityManager interface of ecurityManager COM object
object _securityManager;
Type t = Type.GetTypeFromCLSID(CLSID_InternetSecurityManager);
_securityManager = Activator.CreateInstance(t);
_ism = (IInternetSecurityManager)_securityManager;
string st="*.co.isc.com";
// int result = _ism.SetZoneMapping(URLZONE_UNTRUSTED, st,SZM_CREATE);
int result = _ism.SetZoneMapping(URLZONE_TRUSTED, st, SZM_CREATE);
System.Console.WriteLine("\n \n Result value " + result);
if (result.Equals(0))
{
System.Console.WriteLine("Pattern \"" + st + "\" successfully added to " + " zone.");
}
else
{
System.Console.WriteLine("Could not add pattern \"" + st + "\" to " + " zone.");
}
System.Console.ReadLine();
}
}
[ComImport, GuidAttribute("79EAC9EE-BAF9-11CE-8C82-00AA004BA90B"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInternetSecurityManager
{
[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int SetSecuritySite([In] IntPtr pSite);
[return: MarshalAs(UnmanagedType.I4)][PreserveSig]
int GetSecuritySite([Out] IntPtr pSite);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int MapUrlToZone([In, MarshalAs(UnmanagedType.LPWStr)] string pwszUrl, out UInt32 pdwZone, UInt32 dwFlags);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int GetSecurityId([MarshalAs(UnmanagedType.LPWStr)] string pwszUrl, [MarshalAs(UnmanagedType.LPArray)] byte[] pbSecurityId, ref UInt32 pcbSecurityId, uint dwReserved);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int ProcessUrlAction([In, MarshalAs(UnmanagedType.LPWStr)] string pwszUrl, UInt32 dwAction, out byte pPolicy, UInt32 cbPolicy, byte pContext, UInt32 cbContext, UInt32 dwFlags, UInt32 dwReserved);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int QueryCustomPolicy([In, MarshalAs(UnmanagedType.LPWStr)] string pwszUrl, ref Guid guidKey, ref byte ppPolicy, ref UInt32 pcbPolicy, ref byte pContext, UInt32 cbContext, UInt32 dwReserved);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int SetZoneMapping(UInt32 dwZone, [In, MarshalAs(UnmanagedType.LPWStr)] string lpszPattern, UInt32 dwFlags);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int GetZoneMappings(UInt32 dwZone, out UCOMIEnumString ppenumString, UInt32 dwFlags);
}
}
The above code is working fine for adding urls in UNTRUSTED ZONE...
But while adding in TRUSTED ZONES, the variable result value -2147024891 is printing...
Could resolve this problem...where I am wrong??
-
February 8th, 2008, 12:12 AM
#4
Re: Problem in Adding URL in Trusted Zone
#include "windows.h"
#include "stdafx.h"
#include "urlmon.h"
#using <mscorlib.dll>
#include <atldef.h>
#include <atlconv.h>
using namespace System;
using namespace System::Runtime::InteropServices;
#define MAX_LOADSTRING 100
int _tmain(int argc, _TCHAR* argv[])
{
// constants from urlmon.h
const int URLZONE_LOCAL_MACHINE = 0;
const int URLZONE_INTRANET = URLZONE_LOCAL_MACHINE + 1;
const int URLZONE_TRUSTED = URLZONE_INTRANET + 1;
const int URLZONE_INTERNET = URLZONE_TRUSTED + 1;
const int URLZONE_UNTRUSTED = URLZONE_INTERNET + 1;
//const int URLZONE_ESC_FLAG = 0x100;
const int SZM_CREATE = 0x0;
const int SZM_DELETE = 0x1;
HRESULT hr;
IInternetSecurityManager *pSecurityMgr;
LPCWSTR sites = SysAllocString(L"*.mydomain.com");
CoInitialize(NULL);
hr = CoCreateInstance(CLSID_InternetSecurityManager, NULL, CLSCTX_INPROC_SERVER, IID_IInternetSecurityManager, (void**)&pSecurityMgr);
pSecurityMgr->SetZoneMapping(URLZONE_TRUSTED, sites, SZM_CREATE);
pSecurityMgr->Release();
return 0;
}
hi Kirants.... thanks for ur help...
One more issue... here the above code is running fine...
but I could not see d added url in the following location...
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains
Please tell me d solution.......
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|