Help batch

Discussion in 'Scripting' started by mnguyen, May 3, 2015.

  1. mnguyen

    mnguyen MDL Novice

    Jan 21, 2011
    30
    0
    0
    #1 mnguyen, May 3, 2015
    Last edited by a moderator: Apr 20, 2017
    hello,

    sorry for my bad English

    this code does not work

    Code:
    IF NOT EXIST "D:\SOURCE\A"  (
    
     SET A=D:\SOURCE 
    
     SET B=%A%\tata
    )
    
    ECHO. %B%
    
    result is   \tata
    
    
    why %a% is not initialized?

    thanks
     
  2. Soulfate

    Soulfate MDL Member

    Feb 14, 2011
    185
    51
    10
    #2 Soulfate, May 3, 2015
    Last edited: May 4, 2015
    [EDIT]
    Sorry, I'd badly understood the problem. I'm tired ^^
     
  3. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,965
    908
    60
    #3 Flipp3r, May 3, 2015
    Last edited by a moderator: Apr 20, 2017
    Direct copy & paste and I get: D:\SOURCE \tata

    No prob for me...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. mnguyen

    mnguyen MDL Novice

    Jan 21, 2011
    30
    0
    0
    I expect following the RESULT 'D:\SOURCE\tata' but I have '\tata' and I do not understand why
     
  5. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    #5 Compo, May 4, 2015
    Last edited by a moderator: Apr 20, 2017
    You need to use delayed expansion.
    Code:
    @ECHO OFF
    SETLOCAL ENABLEDELAYEDEXPANSION
    IF NOT EXIST "D:\SOURCE\A\" (
    SET "A=D:\SOURCE"
    SET "B=!A!\tata"
    )
    ECHO. %B%
    PAUSE
    You could of course just arrange things a little differently.
    Code:
    @ECHO OFF
    SETLOCAL ENABLEEXTENSIONS
    SET "A=D:\SOURCE"
    IF NOT EXIST "%A%\A\" (SET B=%A%\tata)
    ECHO. %B%
    PAUSE
     
  6. mnguyen

    mnguyen MDL Novice

    Jan 21, 2011
    30
    0
    0
    Thanks @Compo
     
  7. greenworld5588

    greenworld5588 MDL Novice

    Jun 4, 2014
    19
    0
    0
    Sorry if off topic.
    I want to run two exe files on first logon after Windows 7 installation completion.
    First file name: one.exe
    Second file name: act.exe

    Any one can guide me how to do this? If this require setupcomplete.cmd, please compile cmd for this. Thanks
     
  8. The_Guardian

    The_Guardian Contributor

    May 7, 2012
    2,054
    6,803
    90
    #8 The_Guardian, May 26, 2015
    Last edited by a moderator: Apr 20, 2017
    You can do something like this...
    (assumes that exe's and cmd file are in the scripts folder for this example)

    Step one to add reg entry in setupcomplete.cmd:
    Code:
    reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v !RUN /t REG_SZ /d "%windir%\Setup\scripts\Run.cmd" /f >nul
    Step two to create the Run.cmd itself to install the two exe's:
    Code:
    @echo off
    
    IF EXIST "%windir%\Setup\scripts\one.exe" CALL "%windir%\Setup\scripts\one.exe"
    IF EXIST "%windir%\Setup\scripts\one.exe" DEL /F /Q "%windir%\Setup\scripts\one.exe" >nul
    IF EXIST "%windir%\Setup\scripts\two.exe" CALL "%windir%\Setup\scripts\two.exe"
    IF EXIST "%windir%\Setup\scripts\two.exe" DEL /F /Q "%windir%\Setup\scripts\two.exe" >nul
    
    DEL /F /Q "%~f0"&EXIT >nul
     
  9. knowledge01

    knowledge01 MDL Novice

    Jul 18, 2015
    4
    0
    0
    nice

    nice job
    Guardian