Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invoking Visual Basic Exe from HTML 1

Status
Not open for further replies.

kuttapan

Programmer
Jan 27, 2005
11
US
Hello All,

I wrote a simple Visual Basic Active X Exe which would be invoked from a normal HTML Page. The idea was to invoke the Visual Basic application with values entered from HTML page.

The process worked fine. The question I have now is when i click on the Button on the html page that invokes the VB app, I get a warning
"An ActiveX control on this page might be unsafe to interact with other parts of the page. Do you want to allow this interaction?"
This comes the first time i invoke the VB app and then it works fine. Everytime i open the HTML new this comes up. Is there any way I can eliminate this message so that my VB App comes up directly? I am using IE 6.0

Responses will be really appreciated.

Thanks for your time,
Kuttapan

 
You need to mark your control safe for initialization and scripting.
This can be done in two ways.

1. Implement the IObjectSafety interface.
See How To Implement IObjectSafety in Visual Basic Controls

2. Add appropriate component category entries in the regisrty.

Microsoft recommend the first method explained in the above article.
However, the second method is easier to implement. Follow these steps.

1. Open Registry Editor.

2. Locate the ProgId of your ActiveX EXE project under HKEY_CLASSES_ROOT.
HKEY_CLASSES_ROOT\YourProject.YourClass

3. Locate the Clsid key and see its default value which is the actual Class Id. Make a note of this class Id.
HKEY_CLASSES_ROOT\YourProject.YourClass\Clsid > (Default Value)

4. Now locate your class Id under the key HKEY_CLASSES_ROOT\CLSID.
HKEY_CLASSES_ROOT\CLSID\{Your-Class-id}

5. Expand the above key and create two new keys under the subkey Implemented Categories, as below.

HKEY_CLASSES_ROOT\CLSID\{Your-Class-id}\Implemented Categories\{7DD95801-9882-11CF-9FA9-00AA006C42C4}

HKEY_CLASSES_ROOT\CLSID\{Your-Class-id}\Implemented Categories\{7DD95802-9882-11CF-9FA9-00AA006C42C4}

6. Close Registry Editor.

From now on, you should not see these security warning messages when you invoke or access your ActiveX component from Internet Explorer.
 
Or you could just turn it off for your entire browser.

This is probably not wise but it is effective:

Tools -> Internet Options -> Security -> Custom Level

Enable: Initialise and Script ActiveX Controls not marked as Safe


Just because you can, doesn't mean you should.
 
Thanks Hypetia. I edited the Registry and it worked just fine!

I will try this out in the real world and let know if all went well. Thanks Again!


 
If you have a lot of users maybe you could make a .reg file that they could just download and double-click to make the reg edits.
 
Hypetia: Good answer! I'm emailing this thread to myself for reference. You get a star!


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Hello,
Yeah Hypetia, you really need a star! That was really good solution as compared to disabling the browser that would meddle with other pages.
Sheco, you spoke of a .reg file. I am not sure how to create a .reg file that would automatically update the registry contents for each user. Could anyone give me useful idea of how to create a .reg file that will automatically udpate the registry? Thanks
 
Locate the registry keys you created in the registry editor.
HKEY_CLASSES_ROOT\CLSID\{Your-Class-Id}\Implemented Categories\{7DD95801-9882-11CF-9FA9-00AA006C42C4}

Goto File menu and choose Export. Regedit will create the .reg file itself, containing the selected entry.

You need to edit the file and also add the entry for the second key {7DD95802-9882-11CF-9FA9-00AA006C42C4} you created. The .reg file is a plain text file with a simple format.

After you finish, you can take this .reg file to another PC and choose to merge these registry entries by double-clicking the file.

Another nice option is to add code to your Active EXE program to create these entries programmatically using registry API functions. This will ensure that when you run your ActiveX EXE first time on a PC, it marks itself safe automatically instead of depending upon you or a .reg file.

See the code below, which does the same, not using the registry API functions, but Windows Scripting Host.
___
[tt]
Sub MarkComponentSafe(ProgId As String)
Dim ClsId As String
On Error Resume Next
With CreateObject("WScript.Shell")
ClsId = .RegRead("HKEY_CLASSES_ROOT\" & ProgId & "\Clsid\")
If Len(ClsId) Then
.RegWrite "HKEY_CLASSES_ROOT\CLSID\" & ClsId & "\Implemented Categories\{7DD95801-9882-11CF-9FA9-00AA006C42C4}\", "Safe for scripting"
.RegWrite "HKEY_CLASSES_ROOT\CLSID\" & ClsId & "\Implemented Categories\{7DD95802-9882-11CF-9FA9-00AA006C42C4}\", "Safe for initialization"
End If
End With
End Sub[/tt]
___

You can use it like this.

[tt]MarkComponentSafe "MyProject.MyClass"[/tt]

and the function will create all the necessary keys in the registry.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top