Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Help with a batch file...

  • 10-12-2013 10:46pm
    #1
    Registered Users Posts: 532 ✭✭✭


    All

    Heres what Im trying to achieve.

    I have an app that is no longer available but there is some code in it that requires that I set the date back to 2010 before opening it.
    Once its open I can reset the date.

    This Is the batch file I got so far..

    Date 10/12/2010 /set /y

    cd\
    CD "C:\Program Files\xxx\yyyy"
    zzzzzz.exe

    net time /set /yes


    The date command works fine.
    The program opens ok but the batch file doesn't continue until I close the application.
    Once I close the application the net time command runs but I want it to run as soon as zzzzzz.exe runs.
    Id also like the batch file to run minimised and to close totally once the zzzzzz.exe runs and the net time has run.


Comments

  • Registered Users, Registered Users 2 Posts: 1,456 ✭✭✭FSL


    superuser.com/questions/103937/


  • Moderators, Arts Moderators, Regional Abroad Moderators Posts: 11,086 Mod ✭✭✭✭Fysh


    Instead of
    cd\
    CD "C:\Program Files\xxx\yyyy"
    zzzzzz.exe
    
    try
    cd  "C:\Program Files\xxx\yyyy"
    start zzzzzz.exe
    

    You may be able to shorten it to
    start "C:\Program Files\xxx\yyyy\zzzzzz.exe"
    


  • Registered Users Posts: 532 ✭✭✭dfdream


    All works well 90% there except 2 things.
    The first line causes a second dos box to open.
    Secondly I want batch file to run with the dos box minimised.


    start date 10/10/2010 /yes

    ping 127.0.0.1 -n 1

    c:\

    cd "C:\Program Files\Paint.NET\"

    start PaintDotNet.exe

    ping 127.0.0.1 -n 2

    start net time /set /yes




  • Moderators, Arts Moderators, Regional Abroad Moderators Posts: 11,086 Mod ✭✭✭✭Fysh


    dfdream wrote: »
    All works well 90% there except 2 things.
    The first line causes a second dos box to open.
    Secondly I want batch file to run with the dos box minimised.


    start date 10/10/2010 /yes

    ping 127.0.0.1 -n 1

    c:\

    cd "C:\Program Files\Paint.NET\"

    start PaintDotNet.exe

    ping 127.0.0.1 -n 2

    start net time /set /yes



    OK, try this:
    @echo off
    ::
    start date 10/10/2010 /yes >nul 2>&1
    ::
    ping 127.0.0.1 -n 1 >nul 2>&1
    ::
    cd "C:\Program Files\Paint.NET\"
    ::
    start PaintDotNet.exe
    ::
    ping 127.0.0.1 -n 2 >nul 2>&1
    ::
    start net time /set /yes >nul 2>&1
    exit
    

    @Echo off turns off outputting commands to the terminal window. It's useful to ensure that you only get the outputs you want, though for debugging purposes it can be useful to turn it off.

    The :: is a less distracting equivalent of REM, and causes anything after them on the same line to be ignored - you can use them to space out your commands for easier debugging. You can also use them to put in comments if you have any particularly tricky operations; this is invaluable if you need to come back months later to make a change.

    The >nul 2>&1 suffix basically redirects the output of that command to a null device, preventing it from triggering output. Adding "2>&1" afterwards merely ensures that this catches everything, as some outputs can get past the >nul redirection. (Don't ask me why).

    Using exit at the end makes sure that the batch file terminates properly, which allows the window to close properly.

    The best bet for making the batch file run minimised is to create a shortcut to it (right-click, select Send to > Desktop) and then open the properties for the shortcut. On the Shortcut tab, you'll have a dropdown selection labelled "Run" - select "Minimised", apply the change, and when you run the batch file from that shortcut it will be minimised and automatically close itself.

    Alternatively, if you want to run the batch file as a scheduled task you can invoke it with a minimised window using
    start /min %PATHTOBATCHFILE%
    
    or with no window at all using
    start /B %PATHTOBATCHFILE%
    


Advertisement