12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

バッチファイルからUAC昇格ダイアログを表示する

Last updated at Posted at 2015-03-21

バッチファイルからのUAC昇格ダイアログ表示する方法は、インターネット上で公開されているものがいくつかあるが、一時ファイルを作成せず、かつ1ファイルのみで実現しているものがないため、作成した。stackoverflowTechNet Blogsで公開されている方法を元にしている。純粋にバッチファイルのみで実現する方法はないため、trash-area.comで公開されている方法でWSHと組み合わせて実装した。

elevate.bat
@set @temp=0/*
@echo off

:: Check for Mandatory Label\High Mandatory Level 
whoami /groups | find "S-1-16-12288" > nul
if "%errorlevel%"=="0" ( 
    echo Running as elevated user.  Continuing script. 
) else ( 
    echo Not running as elevated user. 
    echo Relaunching Elevated: "%~dpnx0" %*

    if '%1'=='ELEV' (
        shift
    ) else (
        cscript.exe //e:jscript //nologo "%~f0" "%~0"
        exit /B
    )
)

:: Continue script here

rem Write your own code here  ==>
rem Run shell as admin (example)
cmd /k
rem Write your own code here  <==

goto :EOF
*/
var UAC = new ActiveXObject("Shell.Application");
UAC.ShellExecute(WScript.Arguments(0), "ELEV", "", "runas", 1);

#参考文献

  1. windows - How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required? - Stack Overflow
  2. Elevation PowerToys for Windows - Site Home - TechNet Blogs
  3. WindowsXP標準機能だけでスリープ(コマンド)の実装 | trash-area.com
12
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?