1

Ok, I have spent the better half of the last like 6 hours trying to get this to work and I'm nearly pulling my hair out. If someone could help be figure this out I would be eternally grateful.

@ECHO on
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
CALL:MicrsoftInstaller-IntegrityCheck "x86" "KB978601" "2010\MS10-019\WinSec-MS10-019-011-P57297-Windows6.1-KB978601-x86.msu" "/quiet /norestart"
pause

:MicrsoftInstaller-IntegrityCheck
SET MSCheck="%~1"
IF "%~1" NEQ "" (
    IF /I %MSCheck:~1,1%=="/"       SET MSI_Switch=%MSCheck%
    IF /I %MSCheck:~1,2%=="20"      SET MSI_Path=%MSCheck%
    IF /I %MSCheck:~1,20%=="KB"     SET MSI_KB=%MSCheck%
    IF /I %MSCheck%=="x64"          SET MSI_Architecture=x64
    IF /I %MSCheck%=="x86"          SET MSI_Architecture=x86    
       SHIFT
       GOTO:MicrsoftInstaller-IntegrityCheck
)
ECHO KB: %MSI_KB%
ECHO Switches: %MSI_Switch%
ECHO Path: %MSI_Path%
ECHO Architecture: %MSI_Architecture%
GOTO:EOF
1
  • 1
    Well, if you could say what your program is supposed to do and describe where you are stuck, it would be easier to help you. Commented Jul 14, 2012 at 15:08

1 Answer 1

1

Some small changes were necessary to make it work:

@ECHO off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
CALL:MicrsoftInstaller-IntegrityCheck "x86" "KB978601" "2010\MS10-019\WinSec-MS10-019-011-P57297-Windows6.1-KB978601-x86.msu" "/quiet /norestart"
pause

:MicrsoftInstaller-IntegrityCheck
SET MSCheck="%~1"
IF "%~1" EQU "" GOTO Part2

IF /I "%MSCHECK:~1,1%"=="/"       SET MSI_Switch=%MSCheck%
IF /I "%MSCheck:~1,2%"=="20"      SET MSI_Path=%MSCheck%
IF /I "%MSCheck:~1,2%"=="KB"     SET MSI_KB=%MSCheck%
IF /I %MSCheck%=="x64"          SET MSI_Architecture=x64
IF /I %MSCheck%=="x86"          SET MSI_Architecture=x86    
SHIFT
GOTO:MicrsoftInstaller-IntegrityCheck

:Part2
ECHO KB: %MSI_KB%
ECHO Switches: %MSI_Switch%
ECHO Path: %MSI_Path%
ECHO Architecture: %MSI_Architecture%
GOTO:EOF

First I added some double-quotes in your if statements.

The second problem is linked to how Batch interprets code: line after line. When it came to your line IF "%~1" NEQ "" ( it tried to interpret the following code block even when the condition was not satisfied (=no more argument to check). But with MSCHECK equal to "", the first if statement became IF /I """=="/" which resulted in an error.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much! I think i tried every single combination of quotes, brackets, and if statements except getting rid of the overall if loop. That never cam across my mind because I have an if statement elsewhere in my code that was nearly identical to this statement and had no issues with it at all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.