myProcess.WaitForExit()
Keep getting error..cannot find file I think its cause im trying to pass parameters
Cannot find file
Dim options As String = ("/quiet /norestart /overwriteoem /nobackup") Dim updates As String = ("F:\Updates\") Dim di As New IO.DirectoryInfo("F:\updates") Dim diar1 As IO.FileInfo() = di.GetFiles Dim diar2 As IO.DirectoryInfo() = di.GetDirectories() Dim dra As IO.FileInfo 'list the names of all files in the specified directory For Each dra In diar1 Dim myProcess As Process = System.Diagnostics.Process.Start(updates.ToString & dra.ToString & " " & options.ToString)

Cannot find file
bplucas
Vishalbhambure
but now issue is this..
System.InvalidOperationException was unhandled by user code
Message="Cross-thread operation not valid: Control 'ListBox1' accessed from a thread other than the thread it was created on."
Dim i As Integer = 0 For Each dra In diar1
i = i + 1
Next Dim t As Integer = 0 For Each dra In diar1ListBox1.Items.Add(dra) <----KEEPS BOMBING HERE
Dim myProcess As Process = System.Diagnostics.Process.Start(updates.ToString & dra.ToString, options.ToString)myProcess.WaitForExit()
t = t + 1
Dim total As Integer = (t / i) * 100BackgroundWorker1.ReportProgress(total)
Next End SubI read a post about this on MSDN forum and it states to update the listbox on completion of backgroundworker..i dont want to do this because like stated above i want to post the file name...then run the file..not run all the files then list them all.
afields2
Private Sub btn_getfiles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_getfiles.Click ' make a reference to a directory Dim options As String = ("/passive /norestart /overwriteoem /nobackup") Dim updates As String = ("F:\Updates\") Dim di As New IO.DirectoryInfo("F:\updates") Dim diar1 As IO.FileInfo() = di.GetFiles Dim diar2 As IO.DirectoryInfo() = di.GetDirectories() Dim dra As IO.FileInfo 'list the names of all files in the specified directory For Each dra In diar1
ListBox1.Items.Add(dra)
Dim myProcess As Process = System.Diagnostics.Process.Start(updates.ToString & dra.ToString, options.ToString)myProcess.WaitForExit()
Next End Subutkuozan
However, be aware that this can cause btn_getfiles to be clicked again, so in btn_getfiles_Click place a check to see if the you have already started running the files.
km9
The reason is because you are updating a UI item (ie Control) from a thread that it wasn't created on.
Following is an example of the BackgroundWorker I quickly whipped up:
Imports System.IO
Public Class Form1
Private Sub OnStartButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _StartButton.Click
If (_BackgroundWorker.IsBusy) Then
_BackgroundWorker.CancelAsync()
Else
_ListBox.Items.Clear()
_BackgroundWorker.RunWorkerAsync("c:\")
Me._StartButton.Text = "Cancel"
End If
End Sub
Private Sub OnBackgroundWorkerDoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles _BackgroundWorker.DoWork
For Each fileName As String In Directory.GetFiles(e.Argument)
' Do some work
If (_BackgroundWorker.CancellationPending) Then
Exit For
End If
_BackgroundWorker.ReportProgress(0, fileName)
Next
End Sub
Private Sub OnBackgroundWorkerProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles _BackgroundWorker.ProgressChanged
_ListBox.Items.Add(e.UserState)
End Sub
Private Sub OnBackgroundWorkerRunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles _BackgroundWorker.RunWorkerCompleted
Me._StartButton.Text = "Start"
End Sub
End Class
This expects a couple of things on your form:
1. A Button control named _StartButton
2. A ListBox control named _ListBox
3. A BackgroundWork component named _BackgroundWorker
Simply replace the 'Do some work' comment with the work you need to do.