d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Simple Batch Script > Need Halp
Add Reply New Topic New Poll
Member
Posts: 10,134
Joined: Aug 3 2007
Gold: 1,375.00
Feb 19 2013 03:36am
I can't run my installation files from our server, so im trying to copy the files (succesfully).

Now i want the batch file to run copied program as administrator, automaticly.

The command cannot use specific information such as username, pc name or whatever, it should be able to run from any pc on our domain.

Pls halp.
Member
Posts: 10,134
Joined: Aug 3 2007
Gold: 1,375.00
Feb 19 2013 03:41am
Found this:

@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"
set params = %*:"=""
echo UAC.ShellExecute "%~s0", "%params%", "", "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"
:--------------------------------------

<YOUR BATCH SCRIPT HERE>
--

Works, but not with my script.
Member
Posts: 4,560
Joined: Jul 15 2012
Gold: 110.01
Warn: 30%
Feb 19 2013 12:17pm
dat bat nill, dat bat
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Feb 19 2013 02:15pm
Batch2.bat would be the application/batchfile you want to run as admin

Batch1.bat
Code
powershell Start-Process Batch2.bat -Verb RunAs


although I don't think this quite does what you want


--------------------------------
/e Oh I found something someone else wrote that looks similar to what you have, maybe it will help:


from:
http://stackoverflow.com/questions/7044985/how-can-i-auto-elevate-my-batch-file-so-that-it-requests-from-uac-admin-rights
Code
:::::::::::::::::::::::::::::::::::::::::
:: Automatically check & get admin rights
:::::::::::::::::::::::::::::::::::::::::
@echo off
CLS
ECHO.
ECHO =============================
ECHO Running Admin shell
ECHO =============================

:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )

:getPrivileges
if '%1'=='ELEV' (shift & goto gotPrivileges)  
ECHO.
ECHO **************************************
ECHO Invoking UAC for Privilege Escalation
ECHO **************************************

setlocal DisableDelayedExpansion
set "batchPath=%~0"
setlocal EnableDelayedExpansion
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
ECHO UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs"
"%temp%\OEgetPrivileges.vbs"
exit /B

:gotPrivileges
::::::::::::::::::::::::::::
:START
::::::::::::::::::::::::::::
setlocal & pushd .

REM Run shell as admin (example) - put here code as you like
cmd /k


This post was edited by Azrad on Feb 19 2013 02:25pm
Member
Posts: 10,134
Joined: Aug 3 2007
Gold: 1,375.00
Feb 20 2013 12:55am
Quote (Bossolv @ Feb 19 2013 07:17pm)
dat bat nill, dat bat


pls.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll