Autor Tema: Cerrar ventana DOS después de usar todo  (Leído 3562 veces)

0 Usuarios y 1 Visitante están viendo este tema.

E N T E R

  • Petabyte
  • ******
  • Mensajes: 1062
  • Reputación: +57/-13
  • www.enterpy.com
    • Ver Perfil
    • www.enterpy.com
Cerrar ventana DOS después de usar todo
« 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

Código: [Seleccionar]
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
CIBER GOOGLE - CONCEPCIÓN PARAGUAY
www.enterpy.com
Primera regla de la programacion, para que vas a hacerlo complicado si lo puedes hacer sencillo

YAcosta

  • Moderador Global
  • Exabyte
  • *****
  • Mensajes: 2853
  • Reputación: +160/-38
  • Daddy de Qüentas y QüeryFull
    • Ver Perfil
    • Personal
Re:Cerrar ventana DOS después de usar todo
« Respuesta #1 en: Junio 10, 2011, 12:44:33 pm »
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


« última modificación: Junio 10, 2011, 03:20:33 pm por YvanB »
Me encuentras en YAcosta.com

raul338

  • Terabyte
  • *****
  • Mensajes: 894
  • Reputación: +62/-8
  • xD fan!!!!! xD
    • Ver Perfil
    • Raul's Weblog
Re:Cerrar ventana DOS después de usar todo
« Respuesta #2 en: Junio 10, 2011, 03:07:37 pm »
Exacto, uso la misma tecnica de YvanB

y este seria el codigo

Código: (vb) [Seleccionar]
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
Código: (vb) [Seleccionar]
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

Lolabyte

  • Bytes
  • *
  • Mensajes: 35
  • Reputación: +15/-0
    • Ver Perfil
Re:Cerrar ventana DOS después de usar todo
« Respuesta #3 en: Junio 11, 2011, 05:47:55 am »
Prueba poniendole un "& exit" al final de tu comando :)

Código: (vb) [Seleccionar]
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