Results 1 to 4 of 4

Thread: Executing a batch file from VB or another way of doing an automatic backup

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2000
    Location
    South Africa
    Posts
    113
    hi all
    I need my program to automatically back the database up every month

    I mad a small backup.bat file in DOS whcih just copies my database to a disk

    it is
    copy c:\crms.mdb a:\

    then in vb i try to execute it by...
    dim x
    x = shell("c:\backup.bat")

    but nothing happens.
    is there a way to execute this batch file from VB.
    Or does anyone know the better way of doing it...i.e.copying the file to disk straight via VB. I am not sure of those file.copy etc commands
    thanks in advance
    You are living a pacifist dream, and if you dreaming it means you sleeping and you should damn well wake up!

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539

    Talking use windows schedular

    i just made a automation bot that copies refreshes information from one table to another every night at 3 am

    and i have this set up with windows scheduler so that it runs at 3 am without me touching a thing
    when its done
    it shuts itself down..

  3. #3
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    I have an app that creates a .bat file and executes it. I use ShellExecute.

    Code:
    Private Declare Function ShellExecute Lib "shell32.dll" Alias _
            "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _
            String, ByVal lpszFile As String, ByVal lpszParams As String, _
            ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
    Here is the function that writes and executes the .bat file.
    Code:
    Function Run_Download(cmdline As String) As Long
       ' Build batch file to run the download
       Dim curr_drive As Variant
       Dim curr_path  As Variant
       Dim batfile    As String
       
       ' Get current path
       curr_path = CurDir
       curr_drive = Left$(curr_path, 2)
       
       ' open batch file
       batfile = App.Path & "\wftu.bat"
       Open batfile For Output As #giFileNum
       ' and write the commands
       Print #giFileNum, gsPCDrive(giPCPath)
       Print #giFileNum, "cd " & gsPCPath(giPCPath)
       If Left$(cmdline, 10) = gsPCEXE(giPCPath) Then
          Print #giFileNum, cmdline
       Else
          Print #giFileNum, "call " & cmdline
       End If
       Print #giFileNum, "rem "
       Print #giFileNum, "pause"
       Print #giFileNum, curr_drive
       Print #giFileNum, "cd " & curr_path
       If Exists(gsINIFile) Then
          Print #giFileNum, "del " & gsINIFile
       End If
       Print #giFileNum, "del " & batfile
       Close #giFileNum
      
       Run_Download = ShellExecute(gScr_hDC, "Open", batfile, _
                      "", "C:\", gSW_SHOWNORMAL)
                      
    End Function

  4. #4
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    NY
    Posts
    497
    Try

    x = shell("<path to>\cmd.exe c:\backup.bat")
    end war
    stop greed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width