Skip to content

Instantly share code, notes, and snippets.

@johnbahamon
Created March 4, 2017 07:35
Show Gist options
  • Save johnbahamon/c9f697d0d1942ce489705c8161a254b1 to your computer and use it in GitHub Desktop.
Save johnbahamon/c9f697d0d1942ce489705c8161a254b1 to your computer and use it in GitHub Desktop.
Imports System
Imports System.IO
Imports System.Text
Public Class Form1
Private psi As ProcessStartInfo
Private cmd As Process
Private Delegate Sub InvokeWithString(ByVal text As String)
Dim directorio As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Enabled = False
If Not TextBox1.Enabled Then
TextBox1.BackColor = Color.White
End If
directorio = ".\Equipos\" + TextBox1.Text + "\"
Dim array(9, 1) As String
array(0, 0) = "date /t>"
array(0, 1) = "Fecha.txt"
array(1, 0) = "time /t>"
array(1, 1) = "Hora.txt"
array(2, 0) = ".\SysinternalsSuite\pslist>"
array(2, 1) = "Procesos.txt"
array(3, 0) = ".\SysinternalsSuite\systeminfo>"
array(3, 1) = "System_Info.txt"
array(4, 0) = ".\SysinternalsSuite\arp -a>"
array(4, 1) = "Arp.txt"
array(5, 0) = ".\SysinternalsSuite\psloglist>"
array(5, 1) = "Lista_De_Logs.txt"
array(6, 0) = ".\SysinternalsSuite\netstat -an>"
array(6, 1) = "NetStat.txt"
array(7, 0) = ".\SysinternalsSuite\psservice>"
array(7, 1) = "Servicios.txt"
array(8, 0) = ".\SysinternalsSuite\listdlls>"
array(8, 1) = "Lista_De_Librerias.txt"
If My.Computer.FileSystem.DirectoryExists(directorio) Then
Label4.Text = "El directorio " + TextBox1.Text + " ya existe. Cree un nuevo proyecto"
TextBox1.Text = ""
TextBox1.Enabled = True
Else
My.Computer.FileSystem.CreateDirectory(directorio)
If My.Computer.FileSystem.DirectoryExists(directorio) Then
Label4.Text = ""
Button1.Enabled = False
Button2.Enabled = True
Button3.Enabled = True
Button4.Enabled = True
Shell(".\SysinternalsSuite\cmd.exe /c date /t>" + directorio + array(0, 1))
If My.Computer.FileSystem.FileExists(directorio + array(0, 1)) Then
TextBox2.Text = "El programa ha tenido problemas para su ejecucion"
Else
For i = 0 To 8
If My.Computer.FileSystem.FileExists(directorio + array(i, 1)) Then
TextBox2.Text = array(i, 1) + " Archivos no creado " + Chr(13) + Chr(10) + TextBox2.Text
Else
Shell(".\SysinternalsSuite\cmd.exe /c " + array(i, 0) + directorio + array(i, 1))
TextBox2.Text = array(i, 1) + " Archivos creado exitosamente " + Chr(13) + Chr(10) + TextBox2.Text
End If
Next
End If
End If
End If
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
End Sub
Private Sub Label4_Click(sender As Object, e As EventArgs)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
directorio = ".\Equipos\" + TextBox1.Text
If My.Computer.FileSystem.DirectoryExists(directorio) Then
Button5.Enabled = True
Button5.Visible = True
Button6.Enabled = True
Button6.Visible = True
Button5.Tag = "Metadatos_Acceso.txt"
Try
cmd.Kill()
Catch ex As Exception
End Try
TextBox2.Clear()
psi = New ProcessStartInfo()
Dim systemencoding As System.Text.Encoding
System.Text.Encoding.GetEncoding(Globalization.CultureInfo.CurrentUICulture.TextInfo.OEMCodePage)
With psi
.FileName = ".\SysinternalsSuite\cmd.exe"
.Arguments = "/k dir /t:a/a/s/o:d c:\"
.UseShellExecute = False
.RedirectStandardError = True
.RedirectStandardOutput = True
.RedirectStandardInput = True
.CreateNoWindow = True
.StandardOutputEncoding = systemencoding
.StandardErrorEncoding = systemencoding
End With
cmd = New Process With {.StartInfo = psi, .EnableRaisingEvents = True}
AddHandler cmd.ErrorDataReceived, AddressOf Async_Data_Received
AddHandler cmd.OutputDataReceived, AddressOf Async_Data_Received
cmd.Start()
cmd.BeginOutputReadLine()
cmd.BeginErrorReadLine()
End If
End Sub
Private Sub Async_Data_Received(ByVal sender As Object, ByVal e As DataReceivedEventArgs)
Me.Invoke(New InvokeWithString(AddressOf Sync_Output), e.Data)
End Sub
Private Sub Sync_Output(ByVal text As String)
TextBox2.AppendText(text & Environment.NewLine)
TextBox2.ScrollToCaret()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
directorio = ".\Equipos\" + TextBox1.Text
If My.Computer.FileSystem.DirectoryExists(directorio) Then
Button5.Enabled = True
Button5.Visible = True
Button6.Enabled = True
Button6.Visible = True
Button5.Tag = "Metadatos_Modificacion.txt"
Try
cmd.Kill()
Catch ex As Exception
End Try
TextBox2.Clear()
psi = New ProcessStartInfo()
Dim systemencoding As System.Text.Encoding
System.Text.Encoding.GetEncoding(Globalization.CultureInfo.CurrentUICulture.TextInfo.OEMCodePage)
With psi
.FileName = ".\SysinternalsSuite\cmd.exe"
.Arguments = "/k dir /t:w/a/s/o:d c:\"
.UseShellExecute = False
.RedirectStandardError = True
.RedirectStandardOutput = True
.RedirectStandardInput = True
.CreateNoWindow = True
.StandardOutputEncoding = systemencoding
.StandardErrorEncoding = systemencoding
End With
cmd = New Process With {.StartInfo = psi, .EnableRaisingEvents = True}
AddHandler cmd.ErrorDataReceived, AddressOf Async_Data_Received
AddHandler cmd.OutputDataReceived, AddressOf Async_Data_Received
cmd.Start()
cmd.BeginOutputReadLine()
cmd.BeginErrorReadLine()
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
directorio = ".\Equipos\" + TextBox1.Text
If My.Computer.FileSystem.DirectoryExists(directorio) Then
Button5.Enabled = True
Button5.Visible = True
Button6.Enabled = True
Button6.Visible = True
Button5.Tag = "Metadatos_Creacion.txt"
Try
cmd.Kill()
Catch ex As Exception
End Try
TextBox2.Clear()
psi = New ProcessStartInfo()
Dim systemencoding As System.Text.Encoding
System.Text.Encoding.GetEncoding(Globalization.CultureInfo.CurrentUICulture.TextInfo.OEMCodePage)
With psi
.FileName = ".\SysinternalsSuite\cmd.exe"
.Arguments = "/k dir /t:c/a/s/o:d c:\"
.UseShellExecute = False
.RedirectStandardError = True
.RedirectStandardOutput = True
.RedirectStandardInput = True
.CreateNoWindow = True
.StandardOutputEncoding = systemencoding
.StandardErrorEncoding = systemencoding
End With
cmd = New Process With {.StartInfo = psi, .EnableRaisingEvents = True}
AddHandler cmd.ErrorDataReceived, AddressOf Async_Data_Received
AddHandler cmd.OutputDataReceived, AddressOf Async_Data_Received
cmd.Start()
cmd.BeginOutputReadLine()
cmd.BeginErrorReadLine()
End If
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs)
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub NuevoToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NuevoToolStripMenuItem.Click
TextBox1.Enabled = True
Button1.Enabled = True
TextBox1.Text = ""
TextBox2.Text = ""
If Not TextBox1.Enabled Then
TextBox1.BackColor = Color.White
End If
End Sub
Private Sub Label4_Click_1(sender As Object, e As EventArgs) Handles Label4.Click
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
directorio = ".\Equipos\" + TextBox1.Text + "\"
If My.Computer.FileSystem.DirectoryExists(directorio) Then
Dim path As String = directorio + Button5.Tag
' Create or overwrite the file.
Dim fs As FileStream = File.Create(path)
' Add text to the file.
Dim info As Byte() = New UTF8Encoding(True).GetBytes(TextBox2.Text)
fs.Write(info, 0, info.Length)
fs.Close()
End If
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
cmd.Kill()
End Sub
Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment