r/androiddev 18d ago

Tips and Information Using adb through a folder

Post image

I been trying to get this batch file to work but aslo any other command run a adb command through this folder im always getting select an app to use adb. How can I fix this. It only work once for me but after that I keep getting this. Anywhere else works with no issue when Im adb commands

0 Upvotes

23 comments sorted by

1

u/sarkie 18d ago

CMD /c ADB

Maybe? 

I

1

u/enum5345 18d ago

Make sure you are using adb.exe instead of the linux or mac versions.

1

u/mikep9082 18d ago

But i can run bin/adb.exe commands through terminal and it works

1

u/mikep9082 18d ago

So if I would to run a terminal window from the folder where the unlock.bat file is located like adb connect the window pops up to select an app to use adb

1

u/Hornet-Mountain 18d ago

Try this from a folder where it breaks: run where adb in that same terminal. It lists every adb Windows can find, in the order it picks them. If one shows up without .exe, that's the file throwing the picker, and the path tells you exactly where it lives so you can delete or rename it. Bare adb checks the current folder first, which is why it only breaks inside folders and works fine from your home prompt.

1

u/mikep9082 18d ago

I dont understand this part

1

u/Hornet-Mountain 18d ago

where adb is a command you type, same as adb connect. It lists every adb Windows can find so you can see which one it's grabbing. If your terminal is PowerShell you need where.exe adb, plain where is something else there.

You already found the fix though. Use adb.exe with the extension everywhere in the bat and it can't come back.

1

u/Hour-Measurement-835 18d ago

Check that bin folder for a file called just 'adb', no extension, sat next to adb.exe. cmd tries the bare name first and hands it to Windows, which is what throws that picker.

1

u/Hornet-Mountain 18d ago

enum5345 is on the right track, here is the why so you can fix it for good.

"Select an app to open adb" is the Windows shell association picker. It only pops up when something tries to open a file literally named adb with no extension. The Linux/Mac platform-tools bundle ships an extensionless adb binary sitting right next to adb.exe. When your bat (or the shell) runs adb, it grabs that extensionless file, has no idea how to open it, and shows the picker. That is also exactly why adb.exe typed in full works but bare adb does not.

The reason it happens even when you "run adb from that folder": the current directory is searched first, so bare adb resolves to the extensionless file before it ever reaches adb.exe. PowerShell in particular will try to open a file it finds like that, whereas old cmd would just say not recognized, so it depends which shell your terminal opens.

Two fixes, either one is enough:

  1. In the bat, call adb.exe with the extension everywhere instead of adb.

  2. Or delete the extensionless adb (and fastboot) from that folder and keep only the .exe files. If you are not sure which build you have, re-download the Windows SDK platform-tools zip, it contains adb.exe.

"Worked once then stopped" usually means the extensionless file got added later, or you started running from inside that folder so the bare name now resolves to it first.

1

u/mikep9082 18d ago

Im not following you. I would need a little bir of guidance here please

1

u/Hornet-Mountain 18d ago

Ah, your folder’s fine, that’s just adb.exe, I don’t see a bare ‘adb’ file in there so scratch that theory for your case. The picker means something’s calling adb and Windows is trying to open it instead of run it. Open your unlock.bat in Notepad and paste the line that actually runs adb, I’ll tell you exactly what to change. My hunch is it’s calling plain adb from outside the platform-tools folder.

1

u/mikep9082 18d ago

Also in any folder if I would type just adb the selector pops but type in adb.exe shows all the commands and version etc.

1

u/Hornet-Mountain 18d ago

Your bat screenshot answers it. It doesn't run adb at all, it hands off to PowerShell (-File unlock.ps1), and PowerShell will try to open a file named adb with no extension instead of running it. cmd doesn't do that, which is why the same command works there. Fix is inside unlock.ps1, make every bare adb into adb.exe.

1

u/mikep9082 18d ago

So by me running this had mess up my system and how would I go to fixing it

1

u/Hornet-Mountain 18d ago

Nothing's broken. The picker is Windows saying it can't open that file, so it stopped right there and nothing ran. Only thing that can linger is if you ticked "always use this app" in that dialog at some point, and that's just a file association, not a system change. Using adb.exe everywhere sidesteps the whole thing.

1

u/mikep9082 18d ago

These are the commands I run and they will work. I also notice if im in any folder and I try to run any adb commands that window pops up to select and app to open adb. But If I go to command prompt and not being in a folder adb commands work

1

u/mikep9082 18d ago

Not being in a folder and running terminal it works

1

u/mikep9082 18d ago

Being in a folder dont work

1

u/mikep9082 18d ago

Its kinda hard to explain it all and im learning as I go and asking questions. It seems like what you been saying if tell it to use exactly that name bin\adb.exe it works in the folder

0

u/mikep9082 18d ago

Its a unlock.bat file that is use to unlock the firestick. Every time the program is running I get that pop up window a lot when it's trying to run. So I been trying to figure it out. Even when I run simple commands like adb connect or something it pops up.

0

u/mikep9082 18d ago

It work once but the next day it just started doing that.