0

特定のコマンドを実行するバッチを作成しました。コードは次のようになります。

cd  D:\projects\Project Stress Test\signed one\com0com\x64
setupc
pause

私が欲しいのはsetupc、管理者としてファイルを実行することですか?

runas /user:<Name>\administratorコマンドを試しましたが、機能しませんでした。

それを行う簡単な方法はありますか?

4

1 に答える 1

3

スクリプト全体を管理者レベルで実行することができます。これが私のスクリプトで使用するバッチ関数です。

@echo off
call :Admin xReturn true 1
echo.%xReturn%
goto End

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:Admin <Return> [Needed] [Success]
:: Check for Administrator privileges and request privileges if needed.
:: NOTE: This will restart the script with Admin privs if Needed is set to true.
:::: Usage: call :Admin xReturn true
:: Return success value, if user is Admin. Default `true` if Success not set.
setlocal
set xVBUAC=%Temp%\AdminUAC.vbs
set xSuccess=true
if not "%~3"=="" set xSuccess=%~3

:: Check for Access
::net session >nul 2>&1
>nul 2>&1 "%SystemRoot%\system32\cacls.exe" "%SystemRoot%\system32\config\system"
if %ErrorLevel% EQU 0 set xAdmin=%xSuccess%

:: Execute UAC
if /i not "%xAdmin%"=="%xSuccess%" if not "%~2"=="" if /i "%~2"=="true" (
  echo Set UAC = CreateObject^("Shell.Application"^) > "%xVBUAC%"
    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%xVBUAC%"
    if exist "%xVBUAC%" (
        "%xVBUAC%"
        rem if %ErrorLevel% EQU 5 echo Access Denied. Launching UAC.
        del "%xVBUAC%"
    )
)
endlocal & if not "%~1"=="" set "%~1=%xAdmin%"
goto :eof

:End
于 2012-12-13T22:22:16.197 に答える