Imports System
Imports System.Threading
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Net
Imports System.Net.Mail
Imports System.Runtime.InteropServices
Imports System.IO
Public Class Form1
Const HWND_BROADCAST As Integer = &HFFFF
Const SC_MONITORPOWER As Integer = &HF170
Const WM_SYSCOMMAND As Short = &H112S
Dim ore, minuti, secondi As Integer
Dim setOre, setMin As Integer
Dim nomeapp As String
Dim suono As String
Public nomeprocesso As String
Public testomex As String
Public titolomex As String
#Region "API"
<DllImport("user32.dll", CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall, CharSet:=Runtime.InteropServices.CharSet.Ansi, EntryPoint:="keybd_event", ExactSpelling:=True, SetLastError:=True)> Public Shared Sub keybd_event(ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
End Sub
<DllImport("user32.dll", CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall, CharSet:=Runtime.InteropServices.CharSet.Ansi, EntryPoint:="ExitWindowsEx", ExactSpelling:=True, SetLastError:=True)> Public Shared Sub ExitWindowsEx(ByVal uFlags As Integer, ByVal dwReason As Integer)
End Sub
Private Function SendMessage(ByVal Handle As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
End Function
#End Region
Private Sub NotificaEmail(ByVal destinatario As String, ByVal operazione As String, ByVal nomepc As String, ByVal data As String, ByVal ora As String)
Dim message As New MailMessage("Shutdown@virgilio.it", destinatario, "Operazione effetuata con successo", "Ciao " & destinatario & ", la informo che l'operazione di " & operazione & " sul computer " & nomepc & " è avvenuta con successo il " & data & " alle " & ora & ". Shutdown 4.0 Developed by Progman-92/De Vos Ugo!!!.")
Dim emailClient As New SmtpClient("out.virgilio.it")
message.Priority = MailPriority.Normal
emailClient.Send(message)
End Sub
Private Sub spegniSchermo()
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cbSelezione.SelectedItem = "Nessuna operazione"
tmrOraDataSistema.Start()
lblTipologiaOperazione.Text = "Nessuna operazione"
End Sub
Private Sub btnNascondi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Hide()
End Sub
Private Sub btnOpzioni_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpzioni.Click
Select Case cbSelezione.SelectedItem.ToString
Case "Nessuna operazione", "Disconessione utente", "Blocco personal computer", "Spegnimento", "Riavvio", "Sospensione", "Ibernazione", "Screenshoot", "Spegnimento schermo"
MessageBox.Show("Non è neccessario specificare nessun parametro aggiuntivo per eseguire questa operazione!!!", "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error)
Case "Avvio applicazione"
Dim percorso
apriFile1.InitialDirectory = "C:\Programmi"
apriFile1.RestoreDirectory = True
apriFile1.Title = "Scegli l'applicazione che vuoi avviare"
apriFile1.FilterIndex = 2
apriFile1.DefaultExt = "exe"
apriFile1.Filter = "file eseguibili (*.exe) | *.exe| " & "tutti i file (*.*) | *.*"
If apriFile1.ShowDialog() = Windows.Forms.DialogResult.OK Then
percorso = Me.apriFile1.FileName
nomeapp = percorso.ToString
End If
Case "Chiusura applicazione"
Form2.Show()
Case "Messaggio"
Form3.Show()
Case "Suono"
apriFile1.InitialDirectory = "C:\Windows\Media"
apriFile1.RestoreDirectory = True
apriFile1.Title = "Scegli il suono che vuoi avviare"
apriFile1.FilterIndex = 2
apriFile1.DefaultExt = "wav"
apriFile1.Filter = "File audio wave (*.wav) | *.wav| " & "Tutti i file (*.*) | *.*"
If apriFile1.ShowDialog() = Windows.Forms.DialogResult.OK Then
suono = apriFile1.FileName.ToString
End If
End Select
End Sub
Private Sub tmrOraDataSistema_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrOraDataSistema.Tick
lblOra.Text = Date.Now
End Sub
Private Sub tmrOperazioni_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrOperazioni.Tick
tmrOperazioni.Start()
If rbtnAlle.Checked = True Then
ShutdownAt()
ElseIf rbtnIn.Checked = True Then
ShutdownIn()
End If
End Sub
Private Function formato2Cifre(ByVal Valore As Integer) As String
Dim nuovoValore As String
Dim lungh As Integer = Valore.ToString.Length
If lungh = 1 Then
nuovoValore = "0" + Valore.ToString
Return nuovoValore
Else
Return Valore.ToString
End If
End Function
Private Sub ShutdownIn()
If ore > 0 Or minuti > 0 Or secondi > 0 Then
If minuti = 0 AndAlso ore > 0 Then minuti = 59 : ore = ore - 1
If secondi = 0 AndAlso minuti > 0 Then secondi = 60 : minuti = minuti - 1
secondi = secondi - 1
End If
lblTipologiaOperazione.Text = cbSelezione.Text + " in"
lblCountDown.Text = formato2Cifre(ore) + ":" + formato2Cifre(minuti) + ":" + formato2Cifre(secondi)
If ore = 0 AndAlso minuti = 0 AndAlso secondi = 0 Then
tmrOperazioni.Stop()
Select Case cbSelezione.SelectedIndex
Case 0
Case 1
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
ExitWindowsEx(0, 0)
Me.Close()
Case 2
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
Shell("rundll32.exe user32.dll,LockWorkStation")
Me.Close()
Case 3
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
ExitWindowsEx(2, 0)
Me.Close()
Case 4
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
ExitWindowsEx(1, 0)
Me.Close()
Case 5
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
Application.SetSuspendState(PowerState.Suspend, True, True)
Me.Close()
Case 6
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
Application.SetSuspendState(PowerState.Hibernate, True, True)
Me.Close()
Case 7
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
spegniSchermo()
Me.Close()
Case 8
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
System.Threading.Thread.Sleep(500)
End If
Shell(nomeapp)
Me.Close()
Case 9
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
Dim processi() As Process = Process.GetProcessesByName(nomeprocesso.ToString)
Dim processo As Process
For Each processo In processi
processo.CloseMainWindow()
Next
Me.Close()
Case 10
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
MessageBox.Show(testomex, titolomex, MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Close()
Case 11
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
My.Computer.Audio.Play(suono)
tmrSuono.Start()
Me.Hide()
Case 12
Const KEYEVENTF_KEYUP As Byte = &H2
keybd_event(AscW(Chr(44)), 0, 0, 0)
keybd_event(AscW(Chr(44)), 0, KEYEVENTF_KEYUP, 0)
pctbScreenShoot.Image = CType(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Bitmap)
pctbScreenShoot.Image.Save(Application.StartupPath & "/Screenshoot.jpg", Imaging.ImageFormat.Jpeg)
End Select
End If
End Sub
Private Sub ShutdownAt()
lblTipologiaOperazione.Text = cbSelezione.Text + " alle"
lblCountDown.Text = formato2Cifre(nudOre1.Value) + ":" + formato2Cifre(nudMin1.Value) + ":" + formato2Cifre(0)
If String.Compare(Now.Hour.ToString, nudOre1.Value.ToString) = 0 Then
If String.Compare(Now.Minute.ToString, nudMin1.Value.ToString) = 0 Then
Me.Show()
tmrSuono.Stop()
Select Case cbSelezione.SelectedIndex
Case 0
Case 1
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
ExitWindowsEx(0, 0)
Me.Close()
Case 2
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
Shell("rundll32.exe user32.dll,LockWorkStation")
Me.Close()
Case 3
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
ExitWindowsEx(2, 0)
Me.Close()
Case 4
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
ExitWindowsEx(1, 0)
Me.Close()
Case 5
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
Application.SetSuspendState(PowerState.Suspend, True, True)
Me.Close()
Case 6
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
Application.SetSuspendState(PowerState.Hibernate, True, True)
Me.Close()
Case 7
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
spegniSchermo()
Me.Close()
Case 8
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
System.Threading.Thread.Sleep(500)
End If
Shell(nomeapp)
Me.Close()
Case 9
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
Dim processi() As Process
Dim processo As Process
processi = Process.GetProcessesByName(nomeprocesso.ToString)
For Each processo In processi
processo.CloseMainWindow()
Next
Me.Close()
Case 10
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
MessageBox.Show(testomex, titolomex, MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Close()
Case 11
If Me.chkbNotifica.CheckState = CheckState.Checked And txtMail.Text <> "" Then
NotificaEmail(txtMail.Text, cbSelezione.Text, My.Computer.Name, Date.Today.Day & "/" & Date.Today.Month & "/" & Date.Today.Year, Date.Today.Hour & ":" & Date.Today.Minute & ":" & Date.Today.Second)
End If
My.Computer.Audio.Play(suono)
tmrSuono.Start()
Me.Hide()
Case 12
Const KEYEVENTF_KEYUP As Byte = &H2
keybd_event(AscW(Chr(44)), 0, 0, 0)
keybd_event(AscW(Chr(44)), 0, KEYEVENTF_KEYUP, 0)
pctbScreenShoot.Image = CType(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Bitmap)
pctbScreenShoot.Image.Save(Application.StartupPath & "/Screenshoot.jpg", Imaging.ImageFormat.Jpeg)
End Select
End If
End If
End Sub
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
If cbSelezione.SelectedItem = "Nessuna operazione" Then
MessageBox.Show("Specificare una operazione!!!", "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
tmrOperazioni.Start()
lblOra.Visible = True
setOre = nudOre2.Value
setMin = nudMin2.Value
ore = setOre
minuti = setMin
If nudOre2.Value = 0 AndAlso nudMin2.Value = 0 Then
secondi = 60
Else
secondi = 0
End If
btnOk.Enabled = False
End If
End Sub
Private Sub btnAnnulla_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnnulla.Click
tmrOperazioni.Stop()
lblTipologiaOperazione.Text = "Nessuna operazione"
lblCountDown.Text = ""
cbSelezione.SelectedIndex = 0
Me.btnOk.Enabled = True
End Sub
Private Sub nudHours_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudOre1.ValueChanged
tmrOperazioni.Stop()
If nudOre1.Value = nudOre1.Maximum Then
nudOre1.UpButton()
nudOre1.Value = nudOre1.Minimum + 1
End If
If nudOre1.Value = nudOre1.Minimum Then
nudOre1.DownButton()
nudOre1.Value = nudOre1.Maximum - 1
End If
End Sub
Private Sub nudMin_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudMin1.ValueChanged
tmrOperazioni.Stop()
If nudMin1.Value = nudMin1.Maximum Then
nudMin1.UpButton()
nudMin1.Value = nudMin1.Minimum + 1
End If
If nudMin1.Value = nudMin1.Minimum Then
nudMin1.DownButton()
nudMin1.Value = nudMin1.Maximum - 1
End If
End Sub
Private Sub nudHours2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudOre2.ValueChanged
tmrOperazioni.Stop()
If nudOre2.Value = nudOre2.Maximum Then
nudOre2.UpButton()
nudOre2.Value = nudOre2.Minimum + 1
End If
If nudOre2.Value = nudOre2.Minimum Then
nudOre2.DownButton()
nudOre2.Value = nudOre2.Maximum - 1
End If
End Sub
Private Sub nudMin2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nudMin2.ValueChanged
tmrOperazioni.Stop()
If nudMin2.Value = nudMin2.Maximum Then
nudMin2.UpButton()
nudMin2.Value = nudMin2.Minimum + 1
End If
If nudMin2.Value = nudMin2.Minimum Then
nudMin2.DownButton()
nudMin2.Value = nudMin2.Maximum - 1
End If
End Sub
Private Sub rbtnAt_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtnAlle.CheckedChanged
nudOre1.Enabled = True
nudMin1.Enabled = True
nudOre2.Enabled = False
nudMin2.Enabled = False
tmrOperazioni.Stop()
End Sub
Private Sub rbtnIn_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtnIn.CheckedChanged
nudOre1.Enabled = False
nudMin1.Enabled = False
nudOre2.Enabled = True
nudMin2.Enabled = True
tmrOperazioni.Stop()
End Sub
Private Sub txtMail_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtMail.TextChanged
If txtMail.Text.Length <> 0 Then
chkbNotifica.CheckState = CheckState.Checked
Else
chkbNotifica.CheckState = CheckState.Unchecked
End If
End Sub
Private Sub tmrSuono_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrSuono.Tick
My.Computer.Audio.Play(suono)
End Sub
Private Sub MostraToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MostraToolStripMenuItem.Click
Me.ShowDialog()
End Sub
Private Sub NascondiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NascondiToolStripMenuItem.Click
Me.Hide()
End Sub
Private Sub InterrompiTuttoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InterrompiTuttoToolStripMenuItem.Click
tmrOperazioni.Stop()
lblTipologiaOperazione.Text = ""
lblCountDown.Text = ""
cbSelezione.SelectedIndex = 0
Me.btnOk.Enabled = True
End Sub
Private Sub EsciToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EsciToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub InfoSuToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InfoSuToolStripMenuItem.Click
AboutBox1.ShowDialog()
End Sub
End Class