Create a TXT if software exist - batch-file

I'm looking for a batch script to create a text file if a software exists
For example I have this broken code
IF EXIST "C:\Program Files (x86)\Microsoft Office\root\Office16\Outlook.exe"
Create a text file here C:\Users\office2016.txt with the text "Office 2016 Install Complete"
Otherwise end the script
I'm able to create a text file with this command
#echo office 2016 installed> c:\Users\office2016.txt
I need help combining the two together.

This seems like an XY problem; what you really want is some indication that Office is installed on your system.
The command C:\Temp>if exist "C:\Program Files (x86)\Microsoft Office\root\Office16\Outlook.exe" echo Office installed >> C:\Temp\indicator.txt works fine for me so my guess is that since you're trying to write to C:\Users as a non-Administrator you don't have permission to do so.
On my system when I run as non-admin:
C:\Users>type con > test.txt
Access is denied.
C:\Users>
To find out if the user has Office installed you should be checking the registry; the REG command can do that for you:
#echo off
REG QUERY HKLM\SOFTWARE\Microsoft\Office\16.0
IF ERRORLEVEL 0 ECHO Office 2016 installed >> C:\Users\MyUsername\File.txt

Related

Create Batch file to run mstest for coded ui test automation

Can someone help me out in creating Batch file to run the coded ui test using mstest?
I am currently running the coded ui test in the command prompt by running as administrator by using below lines in command prompt:
cd\
cd C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE>MSTest.exe /testcontainer:D:\Working\LOPS_Testing\LOPS6Automation\bin\LOPS6Automation.dll /test:Light_Oil_Price_System.Scripts.PricingScreen_Script.PricingScreenFunctionality
This works correctly.
But now I want to use the same in a batch file. Can some one help me out to create a batch file by using the above code?
Wrap paths with spaces between quotes.
I also used cd /D, that changes drive if necessary (for example if you were on drive D: you would need to change to C: before cd commands. With /D option this is done automatically)
Also, since you are already on the Common7\IDE folder, you don't need to write again the directory, you could just call MSTest.exe:
cd /D "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE"
MSTest.exe /testcontainer:D:\Working\LOPS_Testing\LOPS6Automation\bin\LOPS6Automation.dll /test:Light_Oil_Price_System.Scripts.PricingScreen_Script.PricingScreenFunctionality

Batch file to uninstall a program across multiple OS using IF/ELSE for paths with spaces

What I'm after is a batch file that works across all Microsoft OS from Server 2003 all the way up to Windows 10, to check if a path (with spaces) exists, and if it does, run a command to uninstall McAfee's Virusscan Agent. The problem is the path changes per OS, but the command to uninstall the McAfee Agent remains the same. Here's what I've got so far; I know it's probably completely wrong, but it'll give you a basic idea of what I'm after:
IF EXIST "C:\Program Files (x86)\McAfee\Common Framework" (
c:
cd "C:\Program Files (x86)\McAfee\Common Framework"
start /wait frminst.exe /forceuninstall /silent
) ELSE (
IF EXIST "C:\Program Files\McAfee\Common Framework"
c:
cd "C:\Program Files\McAfee\Common Framework"
start /wait frminst.exe /forceuninstall /silent
) ELSE (
IF EXIST "C:\Program Files\McAfee\Agent\x86"
c:
cd "C:\Program Files\McAfee\Agent\x86"
start /wait frminst.exe /forceuninstall /silent
)
shutdown /r /t 30
So basically, it should check for the existance of one of three default agent install paths (because the path changes on Server 2003/Windows7/Windows10) and if the path exists, go to that directory, and run the frminst.exe executable silently, then reboot the machine after 30s.

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.

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 :)

ClickOnce Deployment with a Database as a Prerequisite

I have a Winforms application that I want to publish using ClickOnce. This application comes with an initial database, which must be installed once on a per-machine basis. After much ado, I have landed on the idea of using a custom pre-requisite to install the .sdf file. I have used Bootstrapper Manifest Generator (BMG) to create a package for the .cmd file I want to run, and I have included the .sdf file as an "additional file."
My expectation was that the two files would end up in the same directory, and I would be able to copy the .sdf file to the place where I want it (They do end up in the same directory.) The pre-requisite shows up in Visual Studio just fine. It get's deployed to the client system just fine, and the setup program kicks off the prerequisite just fine.
The only problem is that the current working directory that the .cmd file is executing is C:\Documents and Settings\\Desktop!
Neither of the two files (.cmd or .sdf) are located there - they were downloaded elsewhere, e.g., "C:\Documents and Settings\drogers\Local Settings\Temp\VSD5A.tmp". So, although I know where to xcopy to, I have no idea where to xcopy from.
How can I resolve this?
Here is the .cmd file:
REM Modify this file to reflect your manufacturer name [FHCRC] and product name [ClickOnceSharedDataDemo].
SET TargetBase=%ALLUSERSPROFILE%
IF NOT "%TargetBase%"=="C:\ProgramData" SET TargetBase=%ALLUSERSPROFILE%\Application Data
REM We only want to do this copy for the first user!
if exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\shareddata.sdf" GOTO EXIT
if not exist "%TargetBase%\FHCRC" mkdir "%TargetBase%\FHCRC"
if not exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo" mkdir "%TargetBase%\FHCRC\ClickOnceSharedDataDemo"
CACLS "%TargetBase%\FHCRC\ClickOnceSharedDataDemo" /E /T /C /G "Users":C
xcopy shareddata.sdf "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\"
if not exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\shareddata.sdf" PAUSE
if not exist "%TargetBase%\FHCRC\ClickOnceSharedDataDemo\shareddata.sdf" exit /B -1
:EXIT
PAUSE
exit /B 0
Thanks,
David
Well, I am not altogether happy with this solution, but it works. I now have two prerequisites. the first is just the command file which runs the CACLS commands to set permissions. It is basically a shortened version of the above:
REM Modify this file to reflect your manufacturer name [Manufacturer] and product name [ProductName].
SET TargetBase=%ALLUSERSPROFILE%
IF NOT "%TargetBase%"=="C:\ProgramData" SET TargetBase=%ALLUSERSPROFILE%\Application Data
REM We only want to do this copy for the first user!
if exist "%TargetBase%\Manufacturer\ProductName\shareddata.sdf" GOTO EXIT
if not exist "%TargetBase%\Manufacturer" mkdir "%TargetBase%\Manufacturer"
if not exist "%TargetBase%\Manufacturer\ProductName" mkdir "%TargetBase%\Manufacturer\ProductName"
CACLS "%TargetBase%\Manufacturer\ProductName" /E /T /C /G "Users":C
:EXIT
ECHO exit /B 0
The second prerequisite is an "all users = true" setup project which has a custom folder located at default location:
"[CommonAppDataFolder][Manufacturer][ProductName]".
Into this folder I put the sdf file.
Finally, I used Bootstrapper Manifest Generator to make packages for both, making the second dependent on the first. I copied the packages to the appropriate VS2010 directory, included them as prerequisites, and published.
I now have per-machine .sdf files published to both WinXP and Win7. Why does this have to be so difficult!?!?
I'm still looking for less complicated solutions, that will install to both Windows 7 and Windows XP.
Did you try MSDeploy? It is able to fulfil all your needs.
Cheers!
You could just include the .sdf file with the ClickOnce application, then have your program copy it to somewhere else the first time it runs. I never recommend keeping the data in the CLickOnce cache anyway, it's safer to handle it yourself. See if this article helps at all:
http://robindotnet.wordpress.com/2009/08/19/where-do-i-put-my-data-to-keep-it-safe-from-clickonce-updates/

Resources