Question for CMD experts

Page 1 of 2 12 LastLast

  1. Posts : 1,728
    Windows 10 Pro x64 22H2
       #1

    Question for CMD experts


    I know there are many individuals here skilled with CMD and shortcuts so here is my question...

    I have a shortcut on my desktop which is a shortcut to Visual Studio compiler configuration which when opened loads development environment into the console that it opens.

    Right click -> properties on that shortcut says this:

    Target:
    Code:
    %comspec% /k "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
    Path:
    Code:
    C:\path\to\my projects
    When the shortcut is opened it runs the command from "Target" entry and opens command line specified in "Path" entry.
    Once it's opened I run the following command in the console:
    Code:
    code .
    This open VSCode in the specified "Path" and picks up set evironment specified by "Target".

    What I want to achieve is to modify either "Target" or "Path" property so that when I run the shortcut it will automatically open VSCode in the specified "Path" once the "Target" has been executed.

    Is that possible and how would I modify this shortcut?
      My Computer


  2. Posts : 17,099
    Windows 10 Home x64 Version 22H2 Build 19045.5371
       #2

    I'm confused about what you want.
    You seem to be saying that it is already opening to the desired path.

    Denis
      My Computer


  3. Posts : 1,041
    Windows 7
       #3

    With shortcut:
    %comspec% /k "C:\Users\GARLIN\Downloads\zebal.bat"

    zebal.bat
    Code:
    REM call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
    @echo arg1 is %1
    cd %~p1
    REM code .

    Dragging my file over the shortcut:
    arg1 is C:\Users\GARLIN\Desktop\randomfile.txt

    C:\Windows\System32>cd \Users\GARLIN\Desktop\

    C:\Users\GARLIN\Desktop>
      My Computer


  4. Posts : 1,728
    Windows 10 Pro x64 22H2
    Thread Starter
       #4

    Try3 said:
    I'm confused about what you want.
    You seem to be saying that it is already opening to the desired path.
    It is opening the desired path but it not executing
    Code:
    code .
    which I need to type each time the shortcut it run.
    I wan to automate this and open VSCode in the path right away.

    @garlin
    Are you saying I should create a bat file that calls vcvars64.bat and then run code . in it?
    and the path would be argument to that batch file?
    I'll test it.

    btw
    Code:
    code .
    is a command to open VSCode in current working directory, I want to automate it.
      My Computer


  5. Posts : 1,041
    Windows 7
       #5

    Forgot if you're crossing drive letters, it's "cd /d %~p1"
      My Computer


  6. Posts : 1,728
    Windows 10 Pro x64 22H2
    Thread Starter
       #6

    @garlin
    It works! thanks a lot, sadly I couldn't rep you.

    but, why do I need to specify random file?
    is there a way to specify just path?

    EDIT:
    OK, I figured out, it's as simple as:

    Code:
    call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
    @echo arg1 is %1
    cd %1
    code .
    But the %~p1 is unknown thing to me, now if I could only do this without creating a custom batch file, ex. doing it all in "Target" path...
    But this will suffice for single click run.
      My Computer


  7. Posts : 1,041
    Windows 7
       #7

    %~pvar means to strip %var to its base pathname. If you're dragging folders (not files), I guess it's okay.
    Never played with VSCode, I just don't want to give an IDE more disk space than Windows...
      My Computer


  8. Posts : 17,099
    Windows 10 Home x64 Version 22H2 Build 19045.5371
       #8

    zebal said:
    But the %~p1 is unknown thing to me
    There's a guide that doubles as a demo script for such parameters in
    my ditty and demo for: Standard passable variables [post #47] - TenForums
    There are other batch file guides, including a guide-demo for other variable manipulations, in
    my ditty Batch file and PowerShell guides [post #16] - TenForums



    All the best,
    Denis
      My Computer


  9. Posts : 1,728
    Windows 10 Pro x64 22H2
    Thread Starter
       #9

    @Try3
    Thanks I might take a look at this next time I face cmd related issues,
    sadly it takes too much time to learn a language from zero, batch scripting has never been attractive to me :/
      My Computer


  10. Posts : 17,099
    Windows 10 Home x64 Version 22H2 Build 19045.5371
       #10

    zebal said:
    sadly it takes too much time to learn a language from zero, batch scripting has never been attractive to me :/
    And, if you are ever going to put in the effort to learn something new, I think that effort will be better rewarded by studying PowerShell rather than batch scripting.

    Denis
      My Computer


 

  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 22:32.
Find Us




Windows 10 Forums