I have set a new environment variable pointing to msbuild.exe folder.
C:\temp\Test>echo %DOT_NET4%
C:\Windows\Microsoft.NET\Framework\v4.0.30319
Now, if I start a new cmd and run "msbuild.exe", the programs runs ok, but after running this simple bat, the program is not found anymore:
"C:\Program Files\TortoiseSVN\bin\svn.exe" checkout %CHECKOUT% %PATH%
cd %PATH%
nuget restore OpenText.sln
msbuild.exe OpenText.sln
msbuild not recognized as an internal or external command.
Thanks in advance
I am seeing the same thing as Joey in his comment. Your use of CD %PATH% is a red flag that indicates a problem.
PATH is a critical environment variable that contains a delimited list of folder paths where important executables are located. The command processor uses that list to locate programs when an external command is issued without the full path to the command.
If PATH is set correctly, then your command CD %PATH% cannot work. But I suspect you have some script that defines PATH to a specific folder, perhaps where nuget is located. In this case, your CD %PATH% command works, but now cmd.exe has no idea where msbuild.exe is located.
Moral of the story - don't ever use PATH for your own purposes. Pick some other variable name that is not reserved.
First things first, where are you setting the msbuild path? To resolve your issues, please check if you have followed this process:
Open your system control panel, check for advanced system settings.
Click on Environment variables and edit PATH
Add a semicolon followed by the msbuild path.
Open a new command prompt and check if it is working or not.
Please note if you set msbuild in one command prompt, it will not be available in another command prompt.
Another issue which I see when I look at your logic is, you are trying to cd to %PATH% which should be avoided, you are either resetting the Environment variable path to a new path and trying to cd to it or you will land up file name longer issues, please use another variable instead.
In the bat which you are invoking, add a condition at the root level, such that if msbuild is not found, basing on %ERRORLEVEL%, try adding msbuild to path again at batch level, so that you build will proceed.
Related
I have created a windows batch file to run a code which is located in a particular folder. However, I am running the batch file but it does not work. What I want it to do is:
Change working directory in Spyder (Spyder is already openned so I don't want it to open it first)
Run the script I want to execute
Basically, the script I am running is plotting a bunch of graphs and all the files needed to create this are located in the working directory.
#echo off
"C:\Users\Mason\Desktop\WinPython-64bit-2.7.6.4\spyder.exe"
chdir /D "F:\optimisation"
"F:\optimisation\plot.py"
pause
The batch file runs fine without any errors, but nothing happens in Spyder e.g. it doesn't change the working directory and neither executes the code.
I'd suggest
#echo off
setlocal
chdir /D "F:\optimisation"
"C:\Users\Mason\Desktop\WinPython-64bit-2.7.6.4\spyder.exe" "F:\optimisation\plot.py"
pause
That is, switch to the required directory, having set a local environment (this restores the original environment when the batch terminates).
Then run the spyder executable, providing it with the name of the file. It would be normal practice to use this structure to provide a significant filename to an executable (eg notepad fred,txt)
Since the current directory when spyder runs is f:\optimisation, it is probably not necessary to specify the entire path in spyder's argument.
Note this is all just speculation using normal practice. I have no experience of spyder- in fact, this is the first I've heard of it.
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
This may be a dumb question with a simple solution but I am trying to incorporate a line in a batch file to silently uninstall a wise uninstaller (it's to uninstall SolidThinking Embed 2017).
There is a shortcut for the Unwise.exe in the same folder to also include the log file from installation, otherwise running it by itself will prompt for a log file, or it throws the error that it cannot find the log if done in the script.
Is there a way to include the log file in the line and also uninstall the application silently?
For example (which doesn't work):
"C:\hw2017\Unwise.exe" "C:\hw2017\VisSimECDWeb150.log" /S
Thanks in advance.
Taken from https://www.symantec.com/connect/blogs/wisescript-command-line-options. Note the final paragraph which has specific instructions for how to specify the log file.
Uninstall Command Line Options
You can apply the following command line options to the WiseScript
Express uninstall executable file, unwise.exe or unwise32.exe.
/Z Removes empty directories, including the one containing Unwise.
/A Automatic mode. The Wise splash screen appears on the destination
computer, and the uninstall proceeds immediately with no end user
choices, except for questions about uninstalling shared files.
/S Silent mode. The uninstall proceeds silently with no splash screen,
no dialogs, and no end user choices.
/R Rollback mode.
/U Removes the Select Uninstall Method dialog, which means the end
user does not see options for a custom, automatic, or repair
uninstall.
When you use command line options for the uninstall
program, you must send it the path to the log file as a parameter. It
must be the log file that is in the same folder as unwise.exe. If the
path to the log file contains spaces, it must be surrounded by
quotation marks.
Example:
"C:\Program Files\Application\UNWISE.EXE" /A "C:\Program Files\Application\INSTALL.LOG" Application Uninstall
I have recently installed a 32-bit program remotely & silently (thru PDQ) that utilizes Wise installer package and uninstalled the same program (via PDQ).
The install was in a batch file using the full file path and its silent switch (/S)
The uninstall was in a different batch file, but contained the short filename scheme (8.3).
So the uninstall path was...
C:\PROGRA~2\YOUR-APP\UNWISE.EXE /S /Z C:\PROGRA~2\YOUR-APP\INSTALL.LOG
/S is silent
/Z is to remove directories including itself
No quotes used since there are no spaces, but it may not hurt if added
Hope this works for someone!
I agree with Bill_Stewart, the vendor needs to answer this for you. However, here's how to find your log:
run regedit
Navigate to HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\
Find the AppName.
Examine the "UninstallString" key value
This will give you the log, but doesn't answer how to silently automate it.
I have the following Post-Build event defined in my project:
if "$(ConfigurationName)"=="Release" ("$(ProjectDir)PostBuildRelease.bat" "$(TargetDir)")
So when I build the project in release mode, the following .bat file is executed:
PostBuildRelease.bat
CMD
SET parameter=%1
CD %1
ECHO "Copying temporary file..."
COPY FileDeleter.exe temp.exe
ECHO "Merging dependancies..."
"..\..\ILMerge.exe" /out:"FileDeleter.exe" /targetPlatform:"v4" "temp.exe" "Microsoft.WindowsAPICodePack.dll" "Microsoft.WindowsAPICodePack.ExtendedLinguisticServices.dll" "Microsoft.WindowsAPICodePack.Sensors.dll" "Microsoft.WindowsAPICodePack.Shell.dll" "Microsoft.WindowsAPICodePack.ShellExtensions.dll"
ECHO "Removing temporary file..."
DEL temp.exe
All it does is copy the assembly to a temporary location, merge the required dependancies into a final executable FileDeleter.exe, and then removes the temporary file.
This worked fine when the project was saved to a local drive, but after moving the project to a network drive, I get these errors when building in Release mode:
'\\file\IT\Internal Apps\AppDev\Applications\WpfFileDeleter\WpfFileDeleter\bin\Release\'
CMD does not support UNC paths as current directories.
C:\Windows>"Copying temporary file..."
The system cannot find the file specified.
"Merging dependancies..."
'"..\..\ILMerge.exe"' is not recognized as an internal or external command,
operable program or batch file.
"Removing temporary file..."
Could Not Find C:\Windows\temp.exe
CMD complains about not supporting UNC paths.
However, I know that the drive in question (\\File) is actually mapped to the Y:\ drive - so I can navigate to the directory in CMD by targeting Y: instead of \\file\.
The question is - how can I get Visual Studio to recognise this drive mapping by default, after all my projects have been moved to this network drive?
I've learned that batch dosnt like going over a network dir unless you add it as a drive with pushhd. This has worked for me like a charm when working over the network.
PUSHD is an internal command. If Command Extensions are disabled the PUSHD command will not accept a network (UNC) path."
Source:
http://ss64.com/nt/pushd.html
I was able to find a solution to this using this answer:
Remove project from Visual Studio solution
Right-click the solution and "Add existing project"
Navigate to the .csproj file, making sure to navigate to it using the mapped drive, (i.e. Y:\folder\test instead of \\file\folder\test)
Now once the project is added, the TargetDir variable will be set using the mapped drive instead of \\file, meaning that no changes are necessary to the post-build event or the batch file.
Another option, as I am using Team Foundation Services in VS, is to remove all existing local git repositories from Team Explorer -> Manage Connection -> Local Git Repositories and then re-adding the same locations, but again when navigating to the folder, use Y:\ instead of \\file.
Now any project I open from these repositories automatically has their TargetDir paths set using the mapped drive.
The other answer here also worked, but requires changing the post-build event to use the hard-coded mapped path as well as changing the batch file to use PUSHD instead of CD.
I know from a desktop I can have a bat file that runs an executable with specific parameters and starts in the same path on the network where the executable exists, but how can I accomplish the same thing when calling the bat file assuming is in same folder as executable from another application?
For example:
\My-Network\app\PR8.exe /noload
I want to start specifically in \My-Network\app (same folder where PR8.exe exists) but not where it defaults to which seems to be c:\windows somehow. I can't seem to do a cd on a UNC path and I don't want to use any path letters as the application also detects as to which server it is executing from as well.
It isn't possible to set a UNC working directory for Windows batch files without network mapping drives. However, in Windows 2000 and later, you can use the PUSHD and POPD commands to change the working directory to a UNC share when running your script.
Wikipedia gives us the example of creating a shortcut to your batch file where the Target is set to the following:
%COMSPEC% /E:ON /C "PUSHD """\\My-Network\app\""" & C:\PATH\TO\BATCHFILE.BAT & POPD"
In this case the Working directory attribute of the shortcut is ignored, as the PUSHD and POPD commands will change it to the path specified.