Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 6 down vote accepted

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

share|improve this answer
    
It worked. Thanks. For other people, I still wait for a solution to the original problem (solving the problem without a shortcut). –  Altar Nov 9 '11 at 11:30

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.