Continue batch after UAC disable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
gymiv
Posts: 38
Joined: 10 Jul 2012 13:47

Re: Continue batch after UAC disable

#16 Post by gymiv » 17 Jul 2012 08:30

Sorry it was not removed i just did not copy the whole thing. This is getting to be a pretty big batch with all my other stuff i have in it. My problem is i still cannot get past the registry entry. I have had no luck fixing that issue yet. Here is the first part of my code.

rem @ECHO OFF

:: Disable UAC
:: This check for the Registry changes made or not yet
:: if the changes is made then goto after_reboot
:: if not make that mean this is the first time to run
:: and it make it and then goto first_time

For /F %%a in ('REG Query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA') DO (
IF %%a==0 ( Goto After_Reboot
) Else ( Goto First_Time )
)

:First_Time

:: 1st Disable UAC from Registry

REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v "EnableLUA" /t "REG_DWORD" /d "0" /f >nul
pause

:: 2nd take a copy of this batch to start up folder
:: Get USB drive letter
:: Use vol f: to get serial number
:: To point to a program on the USB drive use %drv%:\apps\program.exe

setlocal
For %%A in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) Do (
if exist "%%A:\" (for /f "tokens=5 delims= " %%B in ('Vol %%A:') Do if %%B==B729-02C8 set drv=%%A)
)
echo %drv%
pause

Copy /Y "%drv%:\NewMachineSetup.bat" "C:\users\%username%\AppData\Roaming\Microsoft
\Windows\Start Menu\Programs\Startup\NewMachineSetup.bat"
Pause

:: 3rd Now Rebooting the system
Pause
Shutdown -r -f -t 2

:After_Reboot

:: put your commands here to be done after the PC Restart

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Continue batch after UAC disable

#17 Post by abc0502 » 17 Jul 2012 09:34

Hi, Here is A Fix for the code the error was in the for loop and the compared number it should look like this:
For /F "tokens=3 delims= " %%a in ('REG Query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA') DO (
IF %%a==0x0 ( Goto After_Reboot
) Else ( Goto First_Time )
)

the new changes is in the red
Give it a try and tell us. :)

gymiv
Posts: 38
Joined: 10 Jul 2012 13:47

Re: Continue batch after UAC disable

#18 Post by gymiv » 17 Jul 2012 09:41

Still getting access denied. I i right click and run as administrator it comes up with a UAC prompt asking if this is OK. I am using an admin account. I double checked under users and the account i am using is marked as administrator.

rem @ECHO OFF

:: Disable UAC
:: This check for the Registry changes made or not yet
:: if the changes is made then goto after_reboot
:: if not make that mean this is the first time to run
:: and it make it and then goto first_time

For /F "tokens=3 delims= " %%a in ('REG Query HKLM\SOFTWARE\Microsoft\Windows
\CurrentVersion\Policies\System /v EnableLUA') DO (
IF %%a==0x0 ( Goto After_Reboot
) Else ( Goto First_Time )
)


C:\Users\p1tech\Desktop>rem @ECHO OFF

C:\Users\p1tech\Desktop>For /F "tokens=3 delims= " %a in ('REG Query HKLM\SOFTWA
RE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA') DO (IF %a ==
0x0 (Goto After_Reboot ) Else (Goto First_Time ) )

C:\Users\p1tech\Desktop>(IF 0x1 == 0x0 (Goto After_Reboot ) Else (Goto First_Ti
me ) )

C:\Users\p1tech\Desktop>REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\
Policies\System" /v "EnableLUA" /t "REG_DWORD" /d "0" /f 1>nul
ERROR: Access is denied.

C:\Users\p1tech\Desktop>pause
Press any key to continue . . .

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Continue batch after UAC disable

#19 Post by abc0502 » 17 Jul 2012 10:29

remove the Rem befor @echo off in the first line

u can turn the UAC by:
click start menu and write in the search uac
then open the first program and move the slide down to the end
then restart that will set the uac to none and teh value of the registry key we are testing will be 0x0
so teh batch will go automatically to the After_reboot section and run your commands

