androidpowershelladbcommand-precedence

adb not working in powershell but adb.exe works


when typing "adb devices" in Powershell, it return a prompt to ask "How do you want to open this file". screenshot for the prompt However, if I use "adb.exe devices", it works and give me the list of devices.

As I have a lot of scripts written as adb instead of adb.exe, is there a way to fix this?

In cmd, typing adb devices would also work. But the scripts were all PS based. So fixing this in powershell will really helps. Thanks.


Solution

  • As you've confirmed, the problem was an extraneous, empty file literally named adb (without a filename extension) that resided in your C:\WINDOWS\system32 directory.

    Since the PATH environment variable (typically) lists C:\WINDOWS\system32 before the directory in which the desired target executable (adb.exe) is located, C:\Program Files (x86)\Intel\Platform\..., PowerShell attempted to execute C:\WINDOWS\system32\adb, which - as an extension-less file - triggered the GUI dialog you saw.

    Removing the extraneous C:\WINDOWS\system32\adb file solved your problem.

    Get-Command -All adb helped discovered the problem: it listed all forms of a command named adb known to PowerShell, in order of precedence, with information about their type and location; that is, the effective command - the one that is actually invoked - was listed first.

    Read on for background information.