Solved

Simple Batch file to Backup Script ???

Posted on 2002-05-03
2
157 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
Comment Utility
Why not just use the Microsoft Backup program - it does all this for you
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 100 total points
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now