Command Line Installation with SCCM 2012 - batch-file

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

Related

How to specify in windows batch file to open spyder, change the working directory and run a script?

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.

Using 'for' command to find and download the latest file on SFTP server in PSFTP

I have gone through the following guide to set up an SSIS package to retrieve a text file located on an SFTP server:
https://www.mssqltips.com/sqlservertip/3435/using-sftp-with-sql-server-integration-services/
To summarize, the SSIS package executes PSFTP.exe (A PuTTY tool) which takes the necessary credentials to connect to the server. It also takes a batch file that it executes after connecting. This batch file contains the commands to retrieve the desired text file. To start from the guide, it simply contains a cmd command to change directory, and a get command to retrieve the file:
cmd DataDump
get TeleMarketingResults.txt
All of this works fine.
The issue arises when I try to make this batch file logic more complex as it does not seem to recognize basic keywords. For instance, I would like to modify it to retrieve the most recent file, so I tried adding this:
for /f %%i in ('dir /b/a-d/od/t:c') do set LAST=%%i
echo The most recently created file is %LAST%
but then I get these errors:
psftp: unknown command "for"
psftp: unknown command "echo"
If I execute the batch file manually in a local directory, it works. The issue only occurs when passing it as a parameter to PSFTP.exe. Why is this?
psftp script file can contain psftp commands only. for, set or dir are not psftp commands.
There's hardly any reasonable way to retrieve latest file using psftp. You would have to do it in two steps. First to retrieve listing and store it to a file. Then parse that file using some smart batch file commands to find the latest files. And then run psftp again to download that file. It is cumbersome and ineffective as it requires two connections.
You better use a more powerful SFTP client. For example it's trivial with my WinSCP SFTP client. See
Question WinSCP select most recent file or
WinSCP article Downloading the most recent file.

Write a batch file that installs EXE shortcut on computer remotely

I am writing a script to install a program remotely on requested computers. Only problem is that the file we invoke to install the application is actually a shortcut that points to an .exe and an .ini so it can install with specific parameters. Is there a way I can run the shortcut from the batch file so that it points to both file and installs on the users computer with parameters already set?
Is this what you are looking for?
xcopy "source" "destination" Example: xcopy E:\fileC:\Users\user\destination

batch file command line start in same folder as executable on network path

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.

How do i combine a bat file with an MSI?

I have an MSI Installer that I created in WIX that i would like to be run from a .bat file, but I need it to be in one MSI file. How would i do that? for example i have a .bat file that does this
MD C:\TEMP\BATS
START /W msiexec /i Installer.msi /l*v C:\TEMP\BATS\INSTALLERLOG.txt
SLEEP 5
DEL C:\TEMP\INSTALLERLOG.txt
RD C:\TEMP
I want to create an .msi or .exe file that contains both the .bat file and the .msi file and will unpackage the two files and run the .bat file. Is this possible? I am doing it just to force Logging that will be displayed to the user through a custom action if the installer fails some how.
It sounds like you are caught by the technical details of the counterparts of your solution. Try to forget what you have for a moment and think of what you actually need.
As far as I can tell from your code snippet, the bat file creates a temporary directory, runs MSI package installation with verbose logging option, and then deletes the generated log file... Sounds a bit of no sense to me...
This is whatI would do in your case:
Get rid of that bat file
Ask yourself what its purpose is. If it is there to modify the target system, then revise this logic and move it to your MSI package following all the best practices you can find. If it has to to some service work, e.g. prepare parameters for the main MSI package, then consider authoring a bootstrapper.
You can try IExpress to generate a single EXE file. Another solution would be to use a self-extracting EXE archive which can launch a specific file when it finishes extracting.

Resources