Create an .inf script to open a batch file as administrator - batch-file

I`ve been looking around the web for a tutorial on how to make .inf scripts so I can execute a batch file from it. The problem is that the batch script needs admin to run so i have to get that in some way. Here is my code:
:start
echo off
copy program.jar "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\"
The program needs admin to copy to the Starup folder.
Thnx.

Only for the All User's folder. Only Admins can install for all users.
The per user startup folder is at %appdata%\Microsoft\Windows\Start Menu\Programs\Startup

Related

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

Batch Job on Windows Server 2012 Access denied

The batch file is used to execute php files.
Unfortunately whenever i execute the batch file. Access denied error is appear.
below is the source code of my batch file.
set VTIGERCRM_ROOTDIR="C:\Program Files
(x86)\vtigercrm600\apache\htdocs\vtigerCRM" set PHP_EXE="C:\Program
Files (x86)\vtigercrm600\php\php.exe"
cd /D %VTIGERCRM_ROOTDIR%
%PHP_EXE% -f vtigercron.php
pause
It is the problem of the php file itself. Not related to windows server security setting.
Sorry for the trouble.
Thank you.

Using FTP.exe and mget to download files and directories from an FTP directory

I am trying to set up an automatic download of the files from a FTP directory on a scheduled basis. The solution I have come up with is to create a batch file that will be ran by windows task scheduler. The batch file is as follows (so far)
prompt
open ftp://xx.xx.xx.xx
myuser
mypassword
lcd C:\localdir
cd /remotedir/
mget *
quit
The problem is that this does not get everything in the specified directory. Only the loose files in the directory such as a .zip or .txt file. I have searched the questions here to no avail. So how can I get mget to not only download loose files in the root directory but also download the sub-directories and containing files (keeping the structure intact)?
Just answering this in case anyone else has a similar issue. The ftp.exe was a bust but I found out it is fairly easy using WinSCP just create a scheduled task in task scheduler and use the options section for command line parameters
Instructions for creating download script with WinSCP:
http://winscp.net/eng/docs/guide_automation
Instructions for scheduling WinSCP transfer task:
http://winscp.net/eng/docs/guide_schedule
WinSCP downloads directories recursively by default.

Run a powershell script in batch file as administrator

I have a powershell script. To run this sript, I have written a batch file.
Here is code of batch file:
:: psscript.bat
set psscript='%CD%\Hotfix-Automation-Installer.ps1'
echo Running PowerShell Script: %psscript%
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe ^&%psscript% %*
When I double-click on batch file, I want my script Hotfix-Automation-Installer.ps1 to be run as an administrator.
How I can run this script as administrator?
Read Matt's article on this link:
How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required?
He has given complete script to elevate from current session to administrator session. Quiet helpful.

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