Batch file - Add a log file for every .exe executed - batch-file

for /r %%f in (*.exe) do (start /wait %%f /quiet /norestart #echo "Done" >> E:\WindowsUpdate\Alog.txt)
I want to create a log file for every file that is executed to check its properties with the code above. These files are vcredist (Microsoft Visual c++ updates). But it only creates the log file and writes nothing. Any help will do.

Those executables should use msiexec.exe which has a standard option for logging information.
`… /quiet /norestart /log E:\WindowsUpdate\Alog.txt`
If this is not what you mean then please update your question with more information because your question talks about logging information and your comment checking a check box.

Related

MSI installer does not install when executed from a batch file

I am currently creating an improvised installer for a cople software packages. To do this I have to install a couple MSI packages first before doing a couple file operations.
To install an MSI package I am using the following command:
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
This command works and installs the package instantly and witout any problems via CMD.
But when I put this command in my batch file and execute it as an administrator, I get the following error:
This installation package could not be opened. Contact the application vendor to verify that this is a valid Windows Installer package
What cold be the problem? Using the same command via the console works flawlessly, only the batch file throws the error...
EDIT: I have also tried the /a parameter in order to install it as an administrator and it does not work either. Full command in batch file:
start /wait msiexec /qn /a "Myinstaller V2.1.msi"
EDIT2: I just realized that it only does not work when I start the batch file with Right click > Run as administrator
When I open a console with administrative rights and start my batch file it works for some reason...
Is there a way to make it work with the Right click > Run as administrator method?
SOLUTION: Thanks to RGuggisberg's answer I now know that the directory changes once the file is executed as an administrator. With a small change the installer gets fired up as an admin and works perfectly starting the installer from a relative path in the same directory:
#echo off
pushd %~dp0
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
pause
I've now also implemented a feature to detect wether or not the installation fails or not:
#echo off
pushd %~dp0
start /wait msiexec /i "Myinstaller V2.1.msi" /qb
if %ERRORLEVEL% EQU 0 echo SUCCESSFULL
if NOT %ERRORLEVEL% EQU 0 echo MyProgram installation FAILED
pause
The current directory changes when you run as administrator. If you want to prove that to yourself, see this post
Difference between "%~dp0" and ".\"?
Include the full path to your filename and it will work.

In batch script silent installation using Reboot=reallysuppress is not updating the files

I am using batch Script for silent Installation to update the locked and in use files.Using silent installation reboots my system automatically after the update.But I wanna setup a custom reboot message box , So I used the REBOOT=ReallySuppress attribute. And I used a message box to popup the custom reboot message. This helps me avoid the auto-reboot of the system but it is not updating the files even after performing a manual reboot.
Here is the script that I am using.
#echo off
title Installing Updates
msiexec /i "C:\Users\tparvathaneni\Documents\Visual Studio 2015\Projects\SetupProject1\SetupProject1\bin\Debug\SetupProject1.msi" /qn /REBOOT=ReallySuppress
echo updates installed
echo msgbox "Restart your system to complete the installation." > "%temp%\popup.vbs"
wscript.exe "%temp%\popup.vbs"
pause >NUL
shutdown.exe /r /t 000
Can someone give me a solution to get the files updated with manual reboot.
did you try instead of /REBOOT=ReallySuppress the /norestart option?
Please also make a log file in the install cammand via /l option. Then read the log if really the installer reboots the computer.

windows update uninstall batch file

KB3114409 KB2825678 windows update patch files you may know that has caused many user to only be able to launch outlook in safe mode. that means i can not find anybody in outlook, anyway it is no good patch to me.
so i made batch file for our staff that is for uninstalling windows patch about KB3114409 KB2825678. it seems to be looking those file and uninstall. but if i have a look in installed update console, there is still remain those two.
i execute this batch file in administrator mode as well, but still same in.
#echo off
Wusa /KB:3114409 /Uninstall
Wusa /KB:2825678 /Uninstall
exit
i made it like that, but i still have those patches...
i use win7 64bit and using user mode, not administrator mode.
please any idea..?
Not sure if you really have everything on one line or if your post just turned out that way. This is what I use:
#echo off
start "" /b /wait wusa.exe /uninstall /kb:3114409 /quiet /norestart
start "" /b /wait wusa.exe /uninstall /kb:2825678 /quiet /norestart
To put all commands on one line you would need to separate them with &
but that makes it a bit harder to read. Also see WUSA /?
Its better to use MSIEXEC to remove this patch since its an "Office patch" and not for Windows.
Tutorial and script approach described at: http://blog.jocha.se/tech/uninstall-outlook-kb3114409

Checking for existing file in C drive and then running an installer for batch

I`m trying to code a batch file that checks whether a file exists in my c drive.
If it exists , it will end the batch file.
if not, it will run an MSI file.
I got it to run the MSI file , however after installing it.
The checks do not work and it keeps prompting me to install the file.
I have attached the code that i have written.
And also is there any way to do a slient install of MSI in batch?
May i know what is wrong with the code?
if exist "C:\Program Files (x86)\Common Files\hi.txt" goto END
msiexec /i "\\computer-name\Test\setup.msi"
:END
You could do the silent install by typing >nul after msiexec /i "\\computer-name\Test\setup.msi"
So, it would look like this:
msiexec /i "\\computer-name\Test\setup.msi">nul
This works on my computer, I hope it works for you too :)

Creating Batch file to run exe. and output to log file via GPO startup/shutdown

I am having some trouble creating a batch file, I need it to remove a .msi file first and then run a .exe file this is what I have so far.
echo on
title remove mimecast 3.5.6
if exist c:\windows\mimecastrem.tag goto alldone
msiexec.exe /x {86C4653D-E9B2-4421-8578-D2B953FFAEDA} /qn /L "C:\windows\mimecast.log"
start \\fcmsvr2\MimecastMSO\deploymimecast.exe /zap
echo. >c:\windows\mimecastrem.tag
:alldone
rem exit
If I run this in DOS logged on the pc it runs ok, I have tried to add this to a GPO startup and shutdown and the batch runs but only removes the .msi file and won't start the .exe, is there a way to add logging to this so I can see why it isn't running?
Thanks
David
Create a Wrapper Script to Capture the Output
When I try to run batch commands from a GPO, I usually have two batch files:
One batch file does all the work.
One to call the other and redirect all the output.
This way, if the important batch file has syntax problems (usually due to the contents of variables or other conditions on the machine), I still see something in the log.
batch_worker.cmd
#ECHO OFF
SETLOCAL
#ECHO Proceeding with important tasks...
REM do other stuff (delete, install, etc.)
batch_wrapper.cmd
CALL %~dp0batch_worker.cmd > C:\Windows\TEMP\batch_worker.log 2>&1
Self-Wrapping
Another option that I occasionally employ is to have the script invoke itself, redirecting the output.
batch_worker.cmd
#ECHO OFF
SETLOCAL
IF NOT "%_LOGGING%"=="1" (
SET _LOGGING=1
CALL "%0" %* > C:\Windows\TEMP\batch_worker.log 2>&1
EXIT /B %ERRORLEVEL%
)
#ECHO Proceeding with important tasks...
REM do other stuff (delete, install, etc.)
Network Files from GPO
Any startup scripts that run on a Windows machine will have the network identity of the computer account (COMPUTERNAME$). This account doesn't usually have access to most network resources. The one exception is the GPO. All computer accounts have access to the GPO (which is stored as files).
If your script needs other files:
Store them in a world-readable network location (or grant any domain member RX access).
Store them with the GPO.
When you create/add a startup script, the GPMC snap-in gives you access to the network location (under SYSVOL) where the script should reside. Use that UNC path to save any other files the script needs access to.

Resources