PureSc0pe Posted July 19, 2004 Posted July 19, 2004 If you go to run, cmd and then type in tracert and then a site name, it will give you info on the site route...I'm trying to integrate it into my program. My idea was to have it run from the local run, cmd file and save it to a .txt and then have it load to the listbox via a 20 second timer or w/e... Anyone have any ideas as to why this doesn't work? Shell("TextBox13.Text, tracert /c > C:\trace.txt") Quote It's not impossible, it's Inevitable.
Joe Mamma Posted July 19, 2004 Posted July 19, 2004 Anyone have any ideas as to why this doesn't work? Shell("TextBox13.Text, tracert /c > C:\trace.txt") bad vb'er, bad!!! lookup Process.Start Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
PureSc0pe Posted July 19, 2004 Author Posted July 19, 2004 bad vb'er, bad!!! lookup Process.Start Dude, they both work. Quote It's not impossible, it's Inevitable.
Administrators PlausiblyDamp Posted July 19, 2004 Administrators Posted July 19, 2004 Yes but Process.Start is the .Net way of doing things, Shell is a legacy vb6 function. Process.Start gives you far more control over running a process - including redirecting input / output to streams, which is what you are after. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Joe Mamma Posted July 19, 2004 Posted July 19, 2004 Yes but Process.Start is the .Net way of doing things, Shell is a legacy vb6 function. Process.Start gives you far more control over running a process - including redirecting input / output to streams, which is what you are after. Process.Start is the way pretty much every other language does it, .NET or not. Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Joe Mamma Posted July 20, 2004 Posted July 20, 2004 Dude' date=' they both work.[/quote'] Like, obviously shell didn't, dude. Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
PureSc0pe Posted July 20, 2004 Author Posted July 20, 2004 Like' date=' obviously shell didn't, dude.[/quote'] I got other help and used shell. It now works, dude. Quote It's not impossible, it's Inevitable.
Joe Mamma Posted July 20, 2004 Posted July 20, 2004 I got other help and used shell. It now works' date=' dude.[/quote'] My suggestion is you learn to use the Process object. It really is the way to go. You won't need the timer, which is a windows allocated resource. Use the Process and you will have total control over the I/O of the tracert execution. But thats up to you. I can pound screws with a hammer, I choose to use nails. I can pound nails with a screwdriver, I choose to use a hammer. Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
PureSc0pe Posted July 20, 2004 Author Posted July 20, 2004 Point taken, I shall use this from now on. Thanks for taking the time to show me the correct way, despite my initial reaction... :) p.s. Sorry for being a pest... Quote It's not impossible, it's Inevitable.
Joe Mamma Posted July 20, 2004 Posted July 20, 2004 Point taken, I shall use this from now on. Thanks for taking the time to show me the correct way, despite my initial reaction... :) p.s. Sorry for being a pest...No apology necessary. Its all fun! :) I needed the VB practice. . . Did I just say that??? AYE-YIE-YIE!!! SHOOT ME NOW!!!! :) Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
VBAHole22 Posted July 20, 2004 Posted July 20, 2004 Great code Joe. Thanks for the tip. I learned a few things just from that little sample. Quote Wanna-Be C# Superstar
VBAHole22 Posted July 20, 2004 Posted July 20, 2004 actually I think the first one worked better for me. I get an unhandled exception now on If proc.Handle.Equals(IntPtr.Zero) Then on your latest version Quote Wanna-Be C# Superstar
*Experts* mutant Posted July 20, 2004 *Experts* Posted July 20, 2004 actually I think the first one worked better for me. I get an unhandled exception now on If proc.Handle.Equals(IntPtr.Zero) Then on your latest version Are you getting a NullReferenceException? If yes then you probably pressed the button that closed the program before you pressed the button that initialized the process and since there was no error handling to see if the process has started it simply gave you an unhandled exception. BTW. Joe Mamma, if you want the code to be so clean don't use the VB NewLine constant but use System.Environment.NewLine instead; and use TextBox1.AppendText(text) method instead of TextBox1.Text = TextBox1.Text + text. :D Quote
VBAHole22 Posted July 20, 2004 Posted July 20, 2004 it is a NullRef Exception but it comes after a successful trace. Quote Wanna-Be C# Superstar
Joe Mamma Posted July 20, 2004 Posted July 20, 2004 sorry, in adequate testing. . . (DELETED OLD POSTINGS) this should work (changed the button2 click handler): Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If proc Is Nothing Then Application.Exit() Else If Not proc.HasExited Then If MessageBox.Show("Terminate Process?", _ "Terminate " & Me.Text, _ MessageBoxButtons.YesNo, _ MessageBoxIcon.Question, _ MessageBoxDefaultButton.Button2) = DialogResult.Yes Then proc.Kill() End If If proc.HasExited Then Application.Exit() End If Else Application.Exit() End If End If End SubTraceProc.zip Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
VBAHole22 Posted July 20, 2004 Posted July 20, 2004 Now it bails on the next line If Not proc.HasExited Then It's cool though. I get the idea. Just seems tough working with these delegates and events Quote Wanna-Be C# Superstar
Joe Mamma Posted July 20, 2004 Posted July 20, 2004 Now it bails on the next line If Not proc.HasExited Then It's cool though. I get the idea. Just seems tough working with these delegates and events Story of my life. . . they keep telling me, "if it ain't broke, dont fix it!!!" hmmm. . . I downloaded my last code to a different machine (i am at work now) and clicked the close button in three different scenarios and not recv'd an error. scenarios: 1. Click 'Close' button with out running the tracert no error 2. Click 'Close' button while tracert is running no error 3. Click 'Close' button after tracert complete no error am I missing a scenario? Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Joe Mamma Posted July 21, 2004 Posted July 21, 2004 Are you getting a NullReferenceException? If yes then you probably pressed the button that closed the program before you pressed the button that initialized the process and since there was no error handling to see if the process has started it simply gave you an unhandled exception. BTW. Joe Mamma, if you want the code to be so clean don't use the VB NewLine constant but use System.Environment.NewLine instead; and use TextBox1.AppendText(text) method instead of TextBox1.Text = TextBox1.Text + text. :D thanks, I was looking for that! I am used to Delphi's TMemo which utilizes an ArrayList of Strings Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.