How to run batch file inside Visual Studio 2022 Developer Command Prompt - batch-file

I recently upgraded to VS2022 I cannot find a way to start developer command prompt and run a batch file inside it. Previously I called vsvars32.bat and it set all variables and paths, allowing me to continue in my .bat file. In the current version it does not work and when I call VsDevCmd.bat, the rest of commands in my batch file are not executed.
Is there a way to call developer command prompt or set paths and variables from batch file and continue?

I did not find any other solution so ended up using pipe like this:
type cmds.txt | "c:\Program Files\Microsoft Visual
And cmds.txt contains batch file invocation:
buildall.bat
Not pretty, but works.

I just want to thank you and confirm that this was the only way to automate compilation of a C++ project trhough VS Code.
I tried setting up tasks.json in VS Code and multiple other setups but after 4 days of that nothing worked except your solution PiotrK.
So I ended up preparing a TXT file with a list of commands like so:
set PATH=%PATH%;"C:\Users\DEKOLEV\AppData\Local\Programs\Microsoft VS Code\bin"
cd "C:\path\to\some\folder\with\C++\source\code\files"
code .
}
and I piped the text file directly to the Developer Console link. So now I have a batch file containing the following
type "C:\Some\path\to\file\commands.txt" | "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2022\Visual Studio Tools\VC\x64 Native Tools Command Prompt for VS 2022.lnk"
Starting the batch file starts the x64 developer command prompt and runs VS Code from it which enables VS Code to compile the source C++ files with the environment x64 Native Tools Command Prompt for VS 2022 provides.
I don't have enough points to post a comment so I am posting this feedback as an answer. :)

Related

FileZilla Pro CLI Batch command file not executing

I am currently attempting to use FileZilla Pro CLI on a Windows machine to connect and upload to a site in that is working in the Site Manager.
The issue is, the command below works perfectly when pasting it directly into the cmd line. However when saving it as a batch file, it simply just gets to the fzcli> prompt and then nothing happens.
The two line breaks are on purposes to override the requirement for a password and it works perfectly when pasted in.
Does anyone know if this is a cmd line issue, or if my commands need to be different to work in batch file mode?
fzcli
connect --site 0testsite01
put C:/inetpub/wwwroot/websites/sftp/files/customer/test-01.txt /test-sftp/testuser01/test/test-01-uploaded.txt
PAUSE
Your batch file executes fzcli in an interactive mode. The fzcli then waits for you to interactively enter the commands. Only after you would exit the fzcli, the batch file would continue. And fail, as it will try to execute connect as a batch file command. The fzcli does not know about the batch file. Nor does the batch file interpreter know about the fzcli commands.
It's a common misconception. You will find plenty of similar questions basically about scripting any tool that has its own commands. For example: sftp, ftp, psftp, winscp.
To provide commands to fzcli, it seems that you need to use --script switch. The fzcli documentation gives this example:
fzcli --mode standalone --script C:\Scripts\script-file

Bat file is missing in jmeter bin folder

I just tried to install jmeter - (Apache-j meter-5.1.1) but when I view the bin folder bat file is missing. My configuration details: version of jdk is 12.0.2, my operation system is 64 bit. View the screenshot of bin folder -
https://www.screencast.com/t/apWQkxP3dD4h
Type Windows Batch File is a file type with extension .bat
You have such jmeter file in your screenshot
A batch file is a script file in DOS, OS/2 and Microsoft Windows.
The filename extension .bat is used in DOS and Window
The jmeter.bat file can be obtained from JMeter sources at any time if you removed it by accident.
However in fact you do have the file:
You might want to configure Windows Explorer to show file extensions
In general I would recommend launching JMeter from Windows Command Prompt as in case of i.e. Java misconfiguration you will not be able to see the output given you launch JMeter by double-clicking the shortcut because it will blink and close immediately.
More information: How to Get Started With JMeter: Part 1 - Installation & Test Plans
Just double click on file type named as Jmeter with type as "Windows Batch File" or else open it from command prompt/terminal.
refer to the attached screenshot.
Cliek here to open a screenshot

