White Eagle
New member
- Joined
- Jan 13, 2009
- Messages
- 3
- Programming Experience
- 5-10
I am trying to develop an ActiveX control for deployment on remote machines.
The control gets downloaded OK but does not allow scripts to be run.
This is the code for the control:
Imports System.Runtime.InteropServices
<Guid("08B10D76-780A-481E-B08C-58B26DBC9AE3"), _
ComImport(), _
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IObjectSafety
<PreserveSig()> _
Function GetInterfaceSafetyOptions(ByRef riid As Guid, _
<MarshalAs(UnmanagedType.U4)> ByRef pdwSupportedOptions As Integer, _
<MarshalAs(UnmanagedType.U4)> ByRef pdwEnabledOptions As Integer) As Integer
<PreserveSig()> _
Function SetInterfaceSafetyOptions(ByRef riid As Guid, _
<MarshalAs(UnmanagedType.U4)> ByVal dwOptionSetMask As Integer, _
<MarshalAs(UnmanagedType.U4)> ByVal dwEnabledOptions As Integer) As Integer
End Interface
<ComClass(Synch.ClassId)> _
Public Class Synch
Implements IObjectSafety
Public Const ClassId As String = "F37755B8-C1BA-48db-B817-666DCBD620AB"
Public Const INTERFACESAFE_FOR_UNTRUSTED_CALLER = &H1
Public Const INTERFACESAFE_FOR_UNTRUSTED_DATA = &H2
Public Function GetInterfaceSafetyOptions(ByRef riid As System.Guid, ByRef pdwSupportedOptions As Integer, ByRef pdwEnabledOptions As Integer) As Integer Implements IObjectSafety.GetInterfaceSafetyOptions
Dim sGUID As String = riid.ToString("B")
pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER Or _
INTERFACESAFE_FOR_UNTRUSTED_DATA
Return 0
End Function
Public Function SetInterfaceSafetyOptions(ByRef riid As System.Guid, ByVal dwOptionSetMask As Integer, ByVal dwEnabledOptions As Integer) As Integer Implements IObjectSafety.SetInterfaceSafetyOptions
Return 0
End Function
Public Sub New()
MyBase.New()
End Sub
Private m_sParam As String = String.Empty
Private m_xSafeForScripting As Boolean
Private m_xSafeForInitializing As Boolean
Public Property Param() As String
Get
Return m_sParam
End Get
Set(ByVal value As String)
m_sParam = value
End Set
End Property
Public Sub RunSynch(ByVal v_sProductName As String, ByVal v_sExeName As String)
' This is the public procedure that is called from web app
' (code not included).
End Sub
In the assembly information window of the project I have checked Make assembly COM-visible.
On the compile tab of the project I have checked Register for COM interop.
I have created a deployment project where the primary output is the DLL for the control and the register property is set as vsdrpCOM.
This is my .INF file:
[version]
signature="$CHICAGO$"
AdvancedINF=2.0
[Setup Hooks]
hook1=hook1
[hook1]
run=msiexec.exe /i "%EXTRACT_DIR%\AMSSynchLocaldeploy.msi" /qn
I build a CAB file from the msi file and the inf file. The CAB file is signed with a Verisign certificate.
On the web page, the control is defined as:
<object id="Object1" name="myControl1" classid="clsid:F37755B8-C1BA-48db-B817-666DCBD620AB" style="display:none"
codebase="AMS_synchLocal.CAB#version=1,0,0,0" viewastext >
<span style="color:red">ActiveX control failed to load!
</span>
</object>
The control is used in the we page as follows:
<script language="javascript" type="text/javascript">
function doScript()
{
// Check if ActiveX is installed
try{
document.myControl1.RunSynch(93,"MCSE0B","8128F97E-8452-465C-887C-102C5420BF04");
lblDir.innerHTML=document.myControl1.Param;
alert('Ready');
}
catch(ex)
{
alert('Failed - ' + ex);
}
}
</script>
The control gets registered OK, and if the IE option is set to enable ActiveX controls not marked scripts to run it is OK, so why is it not marked as safe?
Any suggestions as to what is wrong?
The control gets downloaded OK but does not allow scripts to be run.
This is the code for the control:
Imports System.Runtime.InteropServices
<Guid("08B10D76-780A-481E-B08C-58B26DBC9AE3"), _
ComImport(), _
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IObjectSafety
<PreserveSig()> _
Function GetInterfaceSafetyOptions(ByRef riid As Guid, _
<MarshalAs(UnmanagedType.U4)> ByRef pdwSupportedOptions As Integer, _
<MarshalAs(UnmanagedType.U4)> ByRef pdwEnabledOptions As Integer) As Integer
<PreserveSig()> _
Function SetInterfaceSafetyOptions(ByRef riid As Guid, _
<MarshalAs(UnmanagedType.U4)> ByVal dwOptionSetMask As Integer, _
<MarshalAs(UnmanagedType.U4)> ByVal dwEnabledOptions As Integer) As Integer
End Interface
<ComClass(Synch.ClassId)> _
Public Class Synch
Implements IObjectSafety
Public Const ClassId As String = "F37755B8-C1BA-48db-B817-666DCBD620AB"
Public Const INTERFACESAFE_FOR_UNTRUSTED_CALLER = &H1
Public Const INTERFACESAFE_FOR_UNTRUSTED_DATA = &H2
Public Function GetInterfaceSafetyOptions(ByRef riid As System.Guid, ByRef pdwSupportedOptions As Integer, ByRef pdwEnabledOptions As Integer) As Integer Implements IObjectSafety.GetInterfaceSafetyOptions
Dim sGUID As String = riid.ToString("B")
pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER Or _
INTERFACESAFE_FOR_UNTRUSTED_DATA
Return 0
End Function
Public Function SetInterfaceSafetyOptions(ByRef riid As System.Guid, ByVal dwOptionSetMask As Integer, ByVal dwEnabledOptions As Integer) As Integer Implements IObjectSafety.SetInterfaceSafetyOptions
Return 0
End Function
Public Sub New()
MyBase.New()
End Sub
Private m_sParam As String = String.Empty
Private m_xSafeForScripting As Boolean
Private m_xSafeForInitializing As Boolean
Public Property Param() As String
Get
Return m_sParam
End Get
Set(ByVal value As String)
m_sParam = value
End Set
End Property
Public Sub RunSynch(ByVal v_sProductName As String, ByVal v_sExeName As String)
' This is the public procedure that is called from web app
' (code not included).
End Sub
In the assembly information window of the project I have checked Make assembly COM-visible.
On the compile tab of the project I have checked Register for COM interop.
I have created a deployment project where the primary output is the DLL for the control and the register property is set as vsdrpCOM.
This is my .INF file:
[version]
signature="$CHICAGO$"
AdvancedINF=2.0
[Setup Hooks]
hook1=hook1
[hook1]
run=msiexec.exe /i "%EXTRACT_DIR%\AMSSynchLocaldeploy.msi" /qn
I build a CAB file from the msi file and the inf file. The CAB file is signed with a Verisign certificate.
On the web page, the control is defined as:
<object id="Object1" name="myControl1" classid="clsid:F37755B8-C1BA-48db-B817-666DCBD620AB" style="display:none"
codebase="AMS_synchLocal.CAB#version=1,0,0,0" viewastext >
<span style="color:red">ActiveX control failed to load!
</span>
</object>
The control is used in the we page as follows:
<script language="javascript" type="text/javascript">
function doScript()
{
// Check if ActiveX is installed
try{
document.myControl1.RunSynch(93,"MCSE0B","8128F97E-8452-465C-887C-102C5420BF04");
lblDir.innerHTML=document.myControl1.Param;
alert('Ready');
}
catch(ex)
{
alert('Failed - ' + ex);
}
}
</script>
The control gets registered OK, and if the IE option is set to enable ActiveX controls not marked scripts to run it is OK, so why is it not marked as safe?
Any suggestions as to what is wrong?