Page 1 of 1

Script issue on "FINDSTR"

Posted: 16 Jun 2023 14:37
by Timecop79
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

Re: Script issue on "FINDSTR"

Posted: 17 Jun 2023 07:16
by Lucky4Me
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!

Re: Script issue on "FINDSTR"

Posted: 17 Jun 2023 08:25
by Lucky4Me
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

Re: Script issue on "FINDSTR"

Posted: 17 Jun 2023 13:19
by miskox
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

Re: Script issue on "FINDSTR"

Posted: 17 Jun 2023 13:37
by Lucky4Me
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:\>

Re: Script issue on "FINDSTR"

Posted: 17 Jun 2023 18:12
by Timecop79
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"

Re: Script issue on "FINDSTR"

Posted: 18 Jun 2023 05:55
by Timecop79
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

Re: Script issue on "FINDSTR"

Posted: 18 Jun 2023 13:46
by miskox

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