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

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

  1. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    Telling me outright that my code doesn't work and 'laughing out loud' is what I'd perceive as rude.

    That said if you read the remit provided in the challenge, it stated
    Therefore you need to provide the batch file with that argument, (parameter). If you just double click the script then it will not receive an argument and will close the window by design. In order to receive an argument the invoker needs to provide one and the instructions for doing so are provided in very simple form above. I could add a question to the beginning of the file asking you to provide the required single integer in order to save you from having to do the less than laborious task of opening a console window all by yourself, but since it does not add anything to the script in response to the challenge then it is not my intention to do so.

    Unless you have a considerably smaller than usual console window size, (usually eighty characters wide), the diamond is not going to extend beyond its extents. A console window of only twelve characters wide should be sufficient to properly display the largest diamond, (nine), allowed by the script.
     
  2. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    At MDL we are not serious and we have fun. So me being amused at this coding stuff was not rude just playing

    Sounds like you got it covered then I'm just trying to learn and I had seen that challenge for several months and thought the console had to have diamond in just by running bat file

    And again remember I'm the only one who tried it so please recognize that cause I wanted to see you accomplish your goal not anything else

    Respect
     
  3. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    I've decided that it order to satisfy the curious who are a little intimidated by opening a Command Prompt window, navigating to a location and typing a command to make it a simple double click the script process.

    The code is the same, I've just added three more lines in order to ask the invoker directly for the number parameter. Just extract Diamond2.cmd from the zip file and double-click it to run it.

    View attachment Diamond2.zip
     
  4. chnix

    chnix MDL Member

    May 16, 2010
    147
    71
    10
    #164 chnix, Apr 1, 2011
    Last edited by a moderator: Apr 20, 2017
    Very interesting code. I'm a beginner and your code will help me a lot to understand the basics (like MasterDisaster said):

    Display message -- ECHO
    Use Variables -- SET
    Conditional Statements -- IF
    Looping Statements -- FOR

    Thank you.
     
  5. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    #165 timesurfer, Apr 1, 2011
    Last edited: Apr 2, 2011
    (OP)
    So you see we have a beginner following here at MDL so your "adjustment" is really appropriate for those who are "intimidated" :eek:

    [​IMG]

    Here is a project that I started a couple months ago if your interested

    I am working on the IR5 installation part which I'm sure you'll see in the last few pages

    http://forums.mydigitallife.net/thr...s-7-Office-2010-VL-and-Adobe-CS5-AIO-Solution

    See you :shisha:
     
  6. Calistoga

    Calistoga MDL Senior Member

    Jul 25, 2009
    420
    199
    10
    #166 Calistoga, Apr 2, 2011
    Last edited: Apr 2, 2011
    Excellent code Compo, very impressing.

    Your script is beyond my knowledge of batch :p
     
  7. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    #167 timesurfer, Jun 1, 2011
    Last edited: Jun 1, 2011
    (OP)
    Need simple cut/copy/xcopy code

    To move C:\MPC.bat to H:MPC.bat

    I'm doing this so MPC users don't have to reboot into windows to move MPC.bat to what actual drive the recovery console says local drive is

    Maybe I should use move cmd http://www.scriptlogic.com/Kixtart/htmlhelp/commands/move.htm

    Anyone care to do some teaching on the CD cmd and copy/move so we can learn

    Then I will link to first post as Batch file repo teaching

    Thanks
     
  8. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    #168 timesurfer, Jun 1, 2011
    Last edited by a moderator: Apr 20, 2017
    (OP)
    So I guess this works

    Code:
    move c:\MPC.bat "h:\MPC.bat"
    Anyone else want's to teach some cmd's please do so

    For instance how to view stuff in certain drive? Folders, files, etc...

    Or how search for file on all drives?

    Thanks
     
  9. UVAIS

    UVAIS MDL Expert

    Mar 17, 2011
    1,332
    1,895
    60
    how to make CMD hidden while running batch file?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    #170 timesurfer, Jun 2, 2011
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Both tasks in IR5 and IORRT run hidden

    Code:
    >NUL
    Code:
    schtasks /create /tn "IORRT" /tr "%SystemDrive%\IORRT\IORRT.bat" /sc %daily% /mo 1 /ru "" >NUL
    Code:
    schtasks /create /tn "IR5" /tr "'%SystemDrive%\Windows\system32\cmd.exe' /c cscript.exe /b %SystemDrive%\Windows\System32\slmgr.vbs /rearm && net stop sppsvc && net start sppsvc" /sc daily /mo 30 /ru "" /f >NUL
    Trilogy 2.8 is a really good way to learn how many cmds work
     
  11. UVAIS

    UVAIS MDL Expert

    Mar 17, 2011
    1,332
    1,895
    60
    #171 UVAIS, Jun 2, 2011
    Last edited by a moderator: Apr 20, 2017
    Please give me an example for this code

    Code:
    @ Echo off
    
    Del "C:\Users\UVJOHNAIS\Desktop\WINNTBBU.DLL"
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    #172 timesurfer, Jun 2, 2011
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Don't forget to say please

    Code:
    @Echo off
    Del "C:\Users\Uvais\Desktop\WINNTBBU.DLL" >NUL
    pause
    If file is not there to avoid error being shown try this

    Code:
    @Echo off
    Del "C:\Users\Uvais\Desktop\WINNTBBU.DLL" 2> nul
    pause
    Again! Trilogy is great learning tool to see these cmds and exactly how they work dude
     
  13. UVAIS

    UVAIS MDL Expert

    Mar 17, 2011
    1,332
    1,895
    60
    #173 UVAIS, Jun 2, 2011
    Last edited: Jun 2, 2011
    Thanks mate but i want to "hide" CMD Windows o_O

    [​IMG]
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    #174 timesurfer, Jun 2, 2011
    Last edited: Jun 2, 2011
    (OP)
    Then how are you going to run them?

    This is why I gave you tasks which can be set to run any batch file hidden

    And why does it matter if cmds are hidden if cmd prompt is hidden :eek:...lol

    If you remove the pause it won't stay open after cmd's are run
     
  15. UVAIS

    UVAIS MDL Expert

    Mar 17, 2011
    1,332
    1,895
    60
    so here is my aim i want to add .bat on my %%s pc @ Startup and i don't want to show when it run :p
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  16. Claysoft65

    Claysoft65 MDL Member

    Sep 4, 2009
    136
    51
    10
    #176 Claysoft65, Jun 2, 2011
    Last edited by a moderator: Apr 20, 2017
    Use a VBScript :

    Code:
    CreateObject("WScript.Shell").Run "C:\whateveryournameis.bat", 0, False
    :biggrin:

    I'm pretty sure you could already find it here at MDL (... if you'd search) ... but, first of all, There's in Trilogy Code too... :p
     
  17. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    #177 timesurfer, Jun 2, 2011
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Are you even listening at all to what I post or just posting :mad:

    Tasks can be run at startup...dah

    Code:
    schtasks /create /tn "Hybrid" /tr "%SystemDrive%\IORRT\IORRT.bat" /sc onstart /ru "" >NUL
     
  18. DoctorSAN

    DoctorSAN MDL Novice

    Jun 6, 2011
    1
    0
    0
    Sending BATCH variables over a network?

    Bit of a challenge here for the batch file gurus.. I'm trying to find a way to send batch file variables ranging from a few alphanumeric characters up to several hundred, over a network preferably using the TCP protocol, and capture them at the other end as variables in another batch file.
    Now scouring the net, I see vague references to people doing similar things by calling Winsock, but all those that I've found so far seem to be fairly elderly approaches from the Windows98/NT days, so I'm wondering (using contemporary XP/2003/vista/7 flavors of MS Windows), is there a reasonably elegant way to pull this off?

    Helper programs shouldn't be a problem as long as they're not bound by crazy licences, as are powershell scripts, but I'm trying to find a way without involving VB and high level language stuff. Suggestions?
     
  19. timesurfer

    timesurfer MDL Developer

    Nov 22, 2009
    8,524
    4,112
    270
    #179 timesurfer, Jul 3, 2011
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Hi, I was working on opening up hosts file and viewing

    Code:
    notepad "%SystemDrive%\Windows\System32\drivers\etc\hosts"
    But I wanted to have it close also

    Code:
    TASKKILL /S system /F /IM notepad.exe /T
    I can set delay fine between the two just can't close hosts file automatically ;)

    Any help?

    Thanks
     
  20. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    6,251
    22,365
    210
    #180 Alphawaves, Jul 3, 2011
    Last edited by a moderator: Apr 20, 2017
    Can you not just close notepad:

    Code:
    TASKKILL /IM notepad.exe /F >nul