0

i used this example to open a command prompt from within vb.net 2010

lnk to stackoverflow document

the command prompt opens as expected and i can do directories open commands like regedit etc. without an issue

but what i really want is tftp.exe when i look for it it does not show up, when doing a dir it is not listed when type tftp at command prompt i get the to recognzed command

when comparing to a normal command prompt by type cmd at the run line i can see it in the windows\system32 folder

also when i do a dir from normal command prompt and compare to dir from the cmd prompt opened by vb.net there is a 400+ number of files difference out of close to 3000 files

trying to find out why i cant see all the files here is the actul code i used

Private Sub Button30_Click(sender As System.Object, e As System.EventArgs) Handles Button30.Click
        Dim command As String = "tftp -i 192.168.10.177 put test1.bin"
        Dim arguments As String = ""
        Dim permanent As Boolean = True
        Dim p As Process = New Process()
        Dim pi As ProcessStartInfo = New ProcessStartInfo()
        pi.Arguments = " " + If(permanent = True, "/K", "/C") + " " + command + " " + arguments
        pi.FileName = "cmd.exe"
        p.StartInfo = pi
        p.Start()
    End Sub
Community
  • 1
  • 1
Robert Allen
  • 150
  • 1
  • 16
  • 1
    What exactly are you trying to accomplish with this. Why not just have your code directly call tftp.exe? – JohnFx Jan 12 '13 at 00:50
  • i am if you look at the code it is calling tftp -i 192.168.10.177 put test1.bin, and it does not see it i get the command not found so i tried to execute manually and it cant find it either. unless there is another way i should be trying to call it. – Robert Allen Jan 12 '13 at 01:01
  • You don't need to use cmd.exe just run the tftp command directly. Your approach is very convoluted and unnecessary. – JohnFx Jan 12 '13 at 05:24
  • i took it 1 step further or lessoned the code to just dim oprocess as process and next line oprocess.start("notepad.exe") and notepad opens but if i change notepad.exe to tftp.exe i get a files not found error. and both files are in the same directory – Robert Allen Jan 12 '13 at 08:25

2 Answers2

1

This seems like a very convuluted approch you are taking, but to answer your question directly, you probably need to set the working directory like so:

pi.WorkingDirectory = "c:\windows\system32"

I have to say though, you might want to reconsider the whole approach of opening a DOS window for the user to type commands. Doesn't see very user friendly.

JohnFx
  • 34,542
  • 18
  • 104
  • 162
  • i dont want the box to stay open when it is working if i change the command on line 2 to somethign else in that directory it runs ie xcopy . again only leaving cmd prompt open till i find why it doesnt see the tftp.exe file – Robert Allen Jan 12 '13 at 01:05
  • i tried addign working directory same result. the wierd thing is if i do a dir tftp*.* nothing is found but if i do dir tftp*.* from a normal cmd prompt it is there – Robert Allen Jan 12 '13 at 01:11
  • i took it 1 step further or lessoned the code to just dim oprocess as process and next line oprocess.start("notepad.exe") and notepad opens but if i change notepad.exe to tftp.exe i get a files not found error. and both files are in the same directory – Robert Allen Jan 12 '13 at 01:32
0

ok found the answer, it is becuase i am running 64bit windows and when its looking for the tftp.exe it is actually looking in the syswow64 directory and tftp.exe is not in that directory.

since i have this running and compiled for x86 and not 64bit here is the work around

Public Declare Function Wow64DisableWow64FsRedirection Lib "kernel32" (ByRef oldvalue As Long) As Boolean

then

Wow64DisableWow64FsRedirection(0)

after adding tthis to my code the tftp upload works flawlessly

Robert Allen
  • 150
  • 1
  • 16