6

I have a .bat file that cannot allow me to set it to run as admin as required by going to the Properties box and check for Privilege checkbox.

But mine is disabled as below snapshot.

What can I do to get it enabled?

enter image description here

1

2 Answers 2

3

It doesn't work because it's a batch file.

I like to use the following approach to get around this limitation:

@if (1==1) @if(1==0) @ELSE
@echo off&SETLOCAL ENABLEEXTENSIONS
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"||(
    cscript //E:JScript //nologo "%~f0"
    @goto :EOF
)
echo.Setting IP configuration to DHCP...
netsh interface ipv4 set address "Local Area Connection" dhcp
echo.Setting DNS configuration to DHCP...
netsh interface ipv4 set dnsservers "Local Area Connection" dhcp
pause
@goto :EOF
@end @ELSE
ShA=new ActiveXObject("Shell.Application")
ShA.ShellExecute("cmd.exe","/c \""+WScript.ScriptFullName+"\"","","runas",5);
@end

This would enable DHCP for a network adapter. Should be fairly easy to adjust to your needs.

2

I think I've got the solution for you. You need to turn off UAC and back on again:

How to turn UAC on or off

Open User Account Control Settings by going to Start > Control Panel. In the search box, type "uac" without quotes, and then click Change User Account Control settings.

Do the following:

  1. Turn off UAC - move the slider to the Never notify position, and then click OK. Administrator permission required If you're prompted for an administrator password or confirmation, type the password or provide confirmation. You will need to restart your computer for UAC to be turned off.

  2. Turn on UAC - move the slider to choose when you want to be notified, and then click OK. Administrator permission required If you're prompted for an administrator password or confirmation, type the password or provide confirmation.

Way back I dealt with a similar issue on an .exe file and I recall trying this after some research over here. It solved my problem right away.

You must log in to answer this question.

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