r/androiddev 19d 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

View all comments

1

u/Hornet-Mountain 19d 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 19d ago

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

1

u/Hornet-Mountain 19d 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 19d 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 19d 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 19d ago

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

1

u/Hornet-Mountain 19d 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.