1

This script (a modification of one of Rob van der Woude's) works fine on XP 32-bit, but fails on 7 64-bit at Set objDialog = CreateObject( "UserAccounts.CommonDialog" ), with something similar to the error (translated from Dutch) ActiveX cannot create the object "UserAccounts.CommonDialog". Is there some different way that I have to do this for it to be compatible with Windows 7?

MsgBox("Your input avi MUST be 60fps, or this script will not work."),0,"IMPORTANT!"

MsgBox("Please select the location of your AVI."),0,"AVI location"

WScript.Echo GetFileName( "", "AVI files (*.avi)|*.avi" )

Function GetFileName( myDir, myFilter )

    Dim objDialog
    Set objDialog = CreateObject( "UserAccounts.CommonDialog" )
    If myDir = "" Then
        objDialog.InitialDir = CreateObject( "WScript.Shell" ).SpecialFolders( "MyDocuments" )
    Else
        objDialog.InitialDir = myDir
    End If
    If myFilter = "" Then
        objDialog.Filter = "All files|*.*"
    Else
        objDialog.Filter = myFilter
    End If

    If objDialog.ShowOpen Then
        GetFileName = objDialog.FileName
    Else
        GetFileName = ""
    End If
End Function
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Matthieu Cartier
  • 2,361
  • 4
  • 17
  • 15
  • Do you have an error code for the CreateObject failure? – Rob Perkins Jan 06 '11 at 21:51
  • Possible duplicate of [How can I use the common Save As dialog from VBScript?](http://stackoverflow.com/questions/4386124/how-can-i-use-the-common-save-as-dialog-from-vbscript) – techie007 Oct 03 '16 at 19:01

2 Answers2

3

There is some evidence online that "UserAccounts.CommonDialog" was not supplied with Windows Vista (and thus, Windows 7).

See, for example, http://www.msghelp.net/showthread.php?tid=88579

The final entry in that thread suggests the use of MSComDlg.CommonDialog, with some caveats, or use the GetOpenFileName API.

If that's not it, then examine your registry, and inspect the script's actions in ProcMon at the point it executes CreateObject. You may have a "bitness" problem, where your script is running in a 64-bit process but attempting to access a 32-bit COM object. If that's the case, you're going to see an error at CreateObject("WScript.Shell") as well.

Rob Perkins
  • 3,088
  • 1
  • 30
  • 51
  • @David Heffernan, @ neurolysis: *Part* of this is correct... You can't call native Windows API functions directly from VBScript, so `GetOpenFileName` is not going to work. There's no "bitness" problem, the `UserAccounts.CommonDialog` was simply an ugly hack that only worked in Windows XP. `MSComDlg.CommonDialog` isn't really a good solution either. A question attempting to solve the root problem was asked and answered a while back: [How can I use the common Save As dialog from VBScript?](http://stackoverflow.com/questions/4386124/how-can-i-use-the-common-save-as-dialog-from-vbscript). – Cody Gray - on strike Jan 11 '11 at 13:21
0

Perhaps you need to re-register the comdlg32.dll? Reference

xXhRQ8sD2L7Z
  • 1,686
  • 1
  • 14
  • 16