Does the VBScript file open dialog open that works in XP and Vista?

In XP, you can use VBScript with the UserAccounts.CommonDialog object to open the file open dialog ( as described here ), but apparently this does not work in Vista .

Is there a VBScript way for File-Open dialogs that will work for both?

Or even one that works great for Vista?

Disclaimer: I am a good programmer, honest and usually do not work with VBScript - I ask this question “for a friend”.

+4
source share
1 answer

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 
+1
source

Source: https://habr.com/ru/post/1307051/


All Articles