.bat file to check whether IIS is installed or not - windows

I am looking for a .bat file which checks whether IIS is installed or not.Below is the .bat file I created
#echo off
reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp /v VersionString
if %ERRORLEVEL% EQU 1 goto NOT_EXISTS
:EXISTS
echo "IIS installed.."
goto:END
:NOT_EXISTS
echo "IIS not installed..."
goto:END
:END
This works fine in Windows 7 machine but this is not working in Windows Server 2012.
In the .bat file I am checking for the registry entry "VersionString" to see whether IIS is installed or not.
I tested this bat file in Windows Server 2012.I uninstalled IIS and after uninstalling IIS registry keys which are there for IIS(ex:VersionString) are not getting removed.So when I run the bat file it shows as IIS is installed.
So is there any better any to check if IIS is installed or not.

Use sc to determine whether services are installed. Run sc query to get an idea of the kinds of information available, sc /? for a full run-down on sc capabilities.
sc query | findstr /C:"DISPLAY_NAME: World Wide Web Publishing Service"
if %ERRORLEVEL% equ 0 echo IIS installed

Related

Check if IIS is installed via .BAT

I'm using the cmd commands bellow to install IIS on my machine, as suggested Here.
start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-HttpRedirect;
IIS-ApplicationDevelopment;IIS-ASPNET;IIS-NetFxExtensibility;IIS-ASP;IIS-CGI;IIS-ISAPIExtensions;IIS-ISAPIFilter;IIS-ServerSideIncludes;IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;IIS-RequestMonitor;IIS-HttpTracing;IIS-CustomLogging;IIS-ODBCLogging;IIS-Security;IIS-BasicAuthentication;
IIS-WindowsAuthentication;IIS-DigestAuthentication;IIS-ClientCertificateMappingAuthentication;IIS-IISCertificateMappingAuthentication;IIS-URLAuthorization;IIS-RequestFiltering;IIS-IPSecurity;
IIS-Performance;IIS-HttpCompressionStatic;IIS-HttpCompressionDynamic;IIS-WebServerManagementTools;IIS-ManagementConsole;IIS-ManagementScriptingTools;IIS-ManagementService;IIS-IIS6ManagementCompatibility;IIS-Metabase;IIS-WMICompatibility;IIS-LegacyScripts;IIS-LegacySnapIn;IIS-FTPPublishingService;IIS-FTPServer;IIS-FTPManagement;WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI
I want to check first if it's already installed using CMD to include an if in my batch script. How can I do this using cmd?
As I have no installed IIS I can't fully test this. You can use the registry entries to check the version, installation dir and so on. You can use this in order to see if the IIS is installed:
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\VersionString" >nul 2>&1 && (
echo installed
)||(
echo NOT installed
)
Based on #npocmaka said in the first comment of my question, and also by following the explanation on this WEBPAGE
I've created this .bat file.
#echo off
reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp /v VersionString
if %ERRORLEVEL% EQU 1 goto NOT_EXISTS
:EXISTS
echo "IIS installed :-)"
goto:END
:NOT_EXISTS
echo "IIS not installed :-( ... Begin installation"
start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-HttpRedirect;
IIS-ApplicationDevelopment;IIS-ASPNET;IIS-NetFxExtensibility;IIS-ASP;IIS-CGI;IIS-ISAPIExtensions;IIS-ISAPIFilter;IIS-ServerSideIncludes;IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;IIS-RequestMonitor;IIS-HttpTracing;IIS-CustomLogging;IIS-ODBCLogging;IIS-Security;IIS-BasicAuthentication;
IIS-WindowsAuthentication;IIS-DigestAuthentication;IIS-ClientCertificateMappingAuthentication;IIS-IISCertificateMappingAuthentication;IIS-URLAuthorization;IIS-RequestFiltering;IIS-IPSecurity;
IIS-Performance;IIS-HttpCompressionStatic;IIS-HttpCompressionDynamic;IIS-WebServerManagementTools;IIS-ManagementConsole;IIS-ManagementScriptingTools;IIS-ManagementService;IIS-IIS6ManagementCompatibility;IIS-Metabase;IIS-WMICompatibility;IIS-LegacyScripts;IIS-LegacySnapIn;IIS-FTPPublishingService;IIS-FTPServer;IIS-FTPManagement;WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI
goto:END
:END
pause

Discrepancy REG QUERY local vs remote computer batch script

