I have to check whether java is installed or not ?
If java is installed then i have to skip it and if not then to install it in silent mode.
I know how to install java in silent mode
**cls
C:\TEMP>jdk-7u4-windows-x64.exe /quiet
echo installation complete
pause**
but how to define condition above in batch file though i'm very new to scripting.
Any link or reference will also work.
This works in Windows 8 to launch the installer:
#echo off
java >nul 2>nul & if errorlevel 9009 jdk-7u4-windows-x64.exe /quiet
REM get the current installed Java version
for /f "tokens=3" %%a in ('java -version 2^>^&1 ^| find /i "version"') do SET "JAVA_current=%%~a"
IF NOT DEFINED JAVA_current (ECHO Java NOT installed.) ELSE ECHO Java version %JAVA_current% installed.
Related
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.
I have tons of FortiClient clients that I need to install on individual computers, each client has it's own PC at home and some of them have Windows 7 32-bit. (Yes, I even saw an XP one.)
I've managed to create a batch script that will install the free FortiClient with all the configuration inside by importing the registry key at the beginning of the script and it's working great, but on Windows 7 32-bit, you can install it only if you have some Windows updates installed before.
So, I've came to a conclusion that I can create a batch file that will check if the KB is installed or not.
So here is the code:
#echo off
Pushd "%~dp0"
wmic qfe get hotfixid | find "KB3033929"
if %errorlevel% neq 1 ECHO KB3033929 Found
if %errorlevel% equ 1 ECHO KB3033929 NOT Found, installing KB3033929
(
wusa .\Windows6.1-KB3033929-x86.msu /quiet /norestart
)
regedit /s .\korona.reg
msiexec.exe /qb /i "%~dp0FortiClient.msi" /norestart INSTALLLEVEL=3
pause
But each time I am running the code, I am getting an error that the syntax is wrong, even though I run only the line with the wusa command.
PS: If you have any other ideas, this would be great - I don't want to use PowerShell.
Your if syntax is wrong:
if %errorlevel% equ 1 ECHO KB3033929 NOT Found, installing KB3033929
(
wusa .\Windows6.1-KB3033929-x86.msu /quiet /norestart
)
should probably be
if %errorlevel% equ 1 (
ECHO KB3033929 NOT Found, installing KB3033929
wusa .\Windows6.1-KB3033929-x86.msu /quiet /norestart
)
3 Months later: in the meantime, this KB is superseeded several times. So actually KB3033929 might not be installed, but a successor is that prevents KB3033929 from installing (which is ok from a technical point of view as the successor includes the function, but ruins your logic).
Source and workaround
We use kerberos authentication for connecting to our on-prem computing environment. I'd like to use visual studio code remote to do development directly on that server. Based on this section in the vscode remote documentation, it seems like it's possible to use password-based authentication, which works for me, but it would be nice if I could use existing kerberos authentication, instead of having to type my password every time I start up a vscode session.
I've tried searching through the documentation above, but I can't figure out if kerberos is supported. I would like to know if I should respectfully raise an issue on the issue tracker.
Update from March 2020.
I've used plain PuTTY (plink.exe) to connect from VsCode with kerberos using those simple steps.
Define a session inside PuTTY that opens a ssh shell to your remote machine, save it as remote.
Create "C:\Users\< youruser >\ssh.bat" with the contents below. You need echo to fool VsCode that it's OpenSSH client.
echo OpenSSH
SET mypath=%~dp0
powershell %mypath%ssh.ps1 %*
Create powershell script ssh.ps1 in the same folder with these contents:
$ArgArray = [System.Collections.ArrayList]$Args
$ind = $ArgArray.IndexOf("-F")
if ($ind -ge 0) {
$ArgArray.RemoveAt($ind)
$ArgArray.RemoveAt($ind)
}
Write-Host $ArgArray
& 'C:\Program Files\PuTTY\plink.exe' $ArgArray
Theoretically you can write it in batch language but I did not want to suffer.
Set "remote.SSH.path" setting in VsCode to your ssh.bat path.
Finally, add ssh host configuration in vscode and use session name as host:
Host remote
HostName remote
User <you ssh user>
My tweak on #Roman's batch script
#echo off
for %%x in (%*) do (
REM Handle -V
IF "%%x" == "-V" GOTO :version
REM Handle vscode remote as special for plink only
IF "%%x" == "remote" GOTO :plink
)
REM use the built in ssh by default
GOTO :default_ssh
:version
echo OpenSSH
GOTO :eof
:plink
powershell -NoProfile -ExecutionPolicy Bypass %~dp0ssh.ps1 %*
GOTO :eof
:default_ssh
ssh.exe %*
GOTO :eof
It allows you to only use plink for the vscode "remote" server name (I have my reasons), so everything behaves as normal unless you choose hostname remote
Currently this is not possible. There is a feature request about this which has been closed because it will not be implemented in the foreseeable future.
If you have a Kerberos-integrated SSH client for Windows it should work.
I'm not sure if the Microsoft openSSH for Windows 10 / Server 2019 is Kerberos-integrated or not. The one that comes with Git for Windows is not.
If you have a Kerberos-enabled version of PuTTY, you can make a small hack to use plink.
This broke with the June release
Create the file C:\Program Files\Microsoft VS Code\bin\ssh.bat
The file location will be different if VScode is installed in your home directory.
Put the following in the file. Adjust the plink path to your PuTTY directory.
"C:\Program Files (x86)\Centrify\Centrify PuTTY\plink.exe" -ssh -K %*
I wrote a very tiny wrapper for plink.exe.
(It just fakes version string with openssl's and remove unsupported '-T' option.)
I don't use with kerberos but it might help with settings like aviso's answer.
Please give it a try.
I would have commented on Roman answer, but it appears I do not have enough reputation.
I followed his steps, except that I put the plink.exe path for "remote.SSH.path" instead of the "ssh.bat". My path to plink.exe is simply "C:\Program Files\PuTTY\plink.exe".
I tried multiple things and to date, this is the only one that worked for me.
Another tweek for #Roman's and #Andy's ssh.bat script that worked for me; I specify several hosts to use plink.
#echo off
if %1 == -V GOTO :version
if %4 == "myFirst.remoteHost.address" GOTO :plink
if %4 == "mySecond.remoteHost.address" GOTO :plink
if %4 == "myThird.remoteHost.address" GOTO :plink
REM use the built in ssh by default
GOTO :default_ssh
:version
echo OpenSSH
GOTO :eof
:plink
powershell -NoProfile -ExecutionPolicy Bypass %~dp0ssh.ps1 %*
GOTO :eof
:default_ssh
ssh.exe %*
GOTO :eof
I'm trying to silently uninstall AIM which is installed on a user's profile, not the machine. I'm using a batch script to find a registry entry that is the path where it's installed, then using that path to uninstall it. I'm not the best at writing scripts, but here is what I've put together.
for /f "tokens=3*" %%! in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Low Rights\DragDrop\{7A02967B-018E-41c9-953E-3DCAB144538B}" /v "AppPath" ^|Findstr.exe /ri "\<AppPath\>"') DO (if exist %%! %%!\uninstall.exe /S /PopUpMsgBox="n" /CheckMutx="N)
I'm not sure what the issue is.
I'm having a problem calling a specific section of my batch script. The goal is to run this script and have it install the given executables and run some commands:
#ECHO OFF
ECHO 1. 32-bit
ECHO 2. 64-bit
SET /P INSTALL="Please choose the correct installation: "
SET /P PROXY="Enter proxy gateway path if applicable to your environment: "
2>NUL CALL :CASE_%INSTALL%
IF ERRORLEVEL 1 CALL :ERROR
REM CASE_%INSTALL% or ERROR returns to here
ECHO Done.
PAUSE
EXIT \B
:CASE_1
REM Install NodeJS 32-bit
CALL node-v4.4.7-x86.msi
REM Install Ruby
CALL rubyinstaller-2.3.1.exe
GOTO NEXT_TASK
:CASE_2
REM Install NodeJS 64-bit
CALL node-v4.4.7-x64.msi
REM Install Ruby
CALL rubyinstaller-2.3.1-x64.exe
GOTO NEXT_TASK
:NEXT_TASK
REM Install SASS CSS precompiler (v3.4.19)
CALL gem install sass --http-proxy %PROXY%
REM Install Compass CSS plug-in (v1.0.3)
CALL gem install compass --http-proxy %PROXY%
REM Run Node package install
CD ..
IF NOT "%PROXY%"=="" (
CALL npm config set proxy %PROXY%
CALL npm config set https-proxy %PROXY%
)
CALL npm install
REM Instal grunt globally
CALL npm install -g grunt
REM Install jshint globally because of warning
CALL npm install -g jshint
GOTO END_CASE
:ERROR
ECHO Unable to complete installation of tools
GOTO END_CASE
:END_CASE
VER > NUL
GOTO:EOF
This will execute either CASE_1 or CASE_2 perfectly, depending on what the user chooses. NodeJS is installed, and so is Ruby. Then, when it reaches the end of one of those sections, I will get this output:
Done.
Press any key to continue . . .
The script never follows the GOTO to run NEXT_TASK, and thus never installs SASS or Compass and also doesn't run the npm commands.
I have noticed that running this script twice and skipping the NodeJS installation on the second run actually executes the NEXT_TASK section correctly... - this leads me to believe there's some sort of timing issue going on here.
Other things I have tried:
Replacing the GOTOs with CALLs (does not behave correctly)
Replacing the section names referenced by GOTO to use the format :{Section} (no change)
Replacing the CALLs before the Node and Ruby executable with START /WAIT (doesn't seem like that makes any difference)
So, I'm stumped. Any help would be appreciated.
I ended up solving my problem (using a workaround) by breaking the script into two separate scripts. Unfortunately, I'm unable to call one script from the other and be certain that the gem and npm commands will be set (even through the use of START to create a new environment, which was surprising to me), so this is my solution. Thanks to #aschipfl for pointing out the unnecessary use of CALL when referencing executables.
install_tools.bat (Run first)
#ECHO OFF
ECHO 1. 32-bit
ECHO 2. 64-bit
SET /P INSTALL="Please choose the correct installation: "
2>NUL CALL :CASE_%INSTALL%
IF ERRORLEVEL 1 CALL :ERROR
REM CASE_%INSTALL% returns to here
PAUSE
EXIT
:CASE_1
REM Install NodeJS 32-bit
START "" /W node-v4.4.7-x86.msi
REM Install Ruby
rubyinstaller-2.3.1.exe
GOTO SUCCESS
:CASE_2
REM Install NodeJS 64-bit
START "" /W node-v4.4.7-x64.msi
REM Install Ruby
rubyinstaller-2.3.1-x64.exe
GOTO SUCCESS
:ERROR
ECHO.
ECHO Unable to complete installation of tools
GOTO END_CASE
:SUCCESS
ECHO.
ECHO Done. Please run init_tools.bat.
GOTO END_CASE
:END_CASE
VER > NUL
GOTO:EOF
init_tools.bat (Run second)
#ECHO OFF
SET /P PROXY="Enter proxy gateway path if applicable to your environment: "
REM Install SASS CSS precompiler (v3.4.19)
CALL gem install sass --http-proxy %PROXY%
REM Install Compass CSS plug-in (v1.0.3)
CALL gem install compass --http-proxy %PROXY%
REM Run Node package install
CD ..
IF NOT "%PROXY%"=="" (
CALL npm config set proxy %PROXY%
CALL npm config set https-proxy %PROXY%
)
CALL npm install
REM Instal grunt globally
CALL npm install -g grunt
REM Install jshint globally because of warning
CALL npm install -g jshint
ECHO.
ECHO Tools initialized.
PAUSE
EXIT
Try this code and let me know if it works, and what the error is. You might need to increase timeout after 1st call.
#ECHO OFF
setlocal EnableExtensions EnableDelayedExpansion
ECHO 1. 32-bit
ECHO 2. 64-bit
SET /P INSTALL="Please choose the correct installation: "
SET /P PROXY="Enter proxy gateway path if applicable to your environment: "
CALL :CASE_%INSTALL%
IF ERRORLEVEL 1 (ECHO Unable to complete ruby installation & GOTO :END
) ELSE (TIMEOUT /t 3 /nobreak >nul
set PATH="%PATH%;C:\Ruby23-x64\bin;C:\Program Files\nodejs\"
CALL :NEXT_TASK
IF ERRORLEVEL 1 ECHO Unable to complete other tools installation & GOTO :END)
ECHO Installation completed.
:END
TIMEOUT /t 5 /nobreak >nul
EXIT /B
:CASE_1
REM Install NodeJS 32-bit
START "" /W node-v4.4.7-x86.msi
REM Install Ruby
rubyinstaller-2.3.1.exe
EXIT /B
:CASE_2
REM Install NodeJS 64-bit
START "" /W node-v4.4.7-x64.msi
REM Install Ruby
rubyinstaller-2.3.1-x64.exe
EXIT /B
:NEXT_TASK
REM Install SASS CSS precompiler (v3.4.19)
START "" /W gem install sass --http-proxy %PROXY%
REM Install Compass CSS plug-in (v1.0.3)
START "" /W gem install compass --http-proxy %PROXY%
REM Run Node package install
CD ..
IF NOT "%PROXY%"=="" (
START "" /W /B npm config set proxy %PROXY%
START "" /W /B npm config set https-proxy %PROXY%
)
START "" /W npm install
REM Instal grunt globally
START "" /W npm install -g grunt
REM Install jshint globally because of warning
START "" /W npm install -g jshint
EXIT /B