Windows Scripting
  Home arrow Windows Scripting arrow Page 4 - 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  
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

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 - Watch it in action


    (Page 4 of 4 )

    Let's take a look at the IE object's File Open dialog in action.  We'll use it to make a backup copy of a file.  The file will be copied to the same directory with a BAK extension.

    WScript.Echo "Please select the file you would like to copy."

    Set objIE = CreateObject("InternetExplorer.Application")

    objIE.Navigate("about:blank")

    Do While objIE.ReadyState <> 4

       WScript.Sleep 1

    Loop

    objIE.Document.Write("<html><body><input id=field " _

       & "type=file></body></html>")

    objIE.Document.all.field.focus

    objIE.Document.all.field.click

    strFile = objIE.Document.all.field.value

    objIE.Quit

    Set objFso = CreateObject("Scripting.FileSystemObject")

    Set objFile = objFso.GetFile(strFile)

    objFile.Copy(objFile.Path & ".bak")

    WScript.Echo "Backup completed."

    This is a pretty basic script.  The IE Object's File Open dialog returns a file path.  We use that file path along with the FileSystemObject's GetFile method to create a File object and make a copy of it.

    I also decided to show a different looping method for checking if Internet Explorer is busy.  I've replaced the Do Until...Loop with its converse Do While...Loop.

    Let's take a look at another example.  In this example, we'll use the File Open Dialog to choose a file.  Then we'll create a shortcut on the Desktop to that file.

    WScript.Echo "Please select a file to make a shortcut to."

    Set objIE = CreateObject("InternetExplorer.Application")

    objIE.Navigate("about:blank")

    While objIE.ReadyState <> 4

       WScript.Sleep 1

    Wend

    objIE.Document.Write("<html><body><input id=field " _

       & "type=file></body></html>")

    objIE.Document.all.field.focus

    objIE.Document.all.field.click

    strFile = objIE.Document.all.field.value

    objIE.Quit

    Set WshShell = CreateObject("WScript.Shell")

    With WshShell

       strPath = .ExpandEnvironmentStrings("%homepath%DesktopTest.lnk")

       Set WshShortcut = .CreateShortcut(strPath)

    End With

    With WshShortcut

       .Description = "Test Shortcut"

       .TargetPath = strFile

       .Save

    End With

    Now I've taken the result of the Open dialog box and used the file path to create a Desktop shortcut to the file.  I've implemented the WshShell object coupled with its WshShortcut object to do the dirty work.

    I've also changed up the looping scheme again replacing the Do While...Loop with a While...Wend loop.  I've also used the With statement to shorten things up a bit and save myself some typing.

    I've shown you how to implement Microsoft's Common Dialog control to present a more user-friendly script.  As I've stated, these methods each have their own drawbacks.  Be sure to stick around for part two of this series when I show you some more viable alternatives.  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.

       · 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

    - 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 5 hosted by Hostway
    Stay green...Green IT