5

I need to stop some services so I made a cmd file but it doesn't work because it needs to run as admin. When I right click on the file and choose Properties, I see that "run this program as an administrator" is disabled. Why? How do I turn it on?

The UAC is enabled (but set not to dim the screen) and for other programs (exe files) that box is enabled.

3 Answers 3

10

As a workaround you can try this.

Create a shortcut to the batch file
Right-click on the shortcut and select properties
(Ignore the option on the compatability tab which is still disabled)
Select the Shortcut tab
Click on Advanced
Select 'Run As administrator'
Click on Ok

4
  • It worked. Thanks. For other people, I still wait for a solution to the original problem (solving the problem without a shortcut).
    – IceCold
    Nov 9, 2011 at 11:30
  • My shortcut also has "run as admin" disabled. This is true whether UAC is enabled or disabled. This is for a Visual Studio *.sln file. Other apps can be run as admin. At this time I don't know what affects some apps but not others. This is on Windows 10. Any ideas? I guess I'll ask a new question...
    – moodboom
    Oct 1, 2015 at 14:11
  • 1
    I don't think you get the 'run as admin' option on files, just programs. In other words you get the option on excel.exe but not a particular xls file. Similarly you will get the option on devenv.exe, but not on the sln file. You would need to create a shortcut to devenv.exe and add your solution as a parameter and then you should be able to set set the 'run as admin' option on this shortcut.
    – sgmoore
    Oct 1, 2015 at 16:15
  • Strangely, this answer is exactly the problem. Doing exactly this, "Run as Administrator" is disabled
    – PandaWood
    Mar 30, 2016 at 2:49
1

I have found a very useful batch file here:

http://jagaroth.livejournal.com/63875.html

I quote the CMD file you will need:

@ECHO OFF

REM Changing working folder back to current directory
%~d0
CD %~dp0
REM Folder changed

REM Check first if Windows XP
for /f "tokens=3*" %%i IN ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName ^| Find "ProductName"') DO set vers=%%i %%j 
echo %vers% | find "XP" > nul
if %ERRORLEVEL% == 0 goto ver_xp

REM Ask for admin access
if exist "admincheckOK.txt" goto adminOK1
del /Q admincheckOK.vbs
ECHO.
ECHO. Please wait...
echo.Set objShell = CreateObject("Shell.Application") > admincheckOK.vbs
echo.Set FSO = CreateObject("Scripting.FileSystemObject") >> admincheckOK.vbs
echo.strPath = FSO.GetParentFolderName (WScript.ScriptFullName) >> admincheckOK.vbs
echo.If FSO.FileExists(%0) Then >> admincheckOK.vbs
echo. Dim oShell >> admincheckOK.vbs
echo. Set oShell = WScript.CreateObject ("WScript.Shell") >> admincheckOK.vbs
echo. oShell.run "cmd.exe /c echo admincheckOK > admincheckOK.txt" >> admincheckOK.vbs
echo. Set oShell = Nothing >> admincheckOK.vbs
echo. objShell.ShellExecute "cmd.exe", " /c " ^& %0 ^& " ", "", "runas", 1 >> admincheckOK.vbs
echo.Else >> admincheckOK.vbs
echo. MsgBox "Script file not found" >> admincheckOK.vbs
echo.End If >> admincheckOK.vbs
cscript //B admincheckOK.vbs
goto timeend
:adminOK1
del /Q admincheckOK.txt
del /Q admincheckOK.vbs
:ver_xp
REM Admin Access allowed
REM CMD CODE TO RUN AS ADMIN HERE!!
REM Following statement required if Admin access denied
:timeend
del /Q admincheckOK.vbs

After the REM CMD CODE TO RUN AS ADMIN HERE!! you will have admin access. It uses a lot of trickery to achieve this.

It effectively creates a .vbs VBScript file. VBScript can trigger UAC. It will also create an admincheckOK.txt that tells the batch file that it is in admin mode right now when it is run the next time (which happens right after that using objShell.ShellExecute)

Unlike the variant with the link file you will only need one file in the directory most of the time. For a remote second during the execution of the batch file there will be 3 files inside, but they are deleted afterwards.

0

Just try to take ownership of the file to yourself by right-click on file
Select Security-and then you can use Edit or Advance settings to change the permissions for the file. I think this would help you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .