How to do this in VB?

Smoblikat

Diamond Member
Nov 19, 2011
5,184
107
106
OK, recycling thread...........

I now have the button open CMD and run a CD command, to put the path back to system332. But im also trying to run a second command after CD to start an ipconfig /all.
Whenever I click the button, CMD pops up and tells me that the system cannot find the file with the path specified. My code is:

Code:
Dim ipcmd As String
    Private Sub ipbut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ipbut.Click
        ipcmd = "ipconfig.exe /all"
        Shell("c:\windows\system32\cmd.exe /k " & cmdtxt.Text + ipcmd, AppWinStyle.NormalFocus)

Can someone please help me get CMD to open, run the CD for the proper directory, then run IPconfig after the CD executes?

CMDtxt.text = CD C:\windows\system32
 
Last edited:

brandonb

Diamond Member
Oct 17, 2006
3,731
2
0
Are both .exe's going to be on the flash drive? If they are going to be launched from the same location, the working directory for the .exe will be the flash drive, and you can just launch the other .exe without specifying a path at all and it will launch.

Can you give more details of what is installed (or are we just dealing with .exes located somewhere) and where both programs are going to reside?
 

Smoblikat

Diamond Member
Nov 19, 2011
5,184
107
106
Are both .exe's going to be on the flash drive? If they are going to be launched from the same location, the working directory for the .exe will be the flash drive, and you can just launch the other .exe without specifying a path at all and it will launch.

Can you give more details of what is installed (or are we just dealing with .exes located somewhere) and where both programs are going to reside?

Yes, both .exe's will be on the flash drive (or whatever storage medium the person decides). So I am creating a program, we can call it program A. The goal is to add buttons to it that will provide a one stop shop for all of our various tolls. I want to make one of the buttons activate program B (the other .exe, not one that I made). I know how to make a button activate a program, but not if the path is different for every person. The exe will be standalone, no installation required. I want to know how do I point the button to program B if the filepath is dynamic.
 

douglasb

Diamond Member
Apr 11, 2005
3,157
0
76
If the other .exe is located on the same flash drive, you can just use a relative path instead of an absolute path. They don't have to be in the same directory; just on the same drive.

If the other .exe is located elsewhere, then it becomes a little bit trickier. In that case, you would have to search for the file based on some criteria that you know of (file size, checksum, or something simliar).


EDIT: I see that both programs are on the same drive. Good. In that case, you can get your program's path through reflection, like this:

Code:
IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)

That will give you your program's path as a URL string. You may or may not want to parse out the "file:\" portion of it.
 
Last edited:

Smoblikat

Diamond Member
Nov 19, 2011
5,184
107
106
If the other .exe is located on the same flash drive, you can just use a relative path instead of an absolute path. They don't have to be in the same directory; just on the same drive.

If the other .exe is located elsewhere, then it becomes a little bit trickier. In that case, you would have to search for the file based on some criteria that you know of (file size, checksum, or something simliar).


EDIT: I see that both programs are on the same drive. Good. In that case, you can get your program's path through reflection, like this:

Code:
IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
That will give you your program's path as a URL string. You may or may not want to parse out the "file:\" portion of it.

Perfect, thank you.

This might be noobish............but where do I input the .exe name? :p
 

Jaydip

Diamond Member
Mar 29, 2010
3,691
21
81
I would recommend to create a batch file with all the command and then execute it; like this

Code:
Dim xProcess As New System.Diagnostics.Process

xProcess.StartInfo.FileName = "C:\jay.bat"

xProcess.StartInfo.UseShellExecute = True

xProcess.Start()
[IMG]http://i1.social.s-msft.com/globalresources/Images/trans.gif?cver=0%0d%0a[/IMG]
 

douglasb

Diamond Member
Apr 11, 2005
3,157
0
76
I would recommend to create a batch file with all the command and then execute it; like this

Code:
Dim xProcess As New System.Diagnostics.Process

xProcess.StartInfo.FileName = "C:\jay.bat"

xProcess.StartInfo.UseShellExecute = True

xProcess.Start()
[IMG]http://i1.social.s-msft.com/globalresources/Images/trans.gif?cver=0%0d%0a[/IMG]

This is the correct ".NET way" to do this. The VB-specific "Shell" method is something that was left in VB .NET for backwards compatibility with VB6 and so that VB6 programmers would be more comfortable when moving to VB .NET.