[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Simple Batch file to Backup Script ???

Posted on 2002-05-03
2
Medium Priority
?
168 Views
Last Modified: 2010-05-02
I have written a simple batch to backup files to a server ...  Now I know nothing about VB, but do know there is so much more you can do with it.  Can anyone help me out ??

cd c:\My Documents
echo %username% was last backed up %time% %date% > Date.txt
xcopy *.* \\Pongo\Home\%Username% /I /E /V /H /R /D /Y

Now I need to tart it up a little.  I need the following :

1. It to run in a Window so the user can see what it is doing / copying

2. Some sort of interaction from the user ie: You are about to back up your data to the server do you wish to continue ?

3. A completion statement ie: Your data has been backed up to \\location press any key to exit.

Thanks in Advance
0
Comment
Question by:rhodrih
2 Comments
 
LVL 15

Expert Comment

by:cquinn
ID: 6988284
Why not just use the Microsoft Backup program - it does all this for you
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 300 total points
ID: 6988514
you could try something like this

Option Explicit
Private Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "Kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400

Private Sub Shell32Bit(ByVal JobToDo As String)
Dim hProcess As Long
Dim RetVal As Long
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(JobToDo, 1))
Do
    GetExitCodeProcess hProcess, RetVal
    DoEvents: Sleep 100
Loop While RetVal = STILL_ACTIVE
End Sub

Private Sub Command1_Click()
Dim rsp As String
Dim strSh As String
Dim strUser As String
Dim nLen As Long
strUser = Space(256)
nLen = 256
Call GetUserName(strUser, nLen)
strUser = Left$(strUser, nLen - 1)
rsp = MsgBox("Would you like to backup all of your files now?", vbYesNoCancel, "Backup Files?")
If rsp = vbYes Then
    strSh = "command.com /c xcopy C:\*.* \\Pongo\Home\" & strUser & " /h/i/c/k/e/r"
    Shell32Bit strSh
    GoTo zDone
End If
MsgBox "Operation Cancelled!"
Exit Sub
zDone:
MsgBox "Data has been backed up to \\Pongo\Home\" & strUser & ".Press Ok to Exit"
End Sub
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question