Visual Basic Foro
Programación => Visual Basic 6 => Mensaje iniciado por: E N T E R en Junio 10, 2011, 12:26:20 pm
-
Yo estoy usando este metodo para hacer un backup la base datos MySQL pero cada ves que ago siempre queda abierto el D.O.S como puedo cerrar eso despues de utilizar todo
Sub CREAR_BACKUP()
D = Format(Day(Date), "0#")
M = Format(Month(Date), "0#")
y = Format(Year(Date), "0#")
'// Hora de Seguridad
h = Format(Hour(Time), "0#")
MI = Format(Minute(Time), "0#")
S = Format(Second(Time), "0#")
fcopia = D & "-" & M & "-" & y & "-" & h & "-" & MI & "-" & S
Set Comando1 = CreateObject("WSCript.shell")
Comando1.run "cmd /K CD c:\wamp\bin\mysql\mysql5.5.8\bin & mysqldump -u root control_prestamos > D:\backup_prestamos\" & fcopia & ".sql"
Set Comando1 = Nothing
End Sub
-
mmm, a ver si te sirve esta sugerencia. En mi caso (ya que yo uso Firebird) los respaldos se hacen con GBak y en caliente (sin detener el server), tonses lo invoco asi
Cadena = "...gbak.exe " & " -v -t -user YVANB -password miclave" & RutaBD & ".FBK"
RetVal = Shell(Cadena, 0)
Lo que quiero decir, es que si lo haces con Shell, al ponerle "0" no te va a salir la ventana del DOS.
¿Tonses como me entero si acabo el backup?, con un timer consulto la existencia del nuevo archivo y doy el mensaje al usuario.
Saludos
-
Exacto, uso la misma tecnica de YvanB
y este seria el codigo
Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
.........................
Dim s As Long
s = ShellExecute(Me.hwnd, "open", "mysql backup.exe", "-bd Bla bla bla", App.Path & "\mysql", 0)
If s <= 32 Then
' Algo salio mal :P
Call Msgbox(MsgErrNoServer, vbCritical)
Call Unload(Me)
End If
Para saber si un archivo esta en uso
Private Declare Function CreateFile Lib "kernel32" Alias _
"CreateFileA" (ByVal lpFileName As String, _
ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, _
ByVal lpSecurityAttributes As Long, _
ByVal dwCreationDisposition As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const OPEN_EXISTING = &H3
Private Const GENERIC_WRITE = &H40000000
Private Const INVALID_HANDLE_VALUE = -1
Public Function ArchivoEnUso(ByVal sFileName As String) As Boolean
Dim hFile As Long
On Error GoTo ExitGetFileInfo
' Obtenemos el manipulador del archivo. Para ello indicamos
' que vamos a permitir el acceso de lectura
hFile = CreateFile(sFileName, GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0&, 0&)
' Si hay un error es porque el archivo está siendo utilizado
If hFile = INVALID_HANDLE_VALUE Then ArchivoEnUso = True
ExitGetFileInfo:
' Cerramos el manipulador del archivo
hFile = CloseHandle(hFile)
End Function
-
Prueba poniendole un "& exit" al final de tu comando :)
Sub CREAR_BACKUP()
D = Format(Day(Date), "0#")
M = Format(Month(Date), "0#")
y = Format(Year(Date), "0#")
'// Hora de Seguridad
h = Format(Hour(Time), "0#")
MI = Format(Minute(Time), "0#")
S = Format(Second(Time), "0#")
fcopia = D & "-" & M & "-" & y & "-" & h & "-" & MI & "-" & S
Set Comando1 = CreateObject("WSCript.shell")
Comando1.run "cmd /K CD c:\wamp\bin\mysql\mysql5.5.8\bin & mysqldump -u root control_prestamos > D:\backup_prestamos\" & fcopia & ".sql & exit"
Set Comando1 = Nothing
End Sub