Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: FoxPro FAQ

COM and Automation

Using Microsoft Windows Script in Visual FoxPro by Mike Gagnon
Posted: 4 Jan 03 (Edited 7 May 03)

Windows scripting guide, For VFP.
1. File System Object
    Example A (Copy a file)
               fs = CreateObject("Scripting.FileSystemObject")
               fs.CopyFile(c:\autoexec.bat,a:\autoexec.bat,.T.)  && The last parameter is for overwriting.
   Example B (Create a textfile and write to it)
             fs = CreateObject("Scripting.FileSystemObject")
            TestFile = fs.CreateTextFile("c:\testfile.txt", .T.)
            TestFile.WriteLine("This is a test.")
    Example C (Check to see if a folder exists)
            fs = CreateObject("Scripting.FileSystemObject")
     Example D (Check to see if a file Exists)
            fs = CreateObject("Scripting.FileSystemObject")
     Example E (Get file version)
    There are many other file system commands, like movefile, movefolder, delete file, delete folder, Open Textfile etc.
2.  WScipt Object
      Example A  (find the path to the Desktop)
                     WshShell = CreateObject("WScript.Shell")
       Example B (Create a replacement to the VFP MessageBox)
                   nReturn =WshShell.Popup("hello")
3. WScript Network
      Example A (map a networkDrive)
                   WshNetwork = CreateObject("WScript.Network")
                   WshNetwork.MapNetworkDrive "S:", "\\server\share"
      Example B (get the username and computer name)
                  ? wshNetwork.Username
                  ? wshNetwork.ComputerName
       Example C (change Windows default Printer)
                  oNet = CREATEOBJECT("WScript.Network")
                  oNet.SetDefaultPrinter("\\slp_nt_termserv\Panasonic Printer")

4. The shell object
       Example A (run a external program)
                  WshShell = CreateObject("WScript.Shell")

Note: Some other noted methods:
AddPrinterConnection Method
The AddPrinterConnection method is used to map a network printer to a local printer resource.

AddWindowsPrinterConnection Method
The AddPrinterConnection method is used to add a printer connection to the local system.

AppActivate Method
The AppActivate method is used to change the focus of a running application.

CreateObject Method
The CreateObject method is used to create an instance of the specified object.

CreateShortcut Method
The CreateShortcut method is used to create shortcuts to files and remote URL's.

DisconnectObject Method
The DisconnectObject method is used to disconnect a previous created object.

Echo Method
The Echo method to display information to the user through the console (CSCRIPT) or dialog boxes (WSCRIPT).

EnumNetworkDrives Method
The EnumNetworkDrives method creates a array containing the drive letter and network path for the locally mapped drives.

EnumPrinterConnections Method
The EnumPrinterConnections method creates a array containing the port and device names for the installed printers.

ExpandEnvironmentStrings Method
The ExpandEnvironmentStrings method returns a string containing the requested substituted environment variable.

GetObject Method
The GetObject method retrieves an object from a file or from an object specified.

LogEvent Method
The LogEvent method is used to log an event to the Event Log (Windows NT/2000) or the WSH.log file (Windows 95, 98, Me).

MapNetworkDrive Method
The MapNetworkDrive method is used to map a network file share to a local drive resource.

Popup Method
The Popup method is used to display a dialog box to a user and wait a button to be pressed, or optionally, a timeout to occur.

Quit Method
The Quit method is used to terminate the execution of the current script with a specified error code.

RegDelete Method
The RegDelete method is used to delete a value or key from the Windows registry.

RegRead Method
The RegRead method is used to retrieve a value from the Windows registry.

RegWrite Method
The RegWrite method is used to write a value to the Windows registry.

RemoveNetworkDrive Method
The RemoveNetworkDrive method is used to disconnect a network drive mapping from the local system.

RemovePrinterConnection Method
The RemovePrinterConnection method is used to disconnect a printer device from the local system.

Run Method
The Run method is used to launch a local application.

SendKeys Method
The SendKeys method is used to send keystrokes to the currently active window as if they where typed from the keyboard.

SetDefaultPrinter Method
The SetDefaultPrinter method is used to specify which printer should be set as the default device.

Sleep Method
The Sleep method is used to freeze the script execution for a specified number of milliseconds and then continue execution.

Mike Gagnon

Back to Microsoft: FoxPro FAQ Index
Back to Microsoft: FoxPro Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close