如何请求管理员权限才能打开.exe文件? [关闭]

问题描述 投票:1回答:1

我刚刚用一些快速批处理文件(.exe)命令制作了一个.bat文件...

我在想: 如何在打开.exe文件时强行请求提升权限? (无需右键单击)

batch-file exe
1个回答
1
投票

对于这个,您必须检查批处理文件是否提升,然后运行VBS文件:

@echo off
SetLocal EnableDelayedExpansion

rem Get the file itself name
set filename=%0

rem Check if batch file is elevated or not:
reg query "HKU\S-1-5-19" >nul 2>&1
if %errorlevel%==1 (
  echo.Set UAC = CreateObject^("Shell.Application"^) > "elevated.vbs"
  echo.UAC.ShellExecute "!filename!", "", "", "runas", 1 >> "elevated.vbs"
  "elevated.vbs"
  goto :eof
)
if %errorlevel%==0 goto elevated

:elevated
rem Now, run the exe file (like use 'start' command, or execute it as a command:
yourExecuteableFileInHere.exe  

但上面的代码仍有一些错误。您可能想要修复它(或者可能不是?)

© www.soinside.com 2019 - 2024. All rights reserved.