Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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")

It's not impossible, it's Inevitable.
Posted

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

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.

Posted
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.

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.

Posted
Dude' date=' they both work.[/quote']

Like, obviously shell didn't, dude.

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.

Posted
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.

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.

Posted

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...

It's not impossible, it's Inevitable.
Posted
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!!!! :)

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.

Posted

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

Wanna-Be C# Superstar
  • *Experts*
Posted
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

Posted

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 Sub

TraceProc.zip

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.

Posted

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

Wanna-Be C# Superstar
Posted
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?

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.

Posted
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

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...