You can create a simple dot net component that exposes a COM interface, so you can use it in VBScript (or any COM/ActiveX based technology).
- (1) Create a dot net library type project, expose the classes you want to be COM interoperability (adding ComVisible and ClassInterface attributes). The ClassInterface attribute must be set to AutoDual so you can create instances by late binding.
- (2) mark the register for COM interoperability check-box in the build tab from the project properties dialog.
- (3) build the project, so the component can be properly registered (you have the option to create a setup project for your component so 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 instantiate 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