Post your batch files v.hasthisbeendone?

Discussion in 'OT Technology' started by ez4me2c3d, Mar 4, 2008.

  1. ez4me2c3d

    ez4me2c3d Cold Member

    Joined:
    Sep 19, 2003
    Messages:
    1,836
    Likes Received:
    0
    Location:
    Minneapolis, MN
    Maybe by looking at some example scripts we can learn a trick or two and appreciate the usefulness of a batch file again.

    This one stop/starts/restarts services and logs the results. I made it specifically to restart the Remote Registry Service twice a day (scheduled task)
    Code:
    @echo off
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    ::
    ::
    ::
    ::
    ::
    :: This script will attempt to stop, start, or restart any service passed
    :: as an argument, and provide a method for logging the actions and results.
    ::
    :: Author:	Anthony
    ::
    :: Last Update:	09 JAN 2008
    ::
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    
    goto :help
    :begin
    
    set envsvc_mode=restart
    if /i {%1} == {/start} set envsvc_mode=start
    if /i {%1} == {/stop}  set envsvc_mode=stop
    
    set envsvc_log=nul
    if not {%envsvc_mode%} == {restart} shift
    if not {%1} == {} set envsvc_service=%1
    if not {%2} == {} set envsvc_log=%~f2
    
    call :%envsvc_mode%
    goto :eof
    
    :restart
    call :stop
    call :start
    goto :eof
    
    :start
    net start %envsvc_service% | find "success" > nul
    if ERRORLEVEL 0 (
      >> %envsvc_log% echo [%DATE% %TIME%] Successfully started service: %envsvc_service%
    ) else (
      >> %envsvc_log% echo [%DATE% %TIME%] Failed to start service: %envsvc_service%
    )
    goto :eof
    
    :stop
    net stop %envsvc_service% | find "success" > nul
    if ERRORLEVEL 0 (
      >> %envsvc_log% echo [%DATE% %TIME%] Successfully stopped service: %envsvc_service%
    ) else (
      >> %envsvc_log% echo [%DATE% %TIME%] Failed to stop service: %envsvc_service%
    )
    goto :eof
    
    :help
    if    {%1} == {}       goto :usage
    if    {%1} == {?}      goto :usage
    if    {%1} == {-?}     goto :usage
    if    {%1} == {/?}     goto :usage
    if /i {%1} == {-h}     goto :usage
    if /i {%1} == {help}   goto :usage
    if /i {%1} == {/help}  goto :usage
    if /i {%1} == {-help}  goto :usage
    if /i {%1} == {--help} goto :usage
    goto :begin
    
    :usage
    echo Starts, stops, or restarts a service
    echo.
    echo   envsvc [/stop ^| /start] service [[drive:][path]filename]
    echo.
    echo   Restart is the default action when none specified
    echo     /start          Starts a service
    echo     /stop           Stops a service
    echo.
    echo   Use double quotes ("") around names with spaces
    echo     service         The service name to start, stop, or restart
    echo.
    echo   Standard output is the default when none specified
    echo     [drive:][path][filename]
    echo                     The file to use for logging
    echo.
    goto :eof
    ibNoCommentsInTheCode=Bad
     
  2. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    that is some massive useless script.
     
  3. dorkultra

    dorkultra OT's resident crohns dude OT Supporter

    Joined:
    Oct 14, 2005
    Messages:
    22,737
    Likes Received:
    27
    Location:
    yinzer / nilbog, trollhio
    defrag c: -f -v
     
  4. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Lol - I gotta agree. The whole point of a batch script IMHO is to make it lean and mean, not an exercise in documentation and making the script act as if it should respond to every possible combination of help.
     
  5. EvilSS

    EvilSS New Member

    Joined:
    Jun 11, 2003
    Messages:
    5,104
    Likes Received:
    0
    Location:
    STL
    While I use batch files quite a bit to, well, batch together a bunch of commands that I may use over and over, anything that requires any logic or complexity I just use vbscript to do. It's usually easier than trying to get a batchfile to jump through hoops it was never really suited to jump through using arcane and often very obtuse commands.

    That said, you (OP) do realize that service state changes are already logged into the system event log, right?
     
  6. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    There are a few batch files I've created that are extremely powerful in only a few lines - I fell in love with the for command a few years ago. I can get some stuff done with it that would take multiple lines of code in vb to accomplish.

    In another words, it really depends on what needs to be done.
     
  7. CodeX

    CodeX Guest

    pure lulz...

    as has already been said that is pointless... you accomplish the same from admin tools -> services / event viewer

    Learn a real language, like C. With C and a little help from the MSDN you could do the same thing in less code and turn it into a standalone executable... and yes even run it from task scheduler, which is a joke to begin with
     
  8. ez4me2c3d

    ez4me2c3d Cold Member

    Joined:
    Sep 19, 2003
    Messages:
    1,836
    Likes Received:
    0
    Location:
    Minneapolis, MN
    I don't understand why so many OTers come into threads with tunnel vision.

    The point of this post was not to pick apart the batch file I posted, but rather:
    i.e., not the usefulness of the batch file I posted, but the usefulness of any batch file. So look at the techniques in the script not the script itself


    Is it so unconceivable that another person's needs for a batch process are not the same as your's? How do you know I don't need the logs of this service correlated into one text file, and formatted a certain way so that I may run the data through another script? I bet you can't do that with eventvwr.msc.

    Looks like one person still agrees that there is some usefulness left in batch files
     
    Last edited: Mar 4, 2008
  9. ez4me2c3d

    ez4me2c3d Cold Member

    Joined:
    Sep 19, 2003
    Messages:
    1,836
    Likes Received:
    0
    Location:
    Minneapolis, MN
    Are you serious? Have you ever administered a windows machine before? Please do tell me how you restart and log a service twice a day/every day without using any scripting or a scheduled task.
     
  10. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    Batch files are ok but VBScript/JScript shell scripting is much more powerful in every way, so I tend to only use batch files for really really simple light stuff.
     
  11. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,441
    Likes Received:
    12
    haha, i love how this thread, where its incentive was to be helpful to others, turned into an absolute bashing thread thanks to the resident faggot in this sub-forum. mods, why in the hell is that idiot not banned. The fatass has generating a constant aurora of negativity with every thread the fatass touches.

    wake the fuck up you mods. jesus fucking christ.
     
  12. retorq

    retorq What up bitch??

    Joined:
    Dec 14, 2006
    Messages:
    6,061
    Likes Received:
    0
    Location:
    Mohave Desert
    Forget it, I'm not posting my batch files now.
     
  13. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Well not to defend Jolly (cuz well that just gives me the shivers), but if the exercise was to demonstrate tricks or how powerful batch can be, I think it falls flat. Examine the code - is there anything in there that is ground breaking? If he didn't comment the code, could you follow it?

    On the other hand, if for some reason you wanted to rename every mp3 in a folder and its subdirectories to a WMA, you can do this in one line:

    for /r "c:\my music" %i in (*.mp3) do ren "%i" "%~ni.wma"

    That to me is pretty cool.
     
  14. crontab

    crontab (uid = 0)

    Joined:
    Nov 14, 2000
    Messages:
    23,441
    Likes Received:
    12
    Bingo. That is all you need in a reply to this type of thread. The original post didn't show anything revolutionary to you scripting elitists. It may have been useful to other noobs.

    Why not post some of your own code/tips like you just did instead of the faggotized bashing that started at the very first reply?

    "Here's a better way to restart services in vb"

    "here's a different way to do it in perl"

    My point here has nothing to do with the thread topic. Just pointing out that jolly is a faggot in almost every thread (even ones that was trying to be helpful especially this one ) and needs some time off at on the treadmill.
     
  15. retorq

    retorq What up bitch??

    Joined:
    Dec 14, 2006
    Messages:
    6,061
    Likes Received:
    0
    Location:
    Mohave Desert
    Pics of Jolly?! Is he really that fat??
     
  16. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    I think what most people's points are is that using a scripting language like VBScript/JScript you can maniuplate the registry, WMI, etc. It's a fully-fledged language with all the constructs, and has much better tools and documentation to go with it.

    So while the batch file used to be cool and all, nowadays the really cool stuff I think is probably done using windows shell scripting. My friend's job pretty much involves purely this.

    I have a couple of batch files that will restart/stop/start all my development services in one go which is useful but not exactly interesting for anyone else.
     
  17. Doomsday

    Doomsday XXX

    Joined:
    Mar 14, 2000
    Messages:
    14,902
    Likes Received:
    0
    Location:
    Minnesota
  18. ez4me2c3d

    ez4me2c3d Cold Member

    Joined:
    Sep 19, 2003
    Messages:
    1,836
    Likes Received:
    0
    Location:
    Minneapolis, MN
  19. ez4me2c3d

    ez4me2c3d Cold Member

    Joined:
    Sep 19, 2003
    Messages:
    1,836
    Likes Received:
    0
    Location:
    Minneapolis, MN
    THANK YOU!!! :bowdown:
     
  20. ez4me2c3d

    ez4me2c3d Cold Member

    Joined:
    Sep 19, 2003
    Messages:
    1,836
    Likes Received:
    0
    Location:
    Minneapolis, MN
    Word, there we go, that is sweet. Thanks for sharing.
     
  21. ez4me2c3d

    ez4me2c3d Cold Member

    Joined:
    Sep 19, 2003
    Messages:
    1,836
    Likes Received:
    0
    Location:
    Minneapolis, MN
    Why can't you see that the thread title says "batch files", and not "scripting solutions". I specifically wanted this thread to be about batch files.

    Think of it like this...

    The PS3 and XBox 360 are dominant in the video game scene right now, right?
    But don't you think there are some people who still like the nostalgia of 8 bit games?

    People who have a real passion for something, computer automation in this case, wouldn't dismiss its history just because it's superseded by something superior.
     
  22. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    oh, wah, wah, wah, p07r0457 pointed out how stupid my batch file is, wah, wah, wah... That's like something you have TOTAL control over... Now lets call him fat when he isn't even close to being the biggest guy here... And can probably out-run most of your skinny asses... Plus it has nothing to do with computers. So great job trying to shift the focus from your crappy script, to something that's not relevant. Just do yourself a favor and delete your thread.
     
  23. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    Horrible analogy. A video came, for all intents and purposes, is not a productivity tool. It's actually the opposite. A video game is designed to waste as much of your time as possible. So just like a movie, it doesn't matter if you like new or old...

    Scripts are designed to make life easier/quicker. So choosing to do things the long and combersome way is actually counter-intuitive to the intent of scripts.

    Everyone that has an unnatural love for "batch" files also has an unnatural love for cobol, perl, python, and numerous other shitty languages that shouldn't be used for all teh crap that people force upon them. They also generally like to still run Windows NT or run linux "because it's not MS".
     
  24. whup

    whup I wish you had children and.. so that I could step

    Joined:
    Feb 12, 2007
    Messages:
    1,603
    Likes Received:
    0
    I'm not dismissing the history. I have (nostalgic) fond memories for batch files. But nowadays I don't really write batch files, and if I need to do something complex I'll use VBScript. So I have no worthwhile batchfiles to share.

    Continue posting batch files if you want though, I'd still be interested in seeing what people do with them.

    I think it's quite a lost art now; no thanks to there being stuff all documentation now.

    I do find it ironic that a lot of people sneer at Windows GUI lean towards administration, when it turns out you can still script nigh on everything.
     
  25. FusionZ06

    FusionZ06 /\__/\__/\__0>

    Joined:
    Apr 10, 2004
    Messages:
    86,918
    Likes Received:
    0
    Location:
    Sunshine State
    login.vbs :o
     

Share This Page