hey all,
I writen this code (below) it use's a background worker to run the 2 dos commands and display them to the listbox as they run.
I had it working well but i made one samll change and now it keeps failing.
the error is;
System.Reflection.TargetInvocationException was unhandled
Message="Exception has been thrown by the target of an invocation."
Source="mscorlib"
StackTrace:
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at Helpdesk_support.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
here's the code. If anyone knows why this is happening please tell me!!!
Public Class menu2
Private WithEvents testworker As System.ComponentModel.BackgroundWorker
Private Sub start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles start.Click
start.Enabled = False
Btncancel.Enabled = True
statuslist.Items.Clear()
prgthread.Value = 0
prgthread.Maximum = 2
testworker = New System.ComponentModel.BackgroundWorker
testworker.WorkerReportsProgress = True
testworker.WorkerSupportsCancellation = True
testworker.RunWorkerAsync()
End Sub
Private Sub testworker_dowork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles testworker.DoWork
Dim value As Integer
For value = 0 To 0
Dim listtext As String
Dim args As String = "/c net use \\crc3 /user:meg_swan\tristan.drinkwater password"
Dim p As New Process()
Dim FileName As String = "cmd"
Dim Arguments As String = args
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.RedirectStandardError = True
p.StartInfo.CreateNoWindow = True
p.StartInfo.FileName = FileName
p.StartInfo.Arguments = Arguments
p.Start()
Dim output1 As IO.StreamReader = p.StandardOutput
While (Not output1.EndOfStream)
listtext = String.Concat(output1.ReadLine)
testworker.ReportProgress(value, listtext)
End While
If testworker.CancellationPending Then
Exit Sub
End If
'Threading.Thread.Sleep(10 * 100)
Next
GoTo lable1
lable1:
Dim value1 As Integer
For value1 = 0 To 0
Dim listtext1 As String
Dim args1 As String = "/c copy c:\test.txt \\crc3\c$\nice10.txt"
Dim p As New Process()
Dim FileName1 As String = "cmd"
Dim Arguments1 As String = args1
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.RedirectStandardError = True
p.StartInfo.CreateNoWindow = True
p.StartInfo.FileName = FileName1
p.StartInfo.Arguments = Arguments1
p.Start()
Dim output1 As IO.StreamReader = p.StandardOutput
While (Not output1.EndOfStream)
listtext1 = String.Concat(output1.ReadLine)
testworker.ReportProgress(value1, listtext1)
End While
If testworker.CancellationPending Then
Exit Sub
End If
'Threading.Thread.Sleep(10 * 100)
Next
End Sub
Private Sub testworker_progresschanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles testworker.ProgressChanged
prgthread.Value = prgthread.Value + 1
statuslist.Items.Add(e.UserState)
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btncancel.Click
testworker.CancelAsync()
statuslist.Items.Clear()
prgthread.Value = 0
End Sub
Private Sub testworker_runworkercompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles testworker.RunWorkerCompleted
start.Enabled = True
Btncancel.Enabled = False
End Sub
End Class
cheers guys!
I writen this code (below) it use's a background worker to run the 2 dos commands and display them to the listbox as they run.
I had it working well but i made one samll change and now it keeps failing.
the error is;
System.Reflection.TargetInvocationException was unhandled
Message="Exception has been thrown by the target of an invocation."
Source="mscorlib"
StackTrace:
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at Helpdesk_support.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
here's the code. If anyone knows why this is happening please tell me!!!
Public Class menu2
Private WithEvents testworker As System.ComponentModel.BackgroundWorker
Private Sub start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles start.Click
start.Enabled = False
Btncancel.Enabled = True
statuslist.Items.Clear()
prgthread.Value = 0
prgthread.Maximum = 2
testworker = New System.ComponentModel.BackgroundWorker
testworker.WorkerReportsProgress = True
testworker.WorkerSupportsCancellation = True
testworker.RunWorkerAsync()
End Sub
Private Sub testworker_dowork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles testworker.DoWork
Dim value As Integer
For value = 0 To 0
Dim listtext As String
Dim args As String = "/c net use \\crc3 /user:meg_swan\tristan.drinkwater password"
Dim p As New Process()
Dim FileName As String = "cmd"
Dim Arguments As String = args
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.RedirectStandardError = True
p.StartInfo.CreateNoWindow = True
p.StartInfo.FileName = FileName
p.StartInfo.Arguments = Arguments
p.Start()
Dim output1 As IO.StreamReader = p.StandardOutput
While (Not output1.EndOfStream)
listtext = String.Concat(output1.ReadLine)
testworker.ReportProgress(value, listtext)
End While
If testworker.CancellationPending Then
Exit Sub
End If
'Threading.Thread.Sleep(10 * 100)
Next
GoTo lable1
lable1:
Dim value1 As Integer
For value1 = 0 To 0
Dim listtext1 As String
Dim args1 As String = "/c copy c:\test.txt \\crc3\c$\nice10.txt"
Dim p As New Process()
Dim FileName1 As String = "cmd"
Dim Arguments1 As String = args1
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.RedirectStandardError = True
p.StartInfo.CreateNoWindow = True
p.StartInfo.FileName = FileName1
p.StartInfo.Arguments = Arguments1
p.Start()
Dim output1 As IO.StreamReader = p.StandardOutput
While (Not output1.EndOfStream)
listtext1 = String.Concat(output1.ReadLine)
testworker.ReportProgress(value1, listtext1)
End While
If testworker.CancellationPending Then
Exit Sub
End If
'Threading.Thread.Sleep(10 * 100)
Next
End Sub
Private Sub testworker_progresschanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles testworker.ProgressChanged
prgthread.Value = prgthread.Value + 1
statuslist.Items.Add(e.UserState)
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btncancel.Click
testworker.CancelAsync()
statuslist.Items.Clear()
prgthread.Value = 0
End Sub
Private Sub testworker_runworkercompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles testworker.RunWorkerCompleted
start.Enabled = True
Btncancel.Enabled = False
End Sub
End Class
cheers guys!