0

Iam trying to synch certain computers to a TimeServer within the network, hence i've written a simple batch script to do the task. I've put into our WDS server. How do i run it in administrator mode. If i open the cmd prompt as administrator it starts with "C:\Windows\System32\" this is where i want to run so how do i achieve it.I dont want to schedule it nor i want to use RMB Click and select "Run as Administrator"

OS: Win 2012R2

My batch file contains.

reg add HKLM\SYSTEM\CurrentControlSet\services\w32time\Config /v MaxNegPhaseCorrection /t REG_DWORD /d 0xffffffff /f
reg add HKLM\SYSTEM\CurrentControlSet\services\w32time\Config /v MaxPosPhaseCorrection /t REG_DWORD /d 0xffffffff /f
w32tm /config /syncfromflags:manual /manualpeerlist:"132.186.XX.XX 132.186.127.XX 132.186.192.XX 132.186.XXX.XX" /largephaseoffset:120000
net stop w32time
net start w32time
w32tm /resync

Thanks in Advance

FloatingKiwi
  • 4,408
  • 1
  • 17
  • 41
Arun Dambal
  • 501
  • 1
  • 4
  • 5

2 Answers2

1

Create a shortcut to the batch file.

Right click on the shortcut, go to properties -> shortcut tab -> advanced.

Tick run as adminstrator

FloatingKiwi
  • 4,408
  • 1
  • 17
  • 41
0

Add this to the start of your batch file:

runas.exe /savecred /user:#administratoraccount# "%windir%/System32/cmd.exe" 

Replace #administratoraccount# with the username of an admin.

The first time you run it, it will ask for the password of that admin account. Enter it. Unless the password is removed from the windows credential locker or the password or username of that admin is changed or the username is disabled, whenever the batch file is run from then on, it will automatically run cmd.exe as administrator.

J03L
  • 314
  • 3
  • 17