Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Not only check but GETTING admin rights automatically<br> aka Automatic UAC for Win 7/8/8.1 ff.</strong>: The following is a really cool one with one more feature: This batch snippet does not only check for admin rights, but gets them automatically! (and tests before, if living on an UAC capable OS.)</p> <p>With this trick you don´t need longer to right klick on your batch file "with admin rights". If you have forgotten, to start it with elevated rights, UAC comes up automatically! Moreoever, at first it is tested, if the OS needs/provides UAC, so it behaves correct e.g. for Win 2000/XP until Win 8.1- tested.</p> <pre><code>@echo off REM Quick test for Windows generation: UAC aware or not ; all OS before NT4 ignored for simplicity SET NewOSWith_UAC=YES VER | FINDSTR /IL "5." &gt; NUL IF %ERRORLEVEL% == 0 SET NewOSWith_UAC=NO VER | FINDSTR /IL "4." &gt; NUL IF %ERRORLEVEL% == 0 SET NewOSWith_UAC=NO REM Test if Admin CALL NET SESSION &gt;nul 2&gt;&amp;1 IF NOT %ERRORLEVEL% == 0 ( if /i "%NewOSWith_UAC%"=="YES" ( rem Start batch again with UAC echo Set UAC = CreateObject^("Shell.Application"^) &gt; "%temp%\getadmin.vbs" echo UAC.ShellExecute "%~s0", "", "", "runas", 1 &gt;&gt; "%temp%\getadmin.vbs" "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" exit /B ) rem Program will now start again automatically with admin rights! rem pause goto :eof ) </code></pre> <p>The snippet merges some good batch patterns together, especially (1) the admin test in this thread by Ben Hooper and (2) the UAC activation read on BatchGotAdmin and cited on the batch site by robvanderwoude (respect). (3) For the OS identificaton by "VER | FINDSTR pattern" I just don't find the reference.)</p> <p>(Concerning some very minor restrictions, when "NET SESSION" do not work as mentioned in another answer- feel free to insert another of those commands. For me running in Windows safe mode or special standard services down and such are not an important use cases- for some admins maybe they are.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload