0

I created a batch file which stops a service,then stops a process and then starts the service it stopped.

When I execute the batch file, it says "access denied". I cannot figure out why it says access denied because I am an Administrator. I searched everywhere for a solution to this with no luck.

Here are my command lines within the batch file:

net stop uvnc_service
taskkill /f /im winvnc.exe
net start uvnc_service

Note: When I right click on it, I can say "run as administrator" which then works, but I created a task in task scheduler which executes the batch file every 5 minutes and I cant right click and say "run as administrator" every 5 minutes.

Also in the properties of the batch file under the compatibility tab, "run as administrator is greyed out so I cant check it.

How can I automatically run the batch file as administrator every 5 minutes?

Is there maybe a command line I can insert into my batch file that runs it as administrator every time?

Kruug
  • 5,250
Stagger
  • 75

3 Answers3

1

Might this help you? I assume you already have the file running every 5 minutes and just need some method of adding the right admin rights.

https://stackoverflow.com/questions/18755553/automatically-running-a-batch-file-as-an-administrator

EDIT: You should also be able to set "run with higher privileges" in the scheduler which might solve it for you.

1

A couple of suggestions:

  1. Have you tried the MakeMeAdmin.cmd script by Aaron Margosis? A great way to learn how to re-start your script with elevated privileges.
  2. How about Matt's solution found at StackOverflow?

Hope that helps somewhat...

JSanchez
  • 1,712
0

Here is what it says in CMD after i execute it:

C:\Users\VANTO.JACQUES\Documents>runas /savecred /profile /user:Administrator VN C Restrat.bat RUNAS USAGE:

RUNAS [ [/noprofile | /profile] [/env] [/savecred | /netonly] ] /user: program

RUNAS [ [/noprofile | /profile] [/env] [/savecred] ] /smartcard [/user:] program

RUNAS /trustlevel: program

/noprofile specifies that the user's profile should not be loaded. This causes the application to load more quickly, but can cause some applications to malfunction. /profile specifies that the user's profile should be loaded. This is the default. /env to use current environment instead of user's. /netonly use if the credentials specified are for remote access only. /savecred to use credentials previously saved by the user. This option is not available on Windows 7 Home or Windows 7 Starter Editions and will be ignored. /smartcard use if the credentials are to be supplied from a smartcard. /user should be in form USER@DOMAIN or DOMAIN\USER /showtrustlevels displays the trust levels that can be used as arguments to /trustlevel. /trustlevel should be one of levels enumerated in /showtrustlevels. program command line for EXE. See below for examples

Examples:

runas /noprofile /user:mymachine\administrator cmd runas /profile /env /user:mydomain\admin "mmc %windir%\system32\dsa.msc" runas /env /user:user@domain.microsoft.com "notepad \"my file.txt\""

NOTE: Enter user's password only when prompted. NOTE: /profile is not compatible with /netonly. NOTE: /savecred is not compatible with /smartcard.

C:\Users\VANTO.JACQUES\Documents>pause Press any key to continue . . .

Stagger
  • 75