none
Batch File Not Working RRS feed

  • Question

  • Hello,

    I had created a batch file which :

    1) Creates a folder under C: drive
    2) Copies data over the network to this created folder
    3) Creates new environment variable

    The script is segregated for x86 and x64 systems based on below :

    ....................................................................................................................................................................

    :CheckOS
    IF "%PROCESSOR_ARCHITECTURE%"=="x86" (GOTO 32BIT) ELSE (GOTO 64BIT)

    :32BIT
    md C:\TEST\x86
    xcopy /s "\\Servername\Foldername\x86" "C:\TEST\x86"
    setx TEST_HOME C:\TEST\x86
    GOTO END

    :64BIT
    md C:\TEST\x64
    xcopy /s "\\Servername\Foldername\x64" "C:\TEST\x64"
    setx TEST_HOME C:\TEST\x64
    GOTO END

    :END

    ....................................................................................................................................................................

    The script was working fine but suddenly it has started behaving strangely. It is only executing first two lines of the 32BIT  category for both x86 or x64 systems and doesnt do anything else, which it was doing some time back. Once this works, my main motive is to achieve the following script. This is what I was trying to achieve and modified the script and it now doesnt work for the first scenario which it was :

    :CheckOS
    IF "%PROCESSOR_ARCHITECTURE%"=="x86" (GOTO 32BIT) ELSE (GOTO 64BIT)

    :32BIT
    md C:\TEST\x86
    xcopy /s "\\Servername\Foldername\x86" "C:\TEST\x86"
    setx TEST_HOME C:\TEST\x86
    GOTO END

    :64BIT
    md C:\TEST\x86

    md C:\TEST\x64
    xcopy /s "\\Servername\Foldername\x86" "C:\TEST\x86"
    xcopy /s "\\Servername\Foldername\x64" "C:\TEST\x64"
    setx TEST_HOME C:\TEST\x86
    setx TEST_HOME C:\TEST\x64
    GOTO END


    :END

    I am trying to achieve this via SCCM. The above (2nd script) works when executed from command prompt on the local system.

    Thursday, June 2, 2016 11:41 AM

Answers

All replies

  • Hi,

    This is likely because ConfigMgr is executing your script as a 32 bit process no matter what the system type is.

    I'd ask for further guidance here:

    https://social.technet.microsoft.com/Forums/en-US/home?forum=configmanagerapps

    Make sure you include details, such as if you're using package/program or application.


    • Edited by Mike Laughlin Thursday, June 2, 2016 12:23 PM
    • Proposed as answer by jrv Thursday, June 2, 2016 1:40 PM
    Thursday, June 2, 2016 12:23 PM
  • But it was working before for both the systems and only stopped when I tried to execute the second script.
    Thursday, June 2, 2016 12:36 PM
  • But it was working before for both the systems and only stopped when I tried to execute the second script.
    The script works when you execute it manually, so there is no problem with the script. This only leaves your method of executing it as the problem, which is a ConfigMgr question.

    Thursday, June 2, 2016 12:41 PM
  • Yes, I understand Mike,

    Have already opened a new thread.
    Thanks :)

    • Marked as answer by Vikram Midha Monday, July 25, 2016 10:02 AM
    Friday, June 3, 2016 9:28 AM
  • Hello Mike,

    I had a new thread opened and as per the discussions, I was advised to capture the execution in logs. To do that, I had modified the script and now it captures the execution to see where is it failing exactly. But for some reasons, the logs are overwritten, how could I prevent that?

    the new script is as below :

    ----------------------------------------------------------------------------------------------------------------------------------------

    :CheckOS
    IF "%PROCESSOR_ARCHITECTURE%"=="x86" (GOTO 32BIT) ELSE (GOTO 64BIT) >> C:\ABClogs.log

    :32BIT
    md C:\TEST\x86 >> C:\ABClogs.log
    xcopy /s "\\Servername\Foldername\x86" "C:\TEST\x86" >> C:\ABClogs.log
    setx TEST_HOME C:\TEST\x86 >> C:\ABClogs.log
    GOTO END


    :64BIT
    md C:\TEST\x86 >> C:\ABClogs.log
    md C:\TEST\x64 >> C:\ABClogs.log
    xcopy /s "\\Servername\Foldername\x86" "C:\TEST\x86" >> C:\ABClogs.log
    xcopy /s "\\Servername\Foldername\x64" "C:\TEST\x64" >> C:\ABClogs.log
    setx TEST_HOME C:\TEST\x86 >> C:\ABClogs.log
    setx TEST_HOME C:\TEST\x64 >> C:\ABClogs.log
    GOTO END


    :END

    ----------------------------------------------------------------------------------------------------------------------------------------

    Wednesday, June 15, 2016 5:09 AM
  • There's nothing in what you've posted that should overwrite your log files, since you're always using >> and never >.

    As a simple example, put this into a batch file and run it a few times:

    echo %time% >> time.txt

    The time.txt file will be updated each execution and not overwritten.


    Wednesday, June 15, 2016 6:20 PM