Command Line Installation with SCCM 2012

I have a few applications that I am trying to deploy with SCCM 2012 but the installations are failing through the application catalog. So what I have for the deployment type is a script installer. I have "cmd.exe" (Without quotations) in the Installation program field and "Installer.bat" in the installation start in field.
When I look at the ccmcache folder, all the contents over that application are there but the following error displays the Software Center:
0x8007010B(-217024629)
I have done some reading online and the "10B" is a common command line error for invalid directory. I have tested the batch file when hard coding a path but my question is, how can I edit the batch file or SCCM to pull from the CCMCache path where the files are downloaded to on the local client? Currently the Batch File is simply:
#echo off
ApplicationName.exe
Do I need to edit the file to cd into the CCMCache folder where the files are placed? How can I get the batch file to run the executable that is downloaded to the CCMCache folder?
Thank You!
You need to have the full path to the installation in your script
#echo Off
\\path to .exe
The way the command is written will not be able to find the .exe file. You need to add the full unc path to the .exe into your .cmd file. You should have your installation .exe and .cmd file in the same location on the distribution share
Recommended Solution:
Before starting, since you are only launching an exe with your batch file, I would recommend just using your ApplicationName.exe as your command line parameter in SCCM instead of using a batch. This will eliminate the need to engineer any further.
Modifying the existing solution to work:
If you do still want to use a batch file, keep a few things in mind. The syntax you are using to launch the batch file will not work. I would recommend just using the batch file name "installer.bat" as your command line. If you still want to preface the batch with the cmd.exe, you absolutely need to use the /c switch with it
cmd.exe /c installer.bat
If you don't use /c the console host will only open to a promopt and not execute your batch.
This is not an ideal solution though because using "cmd.exe /c" will set your working directory to the location of cmd.exe (ie "C:\windows\system32") and since your content is staged in ccmcache, you will need to specify its location within your batch. To do this, you would use %~dp0 variable which gives you the directory the current batch is running from. This means modifying your batch to read
#echo off
%~dp0ApplicationName.exe

compile visual studio solution command line

I'm trying to build a VS solution command line, just with the cmd.
I can do it by launching the devenv console, then run devenv command etc... This work, but I have to do it with the cmd, because I use nodejs to run it, and I need to get the output.
Does anybody has a solution ?
As usual with Visual C++, you open a command prompt window using one of "Tools" shortcuts ("VS2015 x64 Native Tools Command Prompt" or others located in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2015\Visual Studio Tools\Windows Desktop Command Prompts ).
In this console window, cd to your code and compile. Execute CL or run your makefile or msbuild.
Unfortunately, in VS2015 these shortcuts are more fragile than in previous VS versions, so YMMV.

Executing directory Changes when launched from windows explorer as administrator

I'm using a .bat file for installation purposes and I'm using ".\" very often when I need to access files (for example for an unzip) in order so get which directory I'm in.
It worked quite well until yesterday when suddenly I had 2 different behaviours:
Lauched from command console (with the console inside the directory): The file works as normal and knows where .\ is at.
Launched from windows explorer it also functions if it is not started with administrator rights
If launcehd from windows explorer with administrator rights the executing directory (thus the directory which is printed with cd if its the first command in the .bat file) suddenly is c:\windows\system32
This behaviour like I said started just a few days ago (2 days ago we saw it for the first time when we tried that .bat file), before that it worked from windows explorer exactly the same as from the command console.
So my question here is twofold:
Is there anything known as to the cuase of this changed behaviour?
How can I get a handle to the current directory that the .bat file is located in (because the .zip file will always be in the same directory as the .bat file itself), thus how can I solve this problem as I need to start the file with administrator privileges
I found that there is a similar issue in windows vista:
Windows batch file starting directory when 'run as admin' although what intrigues me there is why the problem did not appear for weeks and only appeared recently with windows 8
Use this as the line after #echo off:
cd /d "%~dp0"
It will change the working directory to be where the batch file is located.

Resources