1

I'm new to Windows. I installed adb and fastboot files (platform-tools) for Windows, and added the folder in the path variable so that I can access adb universally.

I did some research, and found that Windows is slowly shifting to PowerShell (which is good) and (I guess) will omit the legacy CMD eventually. So even the [Shift+Right click] menu shows an option to "Open PowerShell window here". I've read some articles and am familiar with registry hacks to add "Open Command Prompt Here" and remove "Open PowerShell window here", but that's not something I would want to do, considering PowerShell is a lot more advanced than CMD.

Now, when I open PowerShell in the same folder where I've installed platform-tools and run the adb command, I get this and it's successful.

.\adb devices  
.\adb.exe devices  

But when I open PowerShell elsewhere and run the command, it's not successful. Why is the behavior so even when I added the adb folder to the path variable? And how can I run the command successfully universally?

During my search, I found an application which provides PowerShell ADB & Fastboot GUI - PoshADB (just wanted to share).

Please note that adb devices works just fine in cmd, universally.

--

A conclusion I drew from the answer below:

  • When adb files are NOT on my PATH

    • These work in the same folder where adb is installed:

      • Call by full path
        • .\adb devices
        • .\adb.exe devices
    • This works universally:

      • Call by full path
  • When adb files are ON my PATH

    • These work in the same folder where adb is installed:

      • Call by full path
        • .\adb devices
        • .\adb.exe devices
      • adb devices
    • These works universally:

      • adb devices
      • Call by full path

For my future reference- (Concisely: If it's not on your PATH then you have to enter the full path for it to work. And if it's on your PATH then you can just type adb devices, or mention the full path of adb)

  • 2
    don't use "dot sourcing" just "adb.exe devices " if it's in your path or use full paths. "dot sourcing" is used in the current directory to prevent unwanted execution PS you may or may not need to modify you command so that the syntax is acceptable by powershell – Jaqueline Vanek Sep 17 '17 at 9:04
  • 1
    PPS use "$Env:Path" to check your path variable from powershell – Jaqueline Vanek Sep 17 '17 at 9:13
  • Small OT-addition: [...] registry-hacks to add 'Open Command Prompt Here' and remove 'Open PowerShell Window here' are not necessary. Go to the new Settings panel -> Personalization -> Taskbar -> uncheck "Replace Command Prompt with Windows PowerShell [...]". – flolilo Sep 17 '17 at 10:24
  • As @Jaqueline mentioned, I can confirm adb.exe devices works fine in the same folder as where the platform-tools are. But since I've added that folder to the path variable (can also confirm it using $Env:Path), the same command adb.exe devices works universally as well. This answers my question very well. Thank-you! However, I'm not able to understand " "dot sourcing" is used in the current directory to prevent unwanted execution". Yes, I can also confirm that in the same folder, .\adb.exe devices and .\adb devices works, but not universally. – swingcake Sep 17 '17 at 14:22
  • Also @flo I would like to correct the information you provided. That option you're referring to by Go to the new Settings panel -> Personalization -> Taskbar -> uncheck "Replace Command Prompt with Windows PowerShell [...]", it only replaces them when you right click the start button or when you press Windows key+X. What I'm talking about in my original post is the context menu Anyways, thanks for the comment! :) – swingcake Sep 17 '17 at 14:36
1

When you use .\ to run a command, you're telling PowerShell to look only in the current directory for it - the dot means "this folder," just like in the old command processor. If the thing you're trying to run is not in the current folder, even if it is on the PATH, that will fail. Note that the term "dot-sourcing" refers to the execution of PowerShell scripts in the current scope instead of their own, which is different from running a command from the current directory.

You can type the program's name without .\ anywhere to run it if it is on your PATH. Note, though, that PowerShell will not see changes to PATH or any environment variable until you restart it. After you adjusted the environment variable and opened a new PowerShell, simply adb is sufficient to identify the program you want to run, no matter your current directory.

  • "until you restart it" so got it. now, how to restart a posh session? – Jaqueline Vanek Sep 19 '17 at 23:51
  • @JaquelineVanek Closing and reopening the PowerShell window should be sufficient, but a logoff/logon cycle would definitely refresh all environment variables. – Ben N Sep 20 '17 at 3:52
  • @BenN Consider that adb files are not on my PATH. Now how do I run/ execute/ flash a file that's not present in the same folder. How do I navigate to that file from the adb folder? – swingcake Sep 21 '17 at 13:52
  • @unixf You can use cd to change the current directory (much like in the old command processor), or you can enter a relative (e.g. subfolder\program.ext) or fully qualified path (e.g. C:\somefolder\subfolder\program.ext) to run a program that resides somewhere else than the current directory. – Ben N Sep 21 '17 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.