I'm writing a batch script to update a software package (uninstall old
version/ install new one). This needs to be done over the network as
there are 500 PCs to update. One of the first steps before uninstalling is checking wether that software is installed or not. In order to check that
I query the registry:
reg query "HKLM\SOFTWARE\A.E.T Europe B.V."
This query gives adecuate results when running in local (for testing purposes), but when I run it remotely (they way it will be
ran) returns wrong results.
reg query "\\I301\HKLM\SOFTWARE\A.E.T Europe B.V."
returns 0 if i run that line locally. But if I log into I301 and run the
query locally returns 1, being the truth that A.E.T Europe B.V. shows up under the Wow6432Node branch in the windows registry.
Why is that???
Thanks in advance!
If there is on 64-bit Windows just the key
HKLM\SOFTWARE\Wow6432Node\A.E.T Europe B.V.
but no key
HKLM\SOFTWARE\A.E.T Europe B.V.
the reason for the different result is caused most likely by which version of reg.exe is executed from batch file or command line.
The key is not found if 64-bit %SystemRoot%\System32\reg.exe is executed on processing the batch file or running the command by 64-bit %SystemRoot%\System32\cmd.exe on using the line
reg query "\\I301\HKLM\SOFTWARE\A.E.T Europe B.V."
But the key is found if 32-bit %SystemRoot%\SysWOW64\reg.exe is executed on processing the batch file or running the command by 32-bit %SystemRoot%\SysWOW64\cmd.exe on using the line
reg query "HKLM\SOFTWARE\A.E.T Europe B.V."
because for the 32-bit applications the registry access to HKLM\SOFTWARE is redirected to HKLM\SOFTWARE\Wow6432Node by registry redirector.
Check both possible key locations:
#echo off
%SystemRoot%\System32\ping.exe -n 1 I301 >nul
if errorlevel 1 (
echo Computer with name I301 is not available in network.
goto :EOF
)
%SystemRoot%\System32\reg.exe query "\\I301\HKLM\SOFTWARE\A.E.T Europe B.V." >nul 2>&1
if not errorlevel 1 goto Installed
%SystemRoot%\System32\reg.exe query "\\I301\HKLM\SOFTWARE\Wow6432Node\A.E.T Europe B.V." >nul 2>&1
if not errorlevel 1 goto Installed
echo A.E.T Europe B.V. is not installed.
goto :EOF
:Installed
echo A.E.T Europe B.V. is installed already.
See also the Microsoft documentation pages:
File System Redirector
WOW64 Implementation Details
Registry Keys Affected by WOW64
Good answer by Mofi. On 64 bit systems you might also consider using
/reg:32 & /reg:64
See REG QUERY /?
You can sometimes get into trouble if you are launching CMD.exe from another app. If that app is a 32 bit app it will launch the 32 bit version of CMD.exe
Thanks Mofi and RGuggisberg,
Found out about everything Mofi said (and RGuggisberg complemented) later on the day. Since I couldn't make it work I tried checking for the Uninstall entry in the registry, thinking it would be there and only there. After getting again similar results I did a bit more googling and found out about Windows having two trees in the registry: one for 32 bits applications and another for 64 bits. The hint was given by:
http://ss64.com/nt/reg.html
At the end it shows up the two options that RGuggisber mentions /reg:32 & /reg:64. Looked them up and found about the existence of both registries.
https://msdn.microsoft.com/es-es/library/windows/desktop/ms724072%28v=vs.85%29.aspx
Tried same query (for uninstalled) BUT using /reg:64 and found the key I was looking for. Tried with /reg:32 and indeed could not find it. The machine I was running the script from runs Windows 7 32-bits. The remote machine Windows 8.1 64 bits.

How can I perform different actions in windows batch file based on most recent version of installed program

