Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

Having issues with with a script that won't execute

Can someone look at this script for me and tell me what I'm missing?

@echo off

reg query HKCU\Software\Microsoft\Office\16.0\Outlook\Profiles\o365 >nul if %errorlevel% equ 0 (

echo "mykey exists- do nothing" ) else (

echo "mykey does not exist - add the key and give it a value" reg add HKCU\Software\Microsoft\Office\16.0\Outlook\Profiles\o365 reg add "HKCU\Software\Microsoft\Office\16.0\Outlook" /v DefaultProfile /t REG_SZ /d "o365" /F

)

PAUSE

0

Comments

1 comment
Date Votes
  • I don't think you can start the "if" on the same line as the other code.

    @echo off
    
    reg query HKCU\Software\Microsoft\Office\16.0\Outlook\Profiles\o365 >nul
    
    if %errorlevel% equ 0 (
    
        echo "mykey exists- do nothing"
    
    ) else (
    
        echo "mykey does not exist - add the key and give it a value"
        reg add HKCU\Software\Microsoft\Office\16.0\Outlook\Profiles\o365
        reg add "HKCU\Software\Microsoft\Office\16.0\Outlook" /v DefaultProfile /t REG_SZ /d "o365" /F
    
    )
    
    PAUSE
    
    0