0

I have a strange problem here. I am trying to disable UAC via the command line (batch file) and by using REG.EXE (as it doesn't ask for UAC access itself). I have been able to create a shortcut (.lnk) with the target:

C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 0 /f

If I run that as an administrator - there is no problem at all, it changes the registry. If I try to run that command via the command line itself (run as the exact same administrator), I get access denied.

Eventually, I want to move it to a batch script, but that should be no problem once I am able to run it on the command line. Any ideas? Thank you.

naspinski
  • 177
  • 1
  • 4
  • 10

2 Answers2

5

Just because it doesn't prompt for UAC escalation, doesn't mean it doesn't need it.

It needs it.

You'll need to run it from an escalated context - an escalated command prompt, a scheduled task with "run as highest privilege" checked, something. The registry simply cannot be modified without some form of privilege escalation.

Shane Madden
  • 114,520
  • 13
  • 181
  • 251
  • I understand that, but I am running the .lnk as an admin (right click) and it works (even opens a command prompt itself stating success), but when I run it from an admin command prompt, I get access denied. – naspinski Jul 19 '11 at 21:58
  • 1
    Are you right-clicking cmd.exe and running as admin, and does it say `Administrator: Command Prompt` at the top of the window? Saying "run as the exact same administrator" isn't the same as running with UAC escalation privileges - it's completely separate from the privileges of your user. It works just as expected for me: http://i.stack.imgur.com/erKIY.jpg – Shane Madden Jul 19 '11 at 22:16
  • When I am running in the command prompy, it is not 'Administrator: Command Prompt' - I just do a runas cmd. I may see the problem now. Can I get the 'run as administrator' with the .lnk behavior with the command prompt in any way? A runas does not seem to work... – naspinski Jul 20 '11 at 18:25
  • A command prompt session can be escalated by right-clicking cmd.exe and running as admin. – Shane Madden Jul 20 '11 at 18:33
  • is there any way to get that behavior via command line? Without right-clicking? – naspinski Jul 20 '11 at 18:55
  • How are you looking to run this? If you're trying to integrate it into a script or something, keep in mind that it's still going to need a "yes" click on an elevation prompt - your best bet is to have the process spawning this task be escalated. That said, it does look like there's some third-party tools out there to escalate a process that's launched from the command prompt. – Shane Madden Jul 20 '11 at 19:04
0

You need an elevated context to do it. I searched too much for a task that I needed, and couldn't find a way to request an elevation from the prompt in a batch file.

However, contrary to what Shane Madden has mentioned in the comments of the previous answer, I've been using Prio from prnwatch.com since time immemorial to do automatic silent elevation of certain processes. Naturally, you cannot count on this if you will be distributing your batch file to run on other computers....

Sam Sirry
  • 189
  • 10