I experience a wierd problem with SafeFileDialog: When used, application can't be closed properly and hangs in Background Processes in Task Manager, where I have to kill it (and it takes like 10 minutes before Windows kills it).
Try
SaveFileDialog1.Filter = "Text Files (*.txt*)|*.txt|Report file (*.rpt)|*.rpt"
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
Console.WriteLine("Hello World")
End If
Catch ex As Exception
Console.WriteLine("ERROR during saving report file. " & ex.Message)
End Try
No error or output message is produced and it seem to work as intended otherwise ("Hello World" is written into output).
Any ideas?
Related
Dim app As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
If System.IO.Directory.Exists(app & "\Divers") Then
Try
Process.Start(app & "\Divers\b.bat")
cs.Text = "OK"
cs.Refresh()
Catch ex As Exception
eror.Text = "(B) Problems"
cs.Text = "error"
End Try
Try
Process.Start(app & "\Divers\Realtek\diver.exe")
d.Text = "OK"
Catch ex As Exception
DebugLog()
error.Text = "Driver Problems"
cs.Text = "error"
End Try
Try
Process.Start(app & "\Divers\a.bat")
CVS.Text = "OK"
Catch ex As Exception
error.Text = eror.Text & "(A) Problems"
cs.Text = "error"
End Try
And that is my code guys but the bat file is not working. Is opened but do nothing, if i open the bat file manual (with a mouse and double click logic!!!) its working. Please help
Your batch file may be working based on a working directory, and because you run the batch file with software that is in a different folder, the batch file's working directory does not match.
Put your software in the batch file folder and try again.
Ok so I am trying to write a program to find a specific file on the C drive and get its location. However the following code does not work! I've researched this a lot and gone from GetFiles to Directory.enumerateFiles. However I keep running into an exception claiming that I have no access, simply ignoring the message (closing it/pressing ok) does not continue the search and instead stops it altogether, I need a way of bypassing this if possible, so If a directory causes an exception it will skip it and move along with no error on screen if possible.
Currently the manifest file is set to "requireAdministrator" so I know thats not the issue. Running VB as administrator does not solve, and running the compiled file as admin does not work either. Hope someone can help!
Note: I'm using Visual Basic 2010 Express and have no plans to upgrade to a newever version due to hardware limitation and operating system.
Imports System.IO
Public Class GuardianScanner
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.ReadOnly = True
TextBox1.ScrollBars = ScrollBars.Vertical
Button1.Enabled = False
TextBox1.AppendText(Environment.NewLine & "[INFO] Please wait while scanning. This can take a few minutes")
Try
For Each file As String In Directory.EnumerateFiles("C:\", "GodlyNorris.exe", SearchOption.AllDirectories)
TextBox1.AppendText(Environment.NewLine & "[INFO] Found virus: AUTONORRIS: " & file.ToString)
Next file
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
I tried posting this as a comment but it's pretty messy. This should work, basically it tries to create a directory out of every subdirectory in the C drive, and if it fails with the unauthorized access exception, it moves on to the next subdirectory.
For Each directory In New DirectoryInfo("C:\").GetDirectories()
Try
For Each file In directory.GetFiles("*", SearchOption.AllDirectories)
Try
TextBox1.Text += Environment.NewLine + file.Name
Catch ex As Exception
'MsgBox(ex.Message)
Continue For
End Try
Next
Catch ex As Exception
'MsgBox(ex.Message)
Continue For
End Try
Next
I am running a batch file with shell function in VB2010 with the following command
Shell("C:\test.bat", AppWinStyle.NormalFocus)
This process takes a lot of time to complete, might even take a day to complete depending on the input file.
I want a MsgBox to display a "Job Finished" msg when the process is finished.
something like
MsgBox("Job Finished")
How do I do that. I am very new to VB, so please help me with full code.
Thank you
This will basically wait till the process finishes (It finishes by exiting. as most batch files do. I'm only making an assumption though).
Sub Main()
Dim P As New Process
P.StartInfo.FileName = "C:\test.bat"
Try
P.Start()
P.WaitForExit()
MsgBox("Process completed successfully")
Catch ex As Exception
MsgBox("Error:" & ex.Message)
End Try
End Sub
I made an application that our company uses to launch databases and updates them on the users machine, when needed.
I am having a slight problem when it comes to launching databases and the database starts up slow. When this occurs my application throws an exception, as I assuming its awaiting some kind of response back.
As of now the error thrown is: The system cannot find the file specified
I am trying to prevent this exception logging for cases like this(Slow Application), but still allow the logging if a real error occurs while opening a database.
Current Code I am using:
Private Sub OpenApplication()
If File.Exists(LocalPathString) Then ' File Found. Open the File.
Try
Dim ps As New Process
ps = Process.Start(LocalPathString)
Catch ex As Exception
ex.Source += " | " & LocalPathString
RaiseEvent ShowError(ex)
Finally
RaiseEvent CancelIt() ' Thread Complete. Close the ActionForm
End Try
Else
If LocalPathString = vbNullString Then
RaiseEvent CancelIt() ' No file exits. Cancel thread.
Else
RaiseEvent ShowError(New Exception("Database Not Located: " & LocalPathString))
End If
End If
End Sub
StackTrace:
System.Diagnostics.Process.StartWithShellExecuteEx(startInfo As ProcessStartInfo)
App.exe: N 00912
System.Diagnostics.Process.Start()
App.exe: N 00136
System.Diagnostics.Process.Start(startInfo As ProcessStartInfo)
App.exe: N 00049
SAMi.ActionClass.OpenApplication()
App.exe: N 00117
Maybe I'm missing something, but why don't you simply omit the logging if you found that specific exception?
Catch ex As Exception
ex.Source += " | " & LocalPathString
if not ex.Message.Contains("The system cannot find the file specified") Then
RaiseEvent ShowError(ex)
end if
I'm using VB.net to have a GUI on top of a commandline program.
Dim sqliProcess As New Process()
sqliProcess.StartInfo.UseShellExecute = False
sqliProcess.StartInfo.RedirectStandardOutput = True
sqliProcess.StartInfo.RedirectStandardError = True
sqliProcess.StartInfo.FileName = "C:\shell_program.exe"
sqliProcess.StartInfo.CreateNoWindow = True
sqliProcess.Start()
Do While Not bw.CancellationPending
Try
If Not sqliProcess.StandardOutput.EndOfStream Then
Debug.Print(sqliProcess.StandardOutput.ReadLine)
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error reading output")
End Try
Threading.Thread.Sleep(1)
Loop
Which works and prints out all output from the commandline program. However at some point the commandline program ask for user interaction, eg:
Type a number (1/2/3/4):
But the commandline program stops after this. I suspect this is because it doesn't receive a valid option.
Is there a way to capture when the commandline program wants user interaction and hold the reading of the stream to be able to enable the user to input something?
It's not that hard if you use the events. (Don't forget EnableRaisingEvents). Look here at outputdatareceived..