Fail at set batch with Admin Rights and put the computer at Domain
Posted: 02 Mar 2022 14:05
Sup guys?
I'v some problems cuz I'm trying to execute a batch file in user account in order to do some system configs. Itried to use this lines to give admin power to the executing batch:
:: 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"
The major problem is that the I have to run the batch from a server, so it's start to open multiples windows and don't stop, I even tried this method:
net file 1>nul 2>nul && goto :run || powershell -ex unrestricted -Command "Start-Process -Verb RunAs -FilePath '%comspec%' -ArgumentList '/c %~fnx0 %*'"
goto :run
But, result was same as before...
My second problem is to put a computer at the Domain by Powershell (there iso no net command available). I was tryin this:
powershell.exe -command "& {Add-Computer -DomainName domainhere}"
But it happens to set WORKGROUP, not the Domain field
So, can anyone enlighten this problem?
I'v some problems cuz I'm trying to execute a batch file in user account in order to do some system configs. Itried to use this lines to give admin power to the executing batch:
:: 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"
The major problem is that the I have to run the batch from a server, so it's start to open multiples windows and don't stop, I even tried this method:
net file 1>nul 2>nul && goto :run || powershell -ex unrestricted -Command "Start-Process -Verb RunAs -FilePath '%comspec%' -ArgumentList '/c %~fnx0 %*'"
goto :run
But, result was same as before...
My second problem is to put a computer at the Domain by Powershell (there iso no net command available). I was tryin this:
powershell.exe -command "& {Add-Computer -DomainName domainhere}"
But it happens to set WORKGROUP, not the Domain field
So, can anyone enlighten this problem?