Microsoft® Windows® Script Host
Drag and Drop Support
 WSH Tutorial
Previous
Next


The Windows operating system currently supports drag and drop with batch files. This functionality, which enables you to drag one or more files onto a batch file and then run it with the files as arguments, is now supported in Windows Script Host version 2.0 as well.

When you drag files onto a WSH script, the file names are translated into arguments on the command line. These file names can be displayed in a list, which you can use to manipulate files with any scripting object.

To display a script's argument list

  1. Create a file and give it a name with a .vbs extension (for example, DragDrop.vbs).
  2. Add the following code to the .vbs file:
  3. Set objArgs = WScript.Arguments
    For I = 0 to objArgs.Count - 1
      WScript.Echo objArgs(I)
    Next
  4. Save the file to your hard drive.
  5. Drag and drop any file or files onto your .vbs file. The file names are echoed back to the screen.
Remarks
The number of files you can drag onto a script is limited by the maximum command-line length your system allows. If the total number of characters in all file names being dragged exceeds this limit, the dragging and dropping operation will fail.