Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


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

15 Nov 2014   #1
dav1129

Windows XP SP3
 
 
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?


My System SpecsSystem Spec
.
15 Nov 2014   #2
rustberger

Windows 7 Ultimate x64 sp1
 
 

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 System SpecsSystem Spec
15 Nov 2014   #3
dav1129

Windows XP SP3
 
 

Quote   Quote: Originally Posted by rustberger View Post
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 System SpecsSystem Spec
.

15 Nov 2014   #4
Alejandro85

Windows 7 Ultimate x64
 
 

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 System SpecsSystem Spec
15 Nov 2014   #5
dav1129

Windows XP SP3
 
 

Quote   Quote: Originally Posted by Alejandro85 View Post
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?
My System SpecsSystem Spec
16 Nov 2014   #6
Tookeri

Windows 7 Pro 32
 
 

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 System SpecsSystem Spec
29 Nov 2014   #7
dav1129

Windows XP SP3
 
 

Quote   Quote: Originally Posted by Tookeri View Post
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.

Quote   Quote: Originally Posted by Tookeri View Post
Have you tried with just this?
SET TODAY=%date%
Doesn't work or make a difference.

Quote   Quote: Originally Posted by Tookeri View Post
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 System SpecsSystem Spec
30 Nov 2014   #8
Tookeri

Windows 7 Pro 32
 
 

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 System SpecsSystem Spec
30 Nov 2014   #9
dav1129

Windows XP SP3
 
 

Quote   Quote: Originally Posted by Tookeri View Post
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.
My System SpecsSystem Spec
30 Nov 2014   #10
Tookeri

Windows 7 Pro 32
 
 

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 System SpecsSystem Spec
Reply

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




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
How to run a batch , .bat, flle as administrator
I run a batch file from the Windows scheduler and get an error 5, 'access denied'. If i run the batch file as administrator I have access and everything is OK except I must answer the UAC popup. The question is "How can I run the batch file from the scheduler with admin privileges and NOT have to...
General Discussion
Execute Program in Batch File As Administrator (Or Other Solution)
We use a program called TFC.exe (Temp File Cleaner - addpcs.com) to wipe all sorts of temp files off a computer on a monthly basis. The older version was a standalone .exe that users used to execute from a a folder on a server. The newer version is actually installed on each user's PC. If...
General Discussion
shutdown in batch file requires Administrator
Hi all, I've been using GFI Backup 2009 for backups for a while, it does everything I want, and sends email reports after backup is complete. One of its features is to shutdown the computer after a backup, this rarley works, as it wont shutdown if a program is already running, including GFI...
General Discussion
Batch File on USB fails when Ran As Administrator
I am new to this site so please excuse any lack of etiquette I may show. I have recently built a .bat files to perform a large number of configuration changes needed for a Win7 or Win8 workstation to function properly on my network. The .bat file obviously needs to be ran with elevated...
Software
How to always run batch file as administrator?
I've made a batch file, but i don't know how to make it to always run as administartor. In .bat's file properties the option "always run as administartor" is grayed out. I have to right click it and then choose "run as administartor" from context menu. But i don't want to do it every time because...
General Discussion
batch files - run as administrator
I am a software developer (dot net). Until recently I did all my work in the XP environment. I developed a utility library that goes into the global assembly cache. In the XP world this was easy. I write some .bat files that called the gacutil.exe and passed it the appropriate parameters. ...
General Discussion


Our Sites

Site Links

About Us

Find 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 14:51.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App