Some of our computers run multiple versions of Microsoft Access (97 & 2010) while others run 365. For the pcs running multiple versions, the default is set to 97. I have a batch file that is performing various tests to see if files exist, and finished by running an Access 2010 database called MWO.accdb. See below.
if exist c:\windows\system32\mscomct2.ocx goto step2
rem copy mscomct2 and register
cscript \\file\apps\Database\Maintenance\365\MsgBox.vbs "Preparing necessary libraries."
copy "\\file\apps\Database\Maintenance\365\mscomct2.ocx" "c:\windows\system32\"
regsvr32 /u mscomct2.ocx
regsvr32 /i mscomct2.ocx
:step2
if exist "%USERPROFILE%\Desktop\MWO.lnk" goto step3
rem create shortcut on user's desktop for future use
cscript \\file\apps\Database\Maintenance\365\MsgBox.vbs "Creating shortcut on desktop & adding to start menu."
copy "\\file\apps\Database\Maintenance\MWO-INSTALL.lnk" "%USERPROFILE%\Desktop\MWO.lnk"
mkdir "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Maintenance"
copy "\\file\apps\Database\Maintenance\MWO-INSTALL.lnk" "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Maintenance\MWO.lnk"
:step3
\\file\apps\Database\Maintenance\365\MWO.accdb
Is there an easy way to test for the latest version of access, and force the file to open with it to avoid the defaulting to 97 problem?
wmic product where caption="Access" get caption,version
(I don't have access installed, the captionstring may differ)

How to launch debugger automatically to debug 32 bit applications on Windows 7 64 bit?

I'm trying to have Windows automatically start the debugger when an application is launched (as described in msdn) however I'm getting the following error:
The Visual Studio Just-In-Time Debugger was not notified that the application correctly started
A quick search found this person with the same problem where the suggestion was:
If you are running Vista or Win7 you need to run vsjitdebugger as an administrator or you will get that error.
I went to C:\Windows\System32\ and in the compatibility tab of vsjitdebugger.exe's properties I checked the Run this program as an administrator check box. Now I'm getting the following message
The requested operation requires elevation
Followed by
Can't open this item
It might have been moved, renamed, or deleted. Do you want to remove this item?
I'm not sure if the fact that this is a 32 bit application on a 64 bit OS is relevant.
You should run your application as an administrator (don't setup vsjitdebugger.exe to run as administrator). Then you will be prompted with the security warning and after that normal list with debuggers to choose from.
In my case I had to run as an administrator program which runs debugged program.
So after looking around for the solution to this problem I found the answer here. The issue for me was that the debugger registry hives weren't set properly. This is prolly due to missing the Auto entry, though I'm not positive. I didn't have this issue before I upgraded to Windows 10. The registry entries need to be:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug]
"Auto"="1"
"Debugger"="\"C:\\WINDOWS\\system32\\vsjitdebugger.exe\" -p %ld -e %ld"
"UserDebuggerHotKey"=dword:00000000
[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug]
"Auto"="1"
"Debugger"="\"C:\\WINDOWS\\system32\\vsjitdebugger.exe\" -p %ld -e %ld"
"UserDebuggerHotKey"=dword:00000000
To disable JIT debugging use:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug]
"Auto"="1"
"Debugger"=-
"UserDebuggerHotKey"=-
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug]
"Auto"="1"
"Debugger"=-
"UserDebuggerHotKey"=-
Just a FYI, I wrote a simple cmd script to enable/disable on a per executable name basis. I'm posting it here for you convenience:
#echo off
if %1.==. goto help
if %1==/internal goto apply
if %1==/d (
%0 /internal %2 -
) else (
%0 /internal %1 "vsjitdebugger.exe"
)
goto help
:apply
shift
>%temp%\output.reg echo Windows Registry Editor Version 5.00
>>%temp%\output.reg echo+
if %2 == - (
: Delete registry key
>>%temp%\output.reg echo [-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\%~1]
) else (
: Add registry key
>>%temp%\output.reg echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\%~1]
>>%temp%\output.reg echo "debugger"=%2
)
:In case you want to see what it is importing, uncomment the following 3 lines
:echo %temp%\output.reg
:echo --------------------
:type %temp%\output.reg
regedit /s %temp%\output.reg
del %temp%\output.reg
goto :eof
:help
echo %0 [/d] ^<executable.exe^>
echo.
echo Allows you to attach a debugger as soon as the process executes anywhere in the
echo system. If /d switch is provided, then delete the registry key to stop this
echo behaviour.
Because of the use of %0, you can name it whatever you want (with an .cmd or .bat extension) and it will still work as expected.

Get the OS information if server 2003 then run the script

I have a .bat script that I created yesterday. I now need to find the OS name or a remote server and if its server 2003 64bit = true then run test.bat
Is there an easy way to do this?
Heres the script I want to run:
If OS = Server 2003
Then
psexec -u domain\user -p password \\#serverlist -s -i -d
msiexec.exe /i "\\share\folder\Avmr64.msi" /qb
I am finding several ways to get the info but how would I add an if statement in there?
One way you can test for a 64-bit system, without getting too technical, is to check for the C:\program files (x86)\ directory. In a 32-bit system, it's just C:\Program Files. This directory does also exist on 64-bit systems, so the absence of the C:\Program Files (x86)\ tells you it's 32-bit.
The third line of this batch file will run if the directory exists, if it doesn't exist, it goes to the :NoUse32bitVersion label.
C:
IF NOT EXIST "C:\Program Files (x86)\" GOTO IS32BIT
psexec -u domain\user -p password \\#serverlist -s -i -d msiexec.exe /i "\\share\folder\Avmr64.msi" /qb
:IS32BIT
echo Put your 32-bit version of the code here (or just EXIT)
ver | find "2003" > nul
if %ERRORLEVEL% == 0 goto ver_2003
ver | find "some other os string" > nul
if %ERRORLEVEL% == 0 goto some_other_os
:ver_2003
your 2003 specific code here
Replace "some other os string" with meaningful string to get info about other os's if you want.

Resources