Script issue on "FINDSTR"

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Timecop79
Posts: 3
Joined: 16 Jun 2023 14:30

Script issue on "FINDSTR"

#1 Post by Timecop79 » 16 Jun 2023 14:37

Hi, I have a problem with the following script.

Code: Select all

 @echo off
REM Check the OS version
wmic os get Caption | findstr /i "Microsoft Windows 10 Enterprise" > nul
if %errorlevel% equ 0 (
    set "install_folder=\\server\share\EnterpriseAppFolder"
) else (
    wmic os get Caption | findstr /i "Microsoft Windows 10 Professional" > nul
    if %errorlevel% equ 0 (
        set "install_folder=\\server\share\ProfessionalAppFolder"
    ) else (
        echo Unsupported OS version.
        exit /b 1
    )
)
REM Install the application
echo Installing application from %install_folder%...
msiexec /i "%install_folder%\application.msi" /qn
REM Add additional installation steps if needed
exit /b 0 
In both cases, it always chooses the first option, and %errorlevel% is equal to zero. Even though it is Windows 10 Professional, it selects the "Windows 10 Enterprise" option. Although the script seems to be correct, please help me

Lucky4Me
Posts: 19
Joined: 21 Oct 2020 06:33

Re: Script issue on "FINDSTR"

#2 Post by Lucky4Me » 17 Jun 2023 07:16

Have you run "wmic os get Caption" in a DOS window on the PC?
Because when i run it i'll get "Microsoft Windows 10 Pro" not "Microsoft Windows 10 Professional" and that's a great difference!

Lucky4Me
Posts: 19
Joined: 21 Oct 2020 06:33

Re: Script issue on "FINDSTR"

#3 Post by Lucky4Me » 17 Jun 2023 08:25

Maybe this can help?

Code: Select all

@echo off
REM Check the OS version
for /f "tokens=3-5 delims= " %%i in ( 'REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" ^| findstr ProductName' ) do set "winversion=%%i %%j %%k"
if "%winversion%" == "Windows 10 Enterprise" (
    set "install_folder=\\server\share\EnterpriseAppFolder"
) else (
    if "%winversion%" == "Windows 10 Pro" (
        set "install_folder=\\server\share\ProfessionalAppFolder"
    ) else (
        echo Unsupported OS version.
        exit /b 1
    )
)

echo %winversion%
echo %install_folder%
pause
I don't know what "Productname" it gives on a Enterprise edition? But on my Professional version it gives me "Windows 10 Pro" and it works for me!
Maybe you have to change the Productnames in the script to work with your PC's

miskox
Posts: 554
Joined: 28 Jun 2010 03:46

Re: Script issue on "FINDSTR"

#4 Post by miskox » 17 Jun 2023 13:19

Strange. See this what I get on my computer:

Code: Select all

c:\REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion"|find /i "product"
    ProductName    REG_SZ    Windows 10 Enterprise

c:\>wmic os get Caption
Caption
Microsoft Windows 10 Pro

c:\>systeminfo|find /i "os name"
OS Name:                   Microsoft Windows 10 Pro
c:\>
Saso

Lucky4Me
Posts: 19
Joined: 21 Oct 2020 06:33

Re: Script issue on "FINDSTR"

#5 Post by Lucky4Me » 17 Jun 2023 13:37

This is what i get

Code: Select all

C:\>REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" | findstr ProductName
    ProductName    REG_SZ    Windows 10 Pro

C:\>wmic os get Caption
Caption
Microsoft Windows 10 Pro


C:\>systeminfo|find /i "os name"
OS Name:                   Microsoft Windows 10 Pro

C:\>

Timecop79
Posts: 3
Joined: 16 Jun 2023 14:30

Re: Script issue on "FINDSTR"

#6 Post by Timecop79 » 17 Jun 2023 18:12

Thanks a lot for replies, I have to tell you that I'm using French version Et it display with caption option "Microsoft Windows 10 professionnel"

Timecop79
Posts: 3
Joined: 16 Jun 2023 14:30

Re: Script issue on "FINDSTR"

#7 Post by Timecop79 » 18 Jun 2023 05:55

i found this solution in a forum,think it's working

Code: Select all

@echo off
REM Check the OS version
wmic os get Caption | find "Microsoft Windows 10 Enterprise" >nul && set "install_folder=\\server\share\EnterpriseAppFolder"
wmic os get Caption | find "Microsoft Windows 10 Professional" >nul && set "install_folder=\\server\share\ProfessionalAppFolder"
if not defined install_folder (
	echo Unsupported OS version.
	exit /b 1
)
 
REM Install the application
echo Installing application from %install_folder%...
echo msiexec /i "%install_folder%\application.msi" /qn
REM Add additional installation steps if needed
exit /b 0

miskox
Posts: 554
Joined: 28 Jun 2010 03:46

Re: Script issue on "FINDSTR"

#8 Post by miskox » 18 Jun 2023 13:46

Code: Select all

@echo off
for /f "tokens=4 delims= " %%f in ('wmic os get Caption ^| find "Microsoft Windows 10"') do set "install_folder=\\server\share\%%fAppFolder"

echo _%install_folder%_
Unless there are more than two versions in your environment then you could add something like:

Code: Select all

if not exist "%install_folder%\application.msi" echo ERRROR&goto :EOF
Saso

Post Reply