Gane dinero viendo publicidad

Gane dinero viendo publicidad

lunes, 19 de mayo de 2014

Apagar y reiniciar equipos conectados en red desde visual basic 6.0

En esta ocasión les comparto un código que sirve para cuando tenemos varios equipos conectados en la red y somos administradores de la misma y deseamos poder apagar o reiniciar uno o varios equipos desde alguno de ellos.

El programa es muy sencillo, solo hay que tener en cuenta la sentencia que sirve para apagar o reiniciar un equipo desde visual basic 6.0.

Para apagar o reiniciar un equipo, se utiliza la siguiente sentencia:

Shell "shutdown -s -t -m -c
 donde -s es el comando para apagar el equipo, -r es para reiniciarlo
            -t es para configurar el tiempo que debe transcurrir antes que se apague el equipo.
            -m es el parámetro donde se establece el nombre del equipo en el cual se va a ejecutar la acción.
            -c es para escribir un mensaje que se le quiera enviar al equipo.

Por lo tanto, el código para ejecutar dichas acciones sobre 10 equipos es el siguiente:

Option Explicit
Public Accion As String, x As String

Private Sub cmdApagar_Click()
If txtMensaje.Text = Empty Then
    MsgBox "Debes escribir un mensaje", vbInformation, "Control de equipos"
    txtMensaje.SetFocus
    Exit Sub
End If


If chkEquipo(0).Value = 1 Then
 If txtTiempo(0).Text <> Empty And txtMensaje.Text <> Empty Then
    If optApagar(0).Value = True Then Accion = "-s" Else Accion = "-r"
    Shell "shutdown " & Accion & " -t " & txtTiempo(0).Text & " -m \\" & chkEquipo(0).Caption & " -c " & txtMensaje.Text
    End If
End If

If chkEquipo(1).Value = 1 Then
 If txtTiempo(1).Text <> Empty And txtMensaje.Text <> Empty Then
    If optApagar(1).Value = True Then Accion = "-s" Else Accion = "-r"
    Shell "shutdown -s -t " & txtTiempo(1).Text & " -m \\" & chkEquipo(1).Caption & " -c " & txtMensaje.Text
  End If
End If

If chkEquipo(2).Value = 1 Then
 If txtTiempo(2).Text <> Empty And txtMensaje.Text <> Empty Then
    If optApagar(2).Value = True Then Accion = "-s" Else Accion = "-r"
    Shell "shutdown -s -t " & txtTiempo(2).Text & " -m \\" & chkEquipo(2).Caption & " -c " & txtMensaje.Text
  End If
End If

If chkEquipo(3).Value = 1 Then
 If txtTiempo(3).Text <> Empty And txtMensaje.Text <> Empty Then
    If optApagar(3).Value = True Then Accion = "-s" Else Accion = "-r"
    Shell "shutdown -s -t " & txtTiempo(3).Text & " -m \\" & chkEquipo(3).Caption & " -c " & txtMensaje.Text
  End If
End If

If chkEquipo(4).Value = 1 Then
 If txtTiempo(4).Text <> Empty And txtMensaje.Text <> Empty Then
    If optApagar(4).Value = True Then Accion = "-s" Else Accion = "-r"
    Shell "shutdown -s -t " & txtTiempo(4).Text & " -m \\" & chkEquipo(4).Caption & " -c " & txtMensaje.Text
  End If
End If
  
If chkEquipo(5).Value = 1 Then
 If txtTiempo(5).Text <> Empty And txtMensaje.Text <> Empty Then
    If optApagar(5).Value = True Then Accion = "-s" Else Accion = "-r"
    Shell "shutdown -s -t " & txtTiempo(5).Text & " -m \\" & chkEquipo(5).Caption & " -c " & txtMensaje.Text
  End If
End If

If chkEquipo(6).Value = 1 Then
 If txtTiempo(6).Text <> Empty And txtMensaje.Text <> Empty Then
    If optApagar(6).Value = True Then Accion = "-s" Else Accion = "-r"
    Shell "shutdown -s -t " & txtTiempo(6).Text & " -m \\" & chkEquipo(6).Caption & " -c " & txtMensaje.Text
  End If
End If

If chkEquipo(7).Value = 1 Then
 If txtTiempo(7).Text <> Empty And txtMensaje.Text <> Empty Then
    If optApagar(7).Value = True Then Accion = "-s" Else Accion = "-r"
    Shell "shutdown -s -t " & txtTiempo(7).Text & " -m \\" & chkEquipo(7).Caption & " -c " & txtMensaje.Text
  End If
End If

If chkEquipo(8).Value = 1 Then
 If txtTiempo(8).Text <> Empty And txtMensaje.Text <> Empty Then
    If optApagar(8).Value = True Then Accion = "-s" Else Accion = "-r"
    Shell "shutdown -s -t " & txtTiempo(8).Text & " -m \\" & chkEquipo(8).Caption & " -c " & txtMensaje.Text
  End If
End If

If chkEquipo(9).Value = 1 Then
 If txtTiempo(9).Text <> Empty And txtMensaje.Text <> Empty Then
    If optApagar(9).Value = True Then Accion = "-s" Else Accion = "-r"
    Shell "shutdown -s -t " & txtTiempo(9).Text & " -m \\" & chkEquipo(9).Caption & " -c " & txtMensaje.Text
  End If
End If

End Sub

Private Sub cmdCancelar_Click(Index As Integer)

'Cancela el apagado del equipo
 Shell "shutdown -a -m \\" & chkEquipo(Index).Caption

End Sub


Si deseas obtener los archivos del programa puedes descargarlo desde este link:
Descargar programa

No hay comentarios:

Publicar un comentario