[Batch] The Official Batch File Repository - Learn & ask questions about batch files

Discussion in 'Scripting' started by timesurfer, Oct 11, 2010.

  1. Yen

    Yen Admin
    Staff Member

    May 6, 2007
    13,081
    13,980
    340
    We are planning to create a own Coding Life section with a own forum therefore. So all can create different threads about different coding / scripting subjects. It will be a lot easier to navigate then.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. DARKOR04

    DARKOR04 MDL Tester/Developer

    Jul 5, 2010
    497
    909
    10
    Awesome idea Yen... ;)
     
  3. odinthegreatone

    odinthegreatone MDL Junior Member

    Dec 4, 2008
    80
    2
    0
    I was wondering if anyone could help me with creating a xcopy script with creating a date as the folder (this folder would have today's date and all the files that needed to be copy would be copy to this folder). thanks.
     
  4. calpo

    calpo MDL Member

    Apr 23, 2010
    212
    60
    10
    A question to all,

    When do you need to save a file as .bat or .cmd with same scripts? What's the diffenrence between .bat and .cmd ?

    Thanks for your explaination.
     
  5. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    I really like the idea of an actual new forum called "Coding Life"

    Superb :worthy:

    I can see:

    1. Web Coding thread
    2. C#
    3. Php
    4. My scripting/batch file repo

    I am really excited how this turns out. I kinda see it like a interactive school of sorts ;)

    Thanks Yen :hug2:
     
  6. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    #46 MasterDisaster, Oct 19, 2010
    Last edited by a moderator: Apr 20, 2017
    The following command will create a folder with today's date. Set source to the path name of the folder to be copied.

    Code:
    set source="<path to my folder>"
    set dest=%date:~4%
    set dest=%dest:/=-%
    mkdir %dest%
    xcopy /is %source% %dest%
    
    Code Explained:

    set dest=%date:~4% will store the date in dest in the following format mm/dd/yy
    set dest=%dest:/=-% will replace the '/' with '-' because folder names do not allow special characters
    mkdir %dest% creates a folder in the current directory
    xcopy /is %source% %dest% /i switch is to specify that it is a folder copy operation, /s is to copy the subdirectories
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    #47 MasterDisaster, Oct 19, 2010
    Last edited by a moderator: Apr 20, 2017
    The only difference is how the ERRORLEVEL is used in .bat and .cmd file. The ERRORLEVEL is updated after each command in .cmd, but in .bat it is updated only on an error.
    To illustrate the above point, here is a small example.
    Code:
    @echo off
    wmic path OfficeSoftwareProtection
    echo %errorlevel%
    assoc .mkv=MKVFile
    echo %errorlevel%
    
    Run as 1.bat
    Code:
    C:\>1.bat
    Node - MD-PC
    ERROR:
    Description = Invalid class
    
    
    -2147217392
    .mkv=MKVFile
    -2147217392
    
    Run as 1.cmd

    Code:
    C:\>1.bat
    Node - MD-PC
    ERROR:
    Description = Invalid class
    
    
    -2147217392
    .mkv=MKVFile
    0
    
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. calpo

    calpo MDL Member

    Apr 23, 2010
    212
    60
    10
    @ MasterDisaster

    Thanks so much for your helpful info.

    Have a good day
     
  9. ar_seven_am

    ar_seven_am MDL Senior Member

    Mar 7, 2010
    398
    129
    10
    #49 ar_seven_am, Oct 19, 2010
    Last edited: Oct 19, 2010
    Nice, interestin' n should be sticky (it had already) lol... By the way, should this placed on windows 7 only? What I see we can used in xp n vista too, right?

    CHALLENGE : Hmm, guys n girls, there's already batch scripts oem-slp for windows 7/vista made by member of MDL(example searchengine, sam n hazard), how bout XP? I've seen the scripts but it based on Mr. Smartepants n other members of MSFN n Siginet Forums (includin' Freestyler for the source slp 1), so it just an idea, thought we can made multi OEM-XP scripts code based MDL members? I mean pure from MDL member code! (Please correct me if the person who made the scripts already MDL member too, as I can see lots of MSFN, Ryanvm, Wincert, Siginet member has already here like Ricktendo64, urie, veegertx aka maxxp, freestyler, user_hidden, raoul etc)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. Yen

    Yen Admin
    Staff Member

    May 6, 2007
    13,081
    13,980
    340
    We'll start with 2 forums at the Coding Life category. More can be added easily...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  11. HALIKUS

    HALIKUS MDL Addicted

    Jul 29, 2009
    526
    371
    30
    I made this small script to copy a Win7PE to my harddrive and add a bcd entry. Im new to coding and used a bunch of kindergarden stuff to get the job done, but it makes use of some simple "tricks" i found very useful. It searches for Sources\boot.wim in any root, searches for your boot\BCD (i don't use the 100 meg recovery partition), then copies boot.sdi to boot\ and adds the proper BCD entries. Don't so much try to use this as its intended, but more an example of what you can do in a simple cmd.


    echo off
    echo ** This is for making a pe recovery partition
    echo ** Find PE in Sources\boot.wim and copy to \boot then add to boot record. Wait a few seconds...
    FOR %%i IN (C D E F G H I J K L M N O P Q R S T U V W) DO IF EXIST "%%i:\Sources\boot.wim" (SET CDROM=%%i:& goto DONECD)
    :DONECD

    echo ** Find bcd in boot\bcd
    FOR %%i IN (C D E F G H I J K L M N O P Q R S T U V W) DO IF EXIST "%%i:\boot\bcd" (SET bcd=%%i:& goto DONECD)
    :DONECD

    echo f | XCOPY /Y /E /I /Q "%CDROM%\sources\Boot.WIM" "c:\windows\*"
    echo f | XCOPY /Y /E /I /Q "%~dp0boot.sdi" "%bcd%\boot\*"
    set BCD-File="%bcd%\boot\bcd"
    @echo on
    echo ** Enable more than 4GB of memory to be semi-used (displayed)
    %~dp0Bcdedit /set nx Alwaysoff
    %~dp0Bcdedit /set pae ForceEnable
    %~dp0Bcdedit /store %BCD-File% /create {ramdiskoptions} /d "WinPE Recovery"
    %~dp0Bcdedit /store %BCD-File% /set {ramdiskoptions} ramdisksdidevice partition=%bcd%
    %~dp0Bcdedit /store %BCD-File% /set {ramdiskoptions} ramdisksdipath \boot\boot.sdi
    for /f "tokens=3" %%a in ('bcdedit -store %BCD-File% -create /d "WinPE Recovery" -application osloader') do set guidWinPE=%%a
    %~dp0Bcdedit /store %BCD-File% /set %guidWinPE% device ramdisk=[c:]\windows\boot.wim,{ramdiskoptions}
    %~dp0Bcdedit /store %BCD-File% /set %guidWinPE% path \windows\system32\boot\winload.exe
    %~dp0Bcdedit /store %BCD-File% /set %guidWinPE% osdevice ramdisk=[c:]\windows\boot.wim,{ramdiskoptions}
    %~dp0Bcdedit /store %BCD-File% /set %guidWinPE% systemroot \windows
    %~dp0Bcdedit /store %BCD-File% /set %guidWinPE% winpe yes
    Bcdedit /store %BCD-File% /set %guidWinPE% detecthal yes
    bcdedit /displayorder %guidWinPE% /addlast
    bcdedit /store %BCD-File% /ENUM
    pause
     
  12. calpo

    calpo MDL Member

    Apr 23, 2010
    212
    60
    10
    #52 calpo, Oct 19, 2010
    Last edited: Oct 19, 2010
    @ MasterDisaster

    I have 2 files from Windows Vista pkeyconfig.xrm-ms & tokens.dat . How can I have a script to replace the original one in case of re-installing Windows ?

    If it's saved as .cmd, Where can I place it in DVD for silent installing ?

    here's the path for 2 files:

    C:\Windows\System32\licensing\pkeyconfig\pkeyconfig.xrm-ms

    C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareLicensing\tokens.dat

    Thanks in advance
     
  13. MasterDisaster

    MasterDisaster MDL Expert

    Aug 29, 2009
    1,256
    674
    60
    #53 MasterDisaster, Oct 20, 2010
    Last edited by a moderator: Apr 20, 2017
    Try this, place the pkeyconfig.xrm-ms and tokens.dat in the folder you are going to run the following script. The script will create $OEM$ folder that needs to be copied to the sources folder of the DVD.

    Code:
    md $OEM$\$$\System32\licensing\pkeyconfig
    md $OEM$\$$\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareLicensing
    copy pkeyconfig.xrm-ms $OEM$\$$\System32\licensing\pkeyconfig
     copy tokens.dat $OEM$\$$\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareLicensing
    
    After the installation completes, the files in the $OEM$ folder are automatically copied to the system drive.
    Somebody please correct me if I am wrong about the above point.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,488
    1,506
    150
    Thread:
    http://forums.mydigitallife.net/threads/22717-Remove-language-batch

    Question:
    I think this would be the right place to ask..

    I have Windows 7 AIO with 3 languages but im only using English.. So after an install of windows 7 ultimate i have 2 extra languages i really dont need..
    The languages are there beacuse other might need swedish language and my gf wants chinese language..

    I want to run the script manually after install if i want
    I guess i have to identify the installed language and somehow remove the other two..

    But how can i do that?

    Edit: Nice with a scripting subforum!
     
  15. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    #55 timesurfer, Oct 22, 2010
    Last edited: Oct 22, 2010
    (OP)
    I'm working on the first post as to create links to any lessons on certain cmds.

    Any ideas for the repository to keep it simple but extensive?

    @Calistoga

    I don't understand what your teaching in your helpful post. Could you explain more or give another explanation so I can put correct title to link your shared cmd post about directories in my first post?

    Thank you
     
  16. calpo

    calpo MDL Member

    Apr 23, 2010
    212
    60
    10
    #56 calpo, Oct 22, 2010
    Last edited by a moderator: Apr 20, 2017
    @MasterDisaster

    I gave it a try ..... It does not work.

    Thanks anyways.

     
  17. urie

    urie Moderator
    Staff Member

    May 21, 2007
    9,039
    3,388
    300
    What doesn't work some info would be handy
     
  18. BreakRulez

    BreakRulez MDL Novice

    Sep 28, 2010
    3
    0
    0
    #58 BreakRulez, Oct 23, 2010
    Last edited by a moderator: Apr 20, 2017
    MSI Installer Logger

    Hello Friends This is my 1st batch to add a menu to log *.msi installer..
    To see what changes are being made on your PC by the Installer.
    By Default Windows Shows Only 3 Options When Rite Click On a MSI installer.
    It'll add a new menu MSI Log.;)
    When Run a MSI file using this it'll create a MSILog.txt in the Installer Folder
    Menu Image
    Code:
    hxxp://4freeimagehost.com/uploads/714773effda9.png
    Save it as *.bat

    OR If Someone need a Registry
    Save it as *.reg

     
  19. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,527
    4,112
    270
    I think the Scripting forum is really coming along nicely.

    Great job MasterDisaster, Calistoga, tcntad, DARKOR04 and everybody else ;)
     
  20. tcntad

    tcntad MDL Guru

    Oct 26, 2009
    4,488
    1,506
    150
    Where did i come in & help? :p