How to create a batch file to run cmd as administrator

前端 未结 12 2191
一个人的身影
一个人的身影 2020-12-04 19:43

I need to run a batch file which needs to register a DLL. The DLL registration is failing because the Batch file is not starting the command prompt as \"administrator\".

12条回答
  •  离开以前
    2020-12-04 20:24

    This Works for me`in Windows 7 to 10 with parameters and also kick starting app or file from any where(including browser) and also accessing file from anywhere,Replace (YOUR BATCH SCRIPT HERE anchor) with your code ,This solution May Help :)

         @echo off
    
         call :isAdmin
    
         if %errorlevel% == 0 (
            goto :run
         ) else (
            echo Requesting administrative privileges...
            goto :UACPrompt
         )
    
         exit /b
    
         :isAdmin
            fsutil dirty query %systemdrive% >nul
         exit /b
    
         :run
          
         exit /b
    
         :UACPrompt
           echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
           echo UAC.ShellExecute "cmd.exe", "/c %~s0 %~1", "", "runas", 1 >> "%temp%\getadmin.vbs"
    
           "%temp%\getadmin.vbs"
           del "%temp%\getadmin.vbs"
          exit /B`
    

提交回复
热议问题