execute PS or CMD from any directory in C: drive?


  1. Posts : 1,757
    Windows 10 Pro
       #1

    execute PS or CMD from any directory in C: drive?


    Can this be done?

    Configure Windows so that it recognizes the name of a CMD or PS command file, regardless of the current directory in the CMD box?

    Then I could consolidate all my various CMD and PS files into one directory, maybe something like \Program Files\CMD-Files.

    Oh yeah. Windows 10 Pro 64 2H22.
      My Computers


  2. Posts : 8,092
    windows 10
       #2

    To do that the files have to be in the path thats were windows checks for files open a cmd prompt type set to see the path
      My Computer


  3. Posts : 755
    Windows 7
       #3

    There's two separate environment variables for PATH. One for Windows system, another for your user profile. When you change one, it doesn't carry over to the other profile.

    Option 5, Changing environment variables in System Settings is the safest method.
    How to Edit User and System Environment Variables in Windows

    For example, add "C:\Program Files\CMD-Files;" to the end of the current PATH.
    C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\; C:\Windows\System32\OpenSSH\;C:\Users\GARLIN\AppData\Local\Microsoft\WindowsApps;C:\Program Files\CMD-Files;
      My Computer

  4.   My Computer


  5. Posts : 736
    Windows 10/11
       #5

    x509 said:
    Can this be done? Configure Windows so that it recognizes the name of a CMD or PS command file, regardless of the current directory in the CMD box? Then I could consolidate all my various CMD and PS files into one directory, maybe something like \Program Files\CMD-Files.
    Sure, but don't use "Program Files" (or "Program File (x86)") for these reasons 1) that's a protected folder, making it a pain to edit your scripts, 2) any data or settings that your script tries to save in a file in its own directory will get redirected by the Windows "VirtualStore" feature, and 3) That folder name contains a space making it just a tad harder to get your scripts to work correctly when they involve additional files.

    What I do is create a C:\Programs folder. Within that folder I place any portable apps (each in their own folder) that I download (or create myself). Also, within that folder, I create a folder that I add to the Windows search path and that's where I place console scripts and tools that I want to be able to run from the command line, regardless of the current folder. It can have any name. I named mine C:\Programs\OnPath.

    ⊞-R sysdm.cpl (or search env)
    Environment Variables
    User variables, Path, Edit

    execute PS or CMD from any directory in C: drive?-untitled.png
      My Computer


  6. Posts : 1,757
    Windows 10 Pro
    Thread Starter
       #6

    LesFerch said:
    Sure, but don't use "Program Files" (or "Program File (x86)") for these reasons 1) that's a protected folder, making it a pain to edit your scripts, 2) any data or settings that your script tries to save in a file in its own directory will get redirected by the Windows "VirtualStore" feature, and 3) That folder name contains a space making it just a tad harder to get your scripts to work correctly when they involve additional files.

    What I do is create a C:\Programs folder. Within that folder I place any portable apps (each in their own folder) that I download (or create myself). Also, within that folder, I create a folder that I add to the Windows search path and that's where I place console scripts and tools that I want to be able to run from the command line, regardless of the current folder. It can have any name. I named mine C:\Programs\OnPath.

    ⊞-R sysdm.cpl (or search env)
    Environment Variables
    User variables, Path, Edit

    execute PS or CMD from any directory in C: drive?-untitled.png
    I like this.
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 17:03.
Find Us




Windows 10 Forums