Ciao a tutti,
sto cercando di creare un semplice tool [codato in VB8] che mi apra la shell di windows e prenda in input dei comandi sembra funzionare ma devo fixare un problema... in pratica nella funzione devo aggiungere alla fine per forza il comando "exit" altrimenti non mi funziona ma di conseguenza mi esce dalla shell! posto in codice:
Come protrebbe essere risolto?codice:Public Class frmMain Private Sub CMDAutomate(ByVal command As String) Dim myprocess As New Process Dim StartInfo As New System.Diagnostics.ProcessStartInfo StartInfo.UseShellExecute = False StartInfo.RedirectStandardInput = True 'attivo l'input StartInfo.RedirectStandardOutput = True 'attivo l'output StartInfo.RedirectStandardError = True 'gestione errori StartInfo.CreateNoWindow = True 'non creare la finistra del prompt StartInfo.Arguments = "/K" 'parametro per fa rimanere l'output StartInfo.WorkingDirectory = "C:\" 'directory iniziale c:\ StartInfo.FileName = "cmd.exe" myprocess.StartInfo = StartInfo myprocess.Start() Dim SR As System.IO.StreamReader = myprocess.StandardOutput Dim SW As System.IO.StreamWriter = myprocess.StandardInput SW.WriteLine(command) SW.WriteLine("exit") 'esco dal prompt necessario per funzionare txtoutput.Text = SR.ReadToEnd SW.Close() SR.Close() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try 'dichiaro l'utilizzo del thread Dim CMDThread As New Threading.Thread(AddressOf CMDAutomate) CMDAutomate(txtcmd.Text) 'richiamo la funzione RS CMDThread.Abort() 'chiudo il thread Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub End Class
grazie

Rispondi quotando
