[Solved] How to find and get part of a string?

Discussion in 'Scripting' started by xinso, Apr 25, 2014.

  1. xinso

    xinso MDL Guru

    Mar 5, 2009
    13,698
    14,428
    340
    #1 xinso, Apr 25, 2014
    Last edited by a moderator: Apr 20, 2017
    Thank you, Compo and leebo_28.

    With this script, I get e.g. WordRetail. But all I want is the part before Retail, i.e. Word.

    Code:
    for /f "tokens=7 delims=\ " %%A in (' "reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall | findstr /i Retail" ') do (set name=%%A)
    Thanks.
     
  2. leebo_28

    leebo_28 MDL Senior Member

    Jun 12, 2011
    464
    174
    10
    #2 leebo_28, Apr 25, 2014
    Last edited by a moderator: Apr 20, 2017
    FINDSTR "\<Word\>"
     
  3. xinso

    xinso MDL Guru

    Mar 5, 2009
    13,698
    14,428
    340
    #3 xinso, Apr 25, 2014
    Last edited: Apr 25, 2014
    (OP)
    Thanks, leebo_28.

    My problem is there are 15 of them:

    ProPlus
    Standard
    ProjectPro
    ProjectStd
    VisioPro
    VisioStd

    Access
    Excel
    InfoPath
    Lync
    OneNote
    Outlook
    PowerPoint
    Publisher
    Word

    How to get rid of "Retail", so one script is enough?

    Thanks.
     
  4. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    Are you aware that the Uninstall key you are checking is for 32-bit software editions only?

    To provide you with some code examples it would be advantageous to know the intended host OS's, the 'Office' version(s) and the if possible the complete actual strings you are wishing to parse; (as opposed to the intended end results already posted).

    There is more than one way to skin a cat, so if you were good enough to provide an overview of your intent, there may simply be a better way of achieving your goal.
     
  5. xinso

    xinso MDL Guru

    Mar 5, 2009
    13,698
    14,428
    340
    #5 xinso, Apr 26, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Thanks, Compo.

    I wish to get the exact name (without including Retail) of Click-to-Run Office 2013 and set it as variable, so as to set channel directly in the script, the way I do for RTM Office 2013.
    Code:
    for /f "tokens=2 delims==" %%A in ('"wmic path %slp% where (ApplicationID='0ff1ce15-a989-479d-af46-f275c6370663' and PartialProductKey!=NULL) get LicenseFamily /format:list 2>nul"') do (set channel=%%A&call:%%A)
    for /f "tokens=7 delims=\ " %%A in ('"reg query %wowCTR% 2>nul | findstr /i Retail >nul 2>&1"') do (call:%%A)
    For eample, I get Word (without including Retail), then I rewrite the script for Click-to-Run Office 2013 this way:

    Code:
    for /f "tokens=7 delims=\ " %%A in ('"reg query %wowCTR% 2>nul | findstr /i Retail >nul 2>&1"') do (set channel=Office%%AR_Grace&call:%%A)
    And for each edition, it simply looks like

    Code:
    :Word
    :OfficeWordVL_KMS_Client
    :OfficeWordR_Grace
    :OfficeWordVL_MAK
    :OfficeWordR_Retail
    :OfficeWordR_OEM_Perp
    :OfficeWordMSDNR_Retail
    set name=Word&set edition=Word&set kmskey=6Q7VD-NX8JD-WJ2VH-88V73-4GBJ7&set iskmsid=d9f5b1c6-5386-495a-88f9-9ad6b41ac9b3&call:IfExist&goto:eof
    Otherwise I need to set name as WordRetail and set channel for each and every Click-to-Run edition.

    e.g. Click-to-Run Office Word 2013
    Code:
    :WordRetail
    set channel=OfficeWordR_Grace
    :OfficeWordVL_KMS_Client
    :OfficeWordR_Grace
    :OfficeWordVL_MAK
    :OfficeWordR_Retail
    :OfficeWordR_OEM_Perp
    :OfficeWordMSDNR_Retail
    set name=Word&set edition=Word&set kmskey=6Q7VD-NX8JD-WJ2VH-88V73-4GBJ7&set iskmsid=d9f5b1c6-5386-495a-88f9-9ad6b41ac9b3&call:IfExist&goto:eof
    [/COLOR]
     
  6. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    #6 Compo, Apr 26, 2014
    Last edited by a moderator: Apr 20, 2017
    Taking your first post example registry key, what result do you get from the following? and does it help?
    Code:
    For /f "tokens=*" %%A In ('Reg Query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /k /c /f Retail 2^>Nul^|Find "\"') Do (Set "name=%%~nxA" & Call Set "name=%%name:Retail=%%")
    [Edit]
    For the line in your latest post, using the same technique perhaps something like this:
    Code:
    For /f "tokens=*" %%A In ('Reg Query "%wowCTR%" /k /c /f Retail 2^>Nul^|Find "\"') Do (Set name=%%~nxA & Call Set channel=Office%%name:Retail=%%R_Grace & Call :%%name:Retail=%%)
     
  7. xinso

    xinso MDL Guru

    Mar 5, 2009
    13,698
    14,428
    340
    #7 xinso, Apr 26, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Seemlingly it works. I'll rewrite the script for all Click-to-Run editions and feedback.

    Edit:

    Well, It calls "Word" alright, but %channel% does not seem right. Look

    Code:
    :Word
    echo %channel%
    pause
    :OfficeWordVL_KMS_Client
    :OfficeWordR_Grace
    :OfficeWordVL_MAK
    :OfficeWordR_Retail
    :OfficeWordR_OEM_Perp
    :OfficeWordMSDNR_Retail
    set name=Word&set edition=Word&set kmskey=6Q7VD-NX8JD-WJ2VH-88V73-4GBJ7&set iskmsid=d9f5b1c6-5386-495a-88f9-9ad6b41ac9b3&call:IfExist&goto:eof
    
    Code:
    OfficeWord - zh-tw R_Grace
    Press any key to continue . . .
    What expected is "OfficeWordR_Grace".

    I'll install another edition and feedback. Thanks.

    Same result for Publisher

    Code:
    :Publisher
    echo %channel%
    pause
    :OfficePublisherVL_KMS_Client
    :OfficePublisherR_Grace
    :OfficePublisherVL_MAK
    :OfficePublisherR_Retail
    :OfficePublisherR_OEM_Perp
    :OfficePublisherMSDNR_Retail
    set name=Publisher&set edition=Publisher&set kmskey=PN2WF-29XG2-T9HJ7-JQPJR-FCXK4&set iskmsid=00c79ff1-6850-443d-bf61-71cde0de305f&call:IfExist&goto:eof
    
    Code:
    OfficePublisher - zh-tw R_Grace
    Press any key to continue . . .
    I changed it to

    for /f "tokens=7 delims=\ " %%A In ('Reg Query "%wowCTR%" /k /c /f Retail 2^>Nul^|Find "\"') Do (Set name=%%~nxA & Call Set channel=Office%%name:Retail=%%R_Grace & Call :%%name:Retail=%%)

    And the result

    Code:
    OfficePublisher R_Grace
    Press any key to continue . . .
    A space in between r and R.
     
  8. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    #8 Compo, Apr 26, 2014
    Last edited by a moderator: Apr 20, 2017
    I'm having to guess at it a little here because I have no idea what the actual registry key contains in order to parse it correctly.

    What happens if you use the same line without the tokens?
    Code:
    For /f %%A In ('Reg Query "%wowCTR%" /k /c /f Retail 2^>Nul^|Find "\"') Do (Set "name=%%~nxA" & Call Set "channel=Office%%name:Retail=%%R_Grace" & Call :%%name:Retail=%%)
     
  9. xinso

    xinso MDL Guru

    Mar 5, 2009
    13,698
    14,428
    340
    #9 xinso, Apr 26, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Oh, yeah! It works.

    Code:
    OfficePublisherR_Grace
    Press any key to continue . . .
    Code:
    OfficePublisherVL_KMS_Client
    Press any key to continue . . .
    OfficePublisherR_Grace
    Press any key to continue . . .
    Microsoft (R) Windows Script Host Version 5.8
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    License file R:\TEMP\publishervl_kms_client-ppd.xrm-ms installed successfully.
    
    
    Microsoft (R) Windows Script Host Version 5.8
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    License file R:\TEMP\publishervl_kms_client-ul-oob.xrm-ms installed successfully
    .
    
    
    Microsoft (R) Windows Script Host Version 5.8
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    License file R:\TEMP\publishervl_kms_client-ul.xrm-ms installed successfully.
    
    
    Press any key to continue . . .
    Thanks a lot. Thank you, Compo.