Windows Scripting
  Home arrow Windows Scripting arrow Page 4 - Workarounds for Common Dialogs in WSH
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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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

Workarounds for Common Dialogs in WSH
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2007-04-25

    Table of Contents:
  • Workarounds for Common Dialogs in WSH
  • Useful alternatives
  • The Browse For Folder dialog
  • Using the Browse For Folder dialog

  • 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


    Workarounds for Common Dialogs in WSH - Using the Browse For Folder dialog


    (Page 4 of 4 )

    The Browse For Folder dialog is a part of Internet Explorer (shdocvw.dll) but is accessed through the Windows Shell.  So after defining your constants, you’ll need to connect to Shell.Application.

    Const WINDOW_HANDLE = 0

    Const SHOW_EDITBOX = &H0010

    Const VALIDATION = &H0020

    Const DESKTOP = 0

    Set objShell = CreateObject("Shell.Application")

    Set objFolder = objShell.BrowseForFolder(WINDOW_HANDLE, _

       "Please select a folder", _

       SHOW_EDITBOX + VALIDATION, DESKTOP)

    If objFolder Is Nothing Then

       WScript.Echo ""

    Else

       WScript.Echo objFolder.Self.Path

    End If

    Here you can see the Browse For Folder dialog in action.  After connecting to the Shell object, call its BrowseForFolder method to open the dialog.  Now, here’s where it gets a little tricky.  There are a lot of parameters to contend with.

    The first parameter is used to attach the dialog to a specific window handle.  This is not possible in WSH so this value will always be set to 0.

    The second option is the text prompt that appears as the dialog box’s caption.  It accepts a simple text string.

    The third parameter sets the style and functionality of the box.  It can accept a combination of preset hex values.  Remember that hex values are a numeric type and should be combined using a plus sign.

    In the example above, I’ve instructed the box to show an edit box where the user can manually enter a path.  I’ve also included the VALIDATE option which forces the dialog box to validate any entry before allowing the user to click the OK button.

    The final parameter is used to set what folder is displayed when the dialog box opens.  Be very careful when setting this folder.  The user will not be able to browse above this directory.

    Once you have all of the pieces in place you’re all set.  If the user presses the Cancel button, the dialog returns Nothing.  In any other case it returns the folder’s shell namespace object.

    Finally you can access the Self sub-object and use its Path property to return a string.

    I’ve given you a lot of different ways to add dialogs to your scripts.  Choose the method or methods that suit your needs the best based on ease of use and flexibility.  Play around with all of them and see what they have to offer.  Until next time, keep coding!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · In the second part of this series I show you some common workarounds for using...
       · This workaround for the common dialogs was very useful, thanks a lot.Don't you...
       · Thanks for reading the article, I'm glad you enjoyed. To answer your question, I...
     

    WINDOWS SCRIPTING ARTICLES

    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH
    - Advanced Word Object Scripting
    - Reading and Printing Word Documents in WSH
    - Scripting Microsoft Word
    - Using WSH to Catalog MP3 Files
    - Reading MP3 ID3 Tags in WSH
    - A Brief Look at Menus in WPF
    - More Examples of Simplified Image Processing...
    - Completing a WPF To-Do List Application
    - Simplified Image Processing in GDI+





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT