You can create a simple network component that provides a COM interface , so you can use it in VBScript (or any COM / ActiveX > based technology).
- (1) Create a project of type net net library, output the classes that you want to use in COM compatibility (add the ComVisible and ClassInterface attributes ). The ClassInterface attribute must be set to AutoDual so that you can instantiate by late binding.
- (2) check the box to register COM compatibility on the assembly tab in the project properties dialog box.
- (3) create a project so that the component can be registered correctly (you have the opportunity to create a configuration project for your component so that it can be easily deployed).
...
namespace WinUtility { [ComVisible(true), Guid("32284FD3-417E-45fc-A4A0-9344C489053B"), ClassInterface(ClassInterfaceType.AutoDual)] public class WinDialog { public string ShowOpenFileDialog() { string result = string.Empty; OpenFileDialog d = new OpenFileDialog(); if (d.ShowDialog() == DialogResult.OK) { result = d.FileName; } return result; } } }
Once your component is registered, you can create it from VBScript:
dim wnd_helper, file_name Set wnd_helper = CreateObject("WinUtility.WinDialog") file_name = wnd_helper.ShowOpenFileDialog() if trim(file_name) <> "" then msgbox "file: " + file_name else msgbox "No file selected." end if
source share