如何使用批处理文件中的Runas命令运行批处理文件

时间:2022-06-08 04:22:54

This is our batch file which we have this code but its not running the run.bat file. Giving Error : is not recognized as internal or external command

这是我们的批处理文件,我们有这个代码,但它没有运行run.bat文件。给出错误:不被识别为内部或外部命令

@echo off
SET Identity=%userdomain%\%username%
CALL :ICACLS "%Identity%"
SET mypath=%~dp0
echo %mypath:~0,-1%
runas /noprofile /user:%Identity% "cmd /K %mypath%\run.bat"

1 个解决方案

#1


1  

Echo Soft
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"
 ::your code goes here which needs to be run with admin rights::

#1


1  

Echo Soft
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"
 ::your code goes here which needs to be run with admin rights::