I'm making a little application in visual studio which loads a ROM in an emulator. I have two emulators and 20 ROMs.
I made a form and added a few buttons. When you click the Button it opens a new form and closes the old one. Then on the new form I have four buttons: each one loads a different ROM in an emulator. So when you press Button1 this code is triggered:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles yellow.Click
Shell("C:\Users\shifty\Desktop\pokemon games\Emulator\VBA\VisualBoyAdvance.exe ""C:\Users\shifty\Desktop\pokemon games\Roms\Yellow\Pokemon Yellow.gb""", vbNormalFocus)
End Sub
It works fine - I click it and it loads the game in the emulator. The bit im having trouble with is the file paths. If I send this application to a friend, it would still look for "C:\Users\shifty\Desktop\" - but that's on my computer, not his.
Is there a way to make the application look for the file on his computer (without changing the file path to (C:\Users\""his user name""\Desktop))
You need to use a file open dialog to choose your path for the two files. Here is an example.
You then use the two paths in your code:
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
This will resolve to be the desktop folder for the current user.
It will even work between XP, vista and Windows 7 properly.
Really old post at this point, but hey, found what I was looking for.
MC SH1FTY, I assume you have figured this out already, but to do what you are trying to do:
1) Call in that code that Spence wrote as a variable (I'd declare it Globally, but that's my preference. To do that:
2) Either use this DIRECTLY in your code, or make another string to concatenate a directory:
Option A)
Then, within your Subroutine, replace your current
Shell
statement with:Or, Option B, which is thedsz's answer:
There's a mechanism to get the current user's Desktop directory, using
Environment.SpecialFolder
.Usage:
Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
the answer is simple.
Old post but I have to side with Mc Shifty. You can't assume that everyone is a coding expert. If they were then they wouldn't be here asking questions like that.
None of the answers given above were complete
Environment.GetFolderPath(Environment.SpecialFolder.Desktop))
<<< includes and extra )Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
<<< extra ) and the ; is C or java not VB which he is obviously using by his example code.Both of those only give you half of the required code to generate something usable.
The above code will give you the result needed, c:\users\shifty\desktop