|
Answer» Hello,
I have zero experience writing bat files, but was told on the hope chat to come here and ask as it was the way to do it.
I can make a shortcut on a flashdrive pointing to a local .exe file on the same drive. However, the shortcut breaks if the drive letter changes when it's plugged into a different machine.
Any help would be appreciated.
THanksYou say the exe is on the flashdrive? If so, you may only need to eliminate the drive letter from the line that invokes the exe.
Can you post the bat file?I don't have a bat and wouldn't have the faintest idea how to write one. A loooong way from my area of expertise!
I asked in the live chat how I could create a shortcut for an exe on a flashdrive where the drive letter can (and does) change when it's used on different PCs.
Someone said to USE a bat file. I couldn't write one.
ThanksHow is the exe file being started? Why can't the user just double click on the exe?
Perhaps this is what the Original Poster wants.
He has a .EXE file on a flash drive that he wants to run other PCs in his group. He would like a shortcut or batch file that would include the best set of parameters for the .EXE file. And shorten the name of the shortcut or batch.
The problem is that the drive letter changes when the drive is moved to another PC. Poor example: try.bat is: F:\tryprogram.exe -a -b -c So he puts try.bat on F:\ and he then takes it to another computer whee the drive letter for the flash drive i G: and the program fails to start. Does this describe the problem?
If the exe is on the flashdrive then the invocation doesn't need to include the drive letter.
try.bat: tryprogram.exe -a -b -c
This would work if try.bat and tryprogram.exe are both in the same folder on the flashdrive and the user invokes try.bat from that folder. If try.bat was in the root folder of the flashdrive and tryprogram.exe was in a folder called tryme, then try.bat would look like this:
\tryme\tryprogram.exe -a -b -c
The problem would come into play if try.bat is on the user's C: drive and was trying to invoke tryprogram on the flashdrive, in that case the drive letter would be required. Thanks for all replies.
Salmon Trout - when I plug my USB in, I want to be able to run 6 programs from my USB. Each exe is SEVERAL folders deep - that's a lot of clicking.
I right clicked > send to > desktop (create shortcut).
That's fine until the drive letter changes.
Yes, that describes my problem Geek-9pm.
Strollin - so the code should be (for one of the programs)
\mikejava\109\IDE\eclipse\eclipse.exe -a -b -c
Thank you
Rather than send a shortcut to the desktop, one must create a shortcut or batch on the target drive. The the user must navigate to the target drive and start the batch or shortcut. Otherwise, this is, to my knowledge, no DOS thing that finds a drive letter for you. If thee was, the pseudo code would be: Code: [Select]For N=1 to 26 Type=FindDrive(n) IF Type =="USB" set Gotdit = NThat is not real code. It KINDA represent the idea if there was a FindDrive thing is DOS.
PowewrShell has something like that. Code: [Select]GET-WMIOBJECT –query “SELECT * from win32_logicaldisk where DriveType = ‘3’” Also in C++ there is a thing. Somewhere. Quote from: mike1980 on April 02, 2015, 06:40:17 PM Thanks for all replies. ...
Strollin - so the code should be (for one of the programs)
\mikejava\109\IDE\eclipse\eclipse.exe -a -b -c
Thank you
Yes, pretty much. If you put the batch file in the root of the flashdrive then change to the flashdrive before inoking the batch file.A batch file knows its own drive letter, it is given by %~D0 which expands to a letter and colon thus D: E: F: or whatever. A batch file in the root of a removable drive could have a line pointing to an exe anywhere else on that drive for example "%~d0\path\to\program file\program.exe" (quotes needed if path has spaces, does no harm to always use therm). If you wanted this program to run when a flash drive is inserted you are getting into autorun territory and will run into security implications.That's a good tip Salmonthe drive letter is not necessary as long as the batch file and the exe are on the same drive but it certainly doesn't hurt to include it.
|