gymiv
Posts: 38
Joined: 10 Jul 2012 13:47

Re: Continue batch after UAC disable

#20 Post by gymiv » 17 Jul 2012 11:00

the whole reason i am doing this is so this batch will turn off the UAC without user intervention. That is the purpose of the code you wrote. The only issue is how to elevate the command prompt so we do not get the uac popup

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Continue batch after UAC disable

#21 Post by abc0502 » 17 Jul 2012 13:41

the whole reason i am doing this is so this batch will turn off the UAC without user intervention

Sorry I forgot :oops:

The only issue is how to elevate the command prompt so we do not get the uac popup

I Tried to do that before but no luck yet, The only thing that can do such a thing is an exploit but no way you can do exploits with batch

but as you said before right click on the batch and run as admin should make the batch run with admin rights.
so there is no need to put the First_Time section or even the If statement.

All what you have to do is just put your commands in a batch then when starting it right click and Run as administrator, Or
run the batch from elevated cmd window not by clicking the batch.

gymiv
Posts: 38
Joined: 10 Jul 2012 13:47

Re: Continue batch after UAC disable

#22 Post by gymiv » 17 Jul 2012 14:54

yes I can do that and run the batch but if you take out the first_time statement the reg setting will not get changed and the UAC will not get shut off. The only way to run the batch as an admin is to create a shortcut and tell it to run with admin rights. Thats when we get the UAC popup. Since UAC is still turned on administrators run in user mode. So you get the popup. The question being is how to run the batch so we do not get that popup? There has to be a way to suppress that stupid popup. I think thats the last thing holding us back

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Continue batch after UAC disable

#23 Post by abc0502 » 17 Jul 2012 16:20

If you right click and run as administrator you already running with privilage so you don't need to re-run with privelage

gymiv
Posts: 38
Joined: 10 Jul 2012 13:47

Re: Continue batch after UAC disable

#24 Post by gymiv » 18 Jul 2012 07:44

then how do i keep this UAC box from popping up?

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: Continue batch after UAC disable

#25 Post by Squashman » 18 Jul 2012 08:32

gymiv wrote:then how do i keep this UAC box from popping up?

you don't until you disable UAC as far as I know.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Continue batch after UAC disable

#26 Post by Ed Dyreen » 18 Jul 2012 09:21

gymiv wrote:>REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v "EnableLUA" /t "REG_DWORD" /d "0" /f 1>nul
ERROR: Access is denied.
Open regedit and browse the above key, right click and select -> permissions.
Is your username/group listed, can you access the list at all ?

You can edit permissions with 'setACL.EXE', you may need to take ownership of the key first.
http://setacl.sourceforge.net by Helge Klein


Regards,

gymiv
Posts: 38
Joined: 10 Jul 2012 13:47

Re: Continue batch after UAC disable

#27 Post by gymiv » 18 Jul 2012 09:40

my specific login is not in there but the administrators group is in there. the account i am using is marked as administrator under users. The administrator group in the permissions has full control

gymiv
Posts: 38
Joined: 10 Jul 2012 13:47

Re: Continue batch after UAC disable

#28 Post by gymiv » 18 Jul 2012 10:10

now this i do not get. I enabled the administrator account and reran the bat. It runs fine. So even though the account i have been using is marked as administrator it is not getting admin rights. So how do i elevate the privleges to get admin rights using a different account other than admin? Normally we do not enable the admin account. We just use the account that is created when you install win7.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Continue batch after UAC disable

#29 Post by abc0502 » 18 Jul 2012 14:34

As I said microsoft made the UAC to prevent any un authorized actions that happen in the background to act without the user permissions so the only way is using the Administrator account that u activated or disabling the uac by ur self loking for a batch to trick the uac "IMPOSIBLE" and the only other way is "exploits". :|

gymiv
Posts: 38
Joined: 10 Jul 2012 13:47

Re: Continue batch after UAC disable

#30 Post by gymiv » 18 Jul 2012 14:56

Okay thanks everyone I will just resolve to having to turn off uac by hand. Not a big deal but thanks for all the info. I should be able to use it in other areas.

Post Reply