Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - User Interaction with Common Dialogs in WS...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

User Interaction with Common Dialogs in WSH
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2007-04-24

    Table of Contents:
  • User Interaction with Common Dialogs in WSH
  • Accessing the Common Dialog control directly
  • Accessing dialogs through other applications
  • Watch it in action

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    User Interaction with Common Dialogs in WSH - Accessing the Common Dialog control directly


    (Page 2 of 4 )

    Using the Microsoft Common Dialogs control is fairly straightforward.  You initialize the object by connecting to its namespace, assign the dialog's attributes, and then call its display method.  Here's a quick example that opens the familiar Open File dialog.

    Set objDlgs = CreateObject("MSComDlg.CommonDialog")

    objDlgs.Filter = "All Files(*.*)|*.*|VBScript Files(*.vbs)|*.vbs"

    objDlgs.FilterIndex = 2

    objDlgs.MaxFileSize = 128

    objDlgs.ShowOpen()

    WScript.Echo objDlgs.FileName

    The Filter property tells the dialog box what to offer in the file types drop-down box.  The FilterIndex property sets the default.

    You must use the MaxFileSize to set the maximum name length or the control will generate an error.

    Finally, a call to the ShowOpen method returns a string containing the file name and path.  And empty string is returned if the user presses the Cancel button.

    Set objDlgs = CreateObject("MSComDlg.CommonDialog")

    objDlgs.Filter = "Text Files(*.txt)|*.txt"

    objDlgs.FilterIndex = 1

    objDlgs.MaxFileSize = 128

    objDlgs.ShowSave()

    WScript.Echo objDlgs.FileName

    The Save dialog works in the exact same way.  The code above opens a Save dialog with the default file type set to Text Files.

    The Common Dialogs control offers many more familiar dialogs that you can implement in your scripts.  Among these are Choose a Color, Choose a Font, and the Print dialog.

    So why am I touching on these so briefly?  Well, because this probably will not work for most of you.  While the Common Dialogs control is installed on every Windows system by default, it is a licensed control.  That means that its functionality is based upon which license is installed on the machine.

    There are two types of licenses: runtime and development.  A runtime license (the default) only allows the common dialogs to be called from software that was written with a development license.  As you can probably guess, to use this control in WSH you would need to have a development license installed on your machine.

    A development license is installed by Visual Basic 6.0, Visual Studio, or Microsoft Office Developer Edition.  So you can only use this control on any machine that has one of those titles installed.  Since this rules out most scenarios, I didn't feel there was much point in spending a lot of time on this.

    Let's take a look at some of the workarounds available that can be used as alternatives to the Common Dialog control.

    More Windows Scripting Articles
    More By Nilpo/Developer Shed Staff Writer


       · Hey, guys. Thanks for joining me again. In this article how show you how to give...
       · Hi,I am regular reader of your articles. Its very informative. Keep...
       · Thanks for reading.Beginning with the basics, this does require Internet...
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek