How do I make this Batch run as Administrator by default?

Page 1 of 3 123 LastLast

  1. Posts : 48
    Windows XP SP3
       #1

    How do I make this Batch run as Administrator by default?


    I haven't looked back since recently and initially reluctantly upgrade from XP to Windows 7.

    Just loving it now. But I have a small BATCH file problem.

    I found and adapted a batch file (see below) to start the VAG parts catalogue program after first resetting the system date but then resetting the system date back.

    This is because the program checks the system date against the last program updates installed. If too much time has elapsed, the program will not be able to progress beyond the splash screen.

    Starting the program is this way is fine for me as it is for personal use and I am interested only in my own vehicle which is old enough now that is not affected by updates except perhaps in the rare instance where parts are deleted or superseded.

    What I would like to know is how to make the BATCH file (shortcut) run as administrator as otherwise the BATCH file cannot change the system date.

    ECHO OFF
    CLS
    :MENU
    ECHO.
    ECHO ....................................... ........
    ECHO PRESS 1 to select your task, or 2 to EXIT.
    ECHO ....................................... ........
    ECHO.
    ECHO 1 - Launch C:\ETKA\PROG\EtStart.exe "C:\ETKA\PROG\ETKA_VW.INI"
    ECHO 2 - Exit
    ECHO.
    SET /P M=Type 1, 2, then press ENTER:
    IF %M%==1 GOTO PROGRAM
    IF %M%==2 GOTO RESETDATE

    :PROGRAM
    FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CURDATE=%DATE%
    COLOR 4f
    echo Setting System date to 01-01-2012
    echo.
    runas /user:Administrator date 01-01-2012
    echo Launching Program........Please Wait
    echo.
    C:\ETKA\PROG\EtStart.exe "C:\ETKA\PROG\ETKA_VW.INI"
    echo Resetting System Date back to Todays Date....Please Wait
    date %CURDATE%

    PS If the script looks complicated such that I should know the answer to my own question, I didn't write it, only adapted it and found that but for needing to run as administrator, it worked.

    Yes as it turns out, once successfully started the programs checks the system date again when loading a VIN data file (which is used to cross check against VIN first). So whilst this BATCH file is slick and works well, is there a way to only change the system date when the program actually exits?
    Last edited by dav1129; 15 Nov 2014 at 02:50.
      My Computer


  2. Posts : 184
    Windows 7 Ultimate x64 sp1
       #2

    Right click on the shortcut and select the 'shortcut' tab (not the compatibility tab), then click Advanced. Here you will find ANOTHER Run as Administrator option that is just for shortcuts.
      My Computer


  3. Posts : 48
    Windows XP SP3
    Thread Starter
       #3

    rustberger said:
    Right click on the shortcut and select the 'shortcut' tab (not the compatibility tab), then click Advanced. Here you will find ANOTHER Run as Administrator option that is just for shortcuts.
    Thanks. Yes I ultimately discovered this myself.

    I still have a problem in that the batch file resets the system date immediately. This is a problem because the program later checks the system date again. So I have found this batch file. But then syntax in the first line seems to be wrong for the date.

    SET TODAY=%date:~4,2%-%date:~7,2%-%date:~10,2%
    REM setting date back to an older date
    DATE 01/01/2012
    start "" C:\ETKA\PROG\EtStart.exe "C:\ETKA\PROG\ETKA_VW.INI"
    REM Changing date back to todays date
    DATE %TODAY%
      My Computer


  4. Posts : 2,464
    Windows 7 Ultimate x64
       #4

    In your first sample use START /W to run the program. It will cause the bat to stop running until the called program ends, so the subsequent lines are warranted to be run after the program has exited.
      My Computer


  5. Posts : 48
    Windows XP SP3
    Thread Starter
       #5

    Alejandro85 said:
    In your first sample use START /W to run the program. It will cause the bat to stop running until the called program ends, so the subsequent lines are warranted to be run after the program has exited.
    Thanks. Tried that but didn't work
    ECHO OFF
    CLS
    :MENU
    ECHO.
    ECHO ....................................... ........
    ECHO PRESS 1 to select your task, or 2 to EXIT.
    ECHO ....................................... ........
    ECHO.
    ECHO 1 - Launch C:\ETKA\PROG\EtStart.exe "C:\ETKA\PROG\ETKA_VW.INI"
    ECHO 2 - Exit
    ECHO.
    SET /P M=Type 1, 2, then press ENTER:
    IF %M%==1 GOTO PROGRAM
    IF %M%==2 GOTO RESETDATE

    :PROGRAM
    FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CURDATE=%DATE%
    COLOR 4f
    echo Setting System date to 01-01-2012
    echo.
    date 01-01-2012
    echo Launching Program........Please Wait
    echo.
    C:\ETKA\PROG\EtStart.exe "C:\ETKA\PROG\ETKA_VW.INI"
    echo Resetting System Date back to Todays Date....Please Wait
    date %CURDATE%
    The script works tests okay but not yet with START /W. Where should I insert it? If I can't get this to work, I need a way to to reset the system date AFTER I close the program. Or the CMD window should at least stay open, and let me manually reset the system date after I close the program. Like this one.
    SET TODAY=%date:~4,2%-%date:~7,2%-%date:~10,2%
    REM setting date back to an older date
    DATE 01/01/2012
    start "" C:\ETKA\PROG\EtStart.exe "C:\ETKA\PROG\ETKA_VW.INI"
    REM Changing date back to todays date
    DATE %TODAY%
    Except ad per this screenshot, there is something wrong it because 'the system cannot accept the date'. If it did maybe it would do what I want?



    If I cannot get the first script to work with START /W, how I can correct this second script to accept the date?
    Last edited by dav1129; 15 Nov 2014 at 20:09.
      My Computer


  6. Posts : 1,049
    Windows 7 Pro 32
       #6

    Hi,

    Alejandro85 meant you should add /W to the line with the start command:
    start /W "" C:\ETKA\PROG\EtStart.exe "C:\ETKA\PROG\ETKA_VW.INI"

    The date problem is this line:
    SET TODAY=%date:~4,2%-%date:~7,2%-%date:~10,2%

    Have you tried with just this?
    SET TODAY=%date%
      My Computer


  7. Posts : 48
    Windows XP SP3
    Thread Starter
       #7

    Tookeri said:
    Alejandro85 meant you should add /W to the line with the start command:
    start /W "" C:\ETKA\PROG\EtStart.exe "C:\ETKA\PROG\ETKA_VW.INI"
    Doesn't work or make a difference.

    Tookeri said:
    Have you tried with just this?
    SET TODAY=%date%
    Doesn't work or make a difference.

    Tookeri said:
    The date problem is this line:
    SET TODAY=%date:~4,2%-%date:~7,2%-%date:~10,2%

    Doesn't work or make a difference.


    Sorry did work but only if run as administrator. is there a way to have a batch file automatically run as administrator and to reset the date after the program is closed?

    This one actually works best except that

    1. You also have to right click and run it as administraton; and
    2. It resets the date too early i.e. the program checks the system date after starting and fails because the system has already been reset.

    So as well as having the batch automatically run as administrator, is there a way to delay resetting the date until after the program closes
      My Computer


  8. Posts : 1,049
    Windows 7 Pro 32
       #8

    Not sure what you mean. I think both these questions have already been answered. Create a shortcut to the batch file and set the properties to run as administrator. Then you'll automatically get a UAC prompt when you run the shortcut, assuming you have UAC enabled.

    I assume EtStart.exe is a Windows application. The start /W in the batch file will cause the batch file to pause and wait until that program closes until it continues processing the rest of the batch file.
    Do this simple test in a command prompt to see how it works. Run the command:
    start notepad
    Notice how the command prompt is ready so you can type a new command even though notepad is running. Close notepad and now run the command:
    start /W notepad
    Notice how the command prompt is in waiting mode which means you can't type a new command until you close notepad.
      My Computer


  9. Posts : 48
    Windows XP SP3
    Thread Starter
       #9

    Tookeri said:
    Not sure what you mean. I think both these questions have already been answered. Create a shortcut to the batch file and set the properties to run as administrator. Then you'll automatically get a UAC prompt when you run the shortcut, assuming you have UAC enabled.

    I assume EtStart.exe is a Windows application. The start /W in the batch file will cause the batch file to pause and wait until that program closes until it continues processing the rest of the batch file.
    Do this simple test in a command prompt to see how it works. Run the command:
    start notepad
    Notice how the command prompt is ready so you can type a new command even though notepad is running. Close notepad and now run the command:
    start /W notepad
    Notice how the command prompt is in waiting mode which means you can't type a new command until you close notepad.
    Yes I guess they have been answered. but the solutions aren't working or I am doing it wrong. Thanks for the port and suggestions. Thanks also for the example with Notepad. That helped explained a lot.

    So I tried interchanging notepad for etstart after pasting a copy of notepad.exe into the directory and found it worked as you say it should. Notepad just opens the configuration file and the batch file resets the system date as it should when notepad is closed.

    But with etstart restore the batch file resets the system date immediately after starting the program not after it closes. The problem maybe is with "C:\ETKA\PROG\ETKA_VW.INI". But with this reference to a configuration file removed the program cannot start.
    Code:
    ECHO OFF
    CLS
    :MENU
    ECHO.
    ECHO ....................................... ........
    ECHO PRESS 1 to select your task, or 2 to EXIT.
    ECHO ....................................... ........
    ECHO.
    ECHO 1 - Launch C:\ETKA\PROG\EtStart.exe "C:\ETKA\PROG\ETKA_VW.INI"
    ECHO 2 - Exit
    ECHO.
    SET /P M=Type 1, 2, then press ENTER:
    IF %M%==1 GOTO PROGRAM
    IF %M%==2 GOTO RESETDATE
    
    :PROGRAM
    FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CURDATE=%DATE%
    COLOR 4f
    echo Setting System date to 01-01-2012
    echo.
    date 01-01-2012
    echo Launching Program........Please Wait
    echo.
     START / W C:\ETKA\PROG\EtStart.exe "C:\ETKA\PROG\ETKA_VW.INI"
    echo Resetting System Date back to Todays Date....Please Wait
    date %CURDATE%
    Also creating and changing a shortcut to run automatically isn't working because for some reason the option is greyed out on compatibility tab.
    Last edited by dav1129; 30 Nov 2014 at 17:19.
      My Computer


  10. Posts : 1,049
    Windows 7 Pro 32
       #10

    Your example has a space between / and W which won't work. It should be:
    start /W C:\ETKA\PROG\EtStart.exe "C:\ETKA\PROG\ETKA_VW.INI"

    Because you want the program EtStart.exe to run with an old system date, right? And when that program is closed you want to reset the date to todays date?

    An alternative to inserting start /W is to insert a pause after launching EtStart.exe
    Code:
    C:\ETKA\PROG\EtStart.exe "C:\ETKA\PROG\ETKA_VW.INI"
    echo When EtStart.exe has been closed, press any key to Reset System Date back to Todays Date....
    pause
    date %CURDATE%
    Then it would be up to you know when EtStart.exe has been closed, and you would have to "press any key" in the command window so the batch continues and resets the system date. But the start /W is better because it automatically keeps track of when EtStart.exe is closed.
    Or you could use both start /W and the pause.

    As for the shortcut and administrator, go to tab "Shortcut" in the properties instead of Compatibility, click button "Advanced", then check the "Run as administrator" checkbox.
      My Computer


 
Page 1 of 3 123 LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 21:11.
Find Us