0

we are using Windows Server 2008 R2 O/S. We want to execute an script that stops sql server 2008 in the night time (Around 3 am) and copy all the data files.

We want this process to be automatically done, as at 3 am no body would be available to run the batch file as an Administrator.

We've tried using the vbs script on the following link BatchGetAdmin Script

But no success.

We have also tried using runas command, but it is asking for the password, which to us is useless.

How do we achieve this simple task? any ideas?

Here is the script that we are trying to execute but it says "Access denied"

@echo off

:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
    pushd "%CD%"
    CD /D "%~dp0"
:--------------------------------------

net stop SERVER08
net stop SQLEXPRESS
net stop MSOLAP
net stop SQLBrowser
net stop MsDtsServer100
net stop ReportServer
net stop SQLWriter
net stop MSSQLFDLauncher
Shezi
  • 1,352
  • 4
  • 27
  • 51
  • 1
    Any way to elevate a process that runs with the admin token removed (UAC) to a true admin w/o explicit user consent is by definition a bug in UAC. Your scheduler must run already elevated and then the script will inherit the elevated context. – Remus Rusanu Jun 19 '12 at 05:57
  • What do u mean? i didn't understand exactly what you are trying to say? – Shezi Jun 19 '12 at 05:59
  • 2
    He means that when you schedule your job with W2008 scheduler, you have to provide appropriate credentials to run that job. – David Brabant Jun 19 '12 at 06:15
  • I am using syncBack Software to schedule the task. And giving proper credentials. Still no use – Shezi Jun 19 '12 at 06:53
  • Becasue that is not how it works. – TomTom Jun 25 '12 at 04:52

1 Answers1

-1

i think there was some problem with the syncback software from which i was creating the schedule. I used the win2008 scheduler and the scripts works just fine.

Shezi
  • 1,352
  • 4
  • 27
  • 51