Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Star Lounger GiddyUpGo's Avatar
    Join Date
    Nov 2009
    Location
    Clarksville, Arkansas USA
    Posts
    99
    Thanks
    44
    Thanked 4 Times in 3 Posts

    Disable User Account Control using batch file?

    I have several batch files that I use for Programs cleanups, backups, etc.
    I have to set User Account Control's to "Never Notify" before the batch files will run.
    Is there a way to insert a command in the batch files, let the file run, and then reset the User Account Control back to the top?
    I now have to set the control to "Never Notify", run the batch files, then reboot to change the control back for protection.

    My Master Batch file to run the other batch files is:

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

    MODE CON: COLS=80 LINES=45
    @echo off
    cls
    goto begin
    This Menu controls LRBATCH.BAT, BACKUP.BAT, CLEANUP.BAT and RESTORE.BAT files.

    :begin
    cls
    echo.
    echo лллллллллллллллллллллллллллллллллллллллллллллллллл лллл
    echo лллллллллллллллллллллллллллллллллллллллллллллллллл лллл
    echo лллллллллл === Preventative Maintenance === ллллллллллББ
    echo лллллллллллллллллллллллллллллллллллллллллллллллллл ллллББ
    echo лллллллллллллллллллллллллллллллллллллллллллллллллл ллллББ
    echo лллллл 1 - Rejuvenate (Clean) Computer ллллллББ
    echo лллллллллллллллллллллллллллллллллллллллллллллллллл ллллББ
    echo лллллл 2 - Backup Computer ллллллББ
    echo лллллллллллллллллллллллллллллллллллллллллллллллллл ллллББ
    echo лллллл 3 - Restore Computer ллллллББ
    echo лллллллллллллллллллллллллллллллллллллллллллллллллл ллллББ
    echo лллллллллллллллллллллллллллллллллллллллллллллллллл ллллББ
    echo ББББББББББББББББББББББББББББББББББББББББББББББББББ БББ
    echo Enter Selection Number, or Press ESC to Quit:
    :getchoice
    choose
    if errorlevel 27 goto end
    if errorlevel 5 goto getchoice
    if errorlevel 3 goto choice3
    if errorlevel 2 goto choice2
    :choice1
    cls
    echo Choice #1
    c:\CleanUp.bat
    cls
    :choice2
    cls
    echo Choice #2
    c:\BackUp.bat
    :choice3
    cls
    echo Choice #3
    c:\Restore.bat

    :end
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

    I run my computer as Administrator. W7 32bit
    GiddyUpGo "Don't look back. That is not the direction you are going!"

  2. #2
    jwoods
    Guest
    Actually, you could run the batch file as a task in Task Manager without the need to change UAC at all.

    1. Create a new task.

    2. In the General tab, select Run with highest privileges.

    3. In the Actions tab, Program/Script text box, enter the full path and name of the script (i.e. "C:\Users\Your User Name\Scripts\Batch File To Run.bat". Easiest way is to use the Browse button.

    4. Optionally, you could schedule it in Triggers tab.
    Last edited by jwoods; 2015-05-07 at 20:54.

  3. #3
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,417
    Thanks
    33
    Thanked 195 Times in 175 Posts
    Other than running the individual BATch files as scheduled tasks (where you have no user choice input) there is the paid-for Hidden Start (Hstart) program.

    Might not be worth it for just a small number of BATch files, though.
    BATcher

    Time prevents everything happening all at once...

  4. #4
    Star Lounger GiddyUpGo's Avatar
    Join Date
    Nov 2009
    Location
    Clarksville, Arkansas USA
    Posts
    99
    Thanks
    44
    Thanked 4 Times in 3 Posts
    Quote Originally Posted by jwoods View Post
    Actually, you could run the batch file as a task in Task Manager without the need to change UAC at all.

    1. Create a new task.

    2. In the General tab, select Run with highest privileges.

    3. In the Actions tab, Program/Script text box, enter the full path and name of the script (i.e. "C:\Users\Your User Name\Scripts\Batch File To Run.bat". Easiest way is to use the Browse button.
    Thank you jwoods for your reply.
    My w7 Pro does not show the General tab and my users does not show my batch file.
    I can create the Start Task Manager's New Task file OK, but it will only open my Batch file and then close it without it running.
    I can manually run Start Task Manager, using New Task, and my batch file will run without any UAC prompts...perfect calling the other batch files and they will also run.
    I cannot get the auto Start Task Manager to work. I receive no errors message.
    GiddyUpGo "Don't look back. That is not the direction you are going!"

  5. #5
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    GUG,

    To run your cmd file from the the Task Scheduler setup the action page like this.

    uacfreecmd.JPG

    Of course you'll replace the value after the /c to reflect the information for your batch file.

    Don't forget to check the "Run with highest privledges" box on the General Tab.

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  6. #6
    Star Lounger
    Join Date
    Dec 2009
    Location
    Ithaca, New York, USA
    Posts
    64
    Thanks
    1
    Thanked 11 Times in 8 Posts

    This is how you change the User Account Control using a batch file

    To answer the original question: This is how you do it:

    1. Create a file as follows called "UAC_Level-1.reg" (without the quotes):
    Windows Registry Editor Version 5.00
    ; Created by: Shawn Brink
    ; http://www.sevenforums.com
    ; Tutorial: http://www.sevenforums.com/tutorials...-settings.html
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Policies\System]
    "ConsentPromptBehaviorAdmin"=dword:00000002
    "EnableLUA"=dword:00000001
    "PromptOnSecureDesktop"=dword:00000001

    2. Create a file as follows called "UAC_Level-2_Default.reg" (without the quotes):
    Windows Registry Editor Version 5.00
    ; Created by: Shawn Brink
    ; http://www.sevenforums.com
    ; Tutorial: http://www.sevenforums.com/tutorials...-settings.html
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Policies\System]
    "ConsentPromptBehaviorAdmin"=dword:00000005
    "EnableLUA"=dword:00000001
    "PromptOnSecureDesktop"=dword:00000001

    3. Create a file as follows called "UAC_Level-3_No_Dim.reg" (without the quotes):
    Windows Registry Editor Version 5.00
    ; Created by: Shawn Brink
    ; http://www.sevenforums.com
    ; Tutorial: http://www.sevenforums.com/tutorials...-settings.html
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Policies\System]
    "ConsentPromptBehaviorAdmin"=dword:00000005
    "EnableLUA"=dword:00000001
    "PromptOnSecureDesktop"=dword:00000000

    4. Create a file as follows called "UAC_Level-4_Disable.reg" (without the quotes):
    Windows Registry Editor Version 5.00
    ; Created by: Shawn Brink
    ; http://www.sevenforums.com
    ; Tutorial: http://www.sevenforums.com/tutorials...-settings.html
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Curr entVersion\Policies\System]
    "ConsentPromptBehaviorAdmin"=dword:00000000
    "EnableLUA"=dword:00000000
    "PromptOnSecureDesktop"=dword:00000000

    Now, in your BAT file add a CD command to take you to the directory where the 4 files above are stored. Depending on what level UAC you want, simply add this line (for example) to your BAT file:

    Start regedit.exe /s UAC_Level-2_Default.reg

    The above line can be adjusted to whichever of the 4 UAC levels you desire.

    Stu

  7. The Following User Says Thank You to sb06794 For This Useful Post:

    GiddyUpGo (2015-05-14)

  8. #7
    Star Lounger GiddyUpGo's Avatar
    Join Date
    Nov 2009
    Location
    Clarksville, Arkansas USA
    Posts
    99
    Thanks
    44
    Thanked 4 Times in 3 Posts
    Thank You sb06794!
    I make the default.reg file from your instructions.
    After I made a new desktop .Bat Icon, this works like I wanted, perfect!
    Everything I tried before would only work part way, not letting the called .bat files to work all of the way.
    GiddyUpGo "Don't look back. That is not the direction you are going!"

  9. #8
    Star Lounger
    Join Date
    Dec 2009
    Location
    Ithaca, New York, USA
    Posts
    64
    Thanks
    1
    Thanked 11 Times in 8 Posts
    You're welcome GiddyUpGo!

    I'm of the belief that .Bat files are WAY underrated. It's truly amazing what can be done with them. Most people are not aware of most of their capabilities. I'm glad I could help.
    Stu

  10. #9
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,417
    Thanks
    33
    Thanked 195 Times in 175 Posts
    I think a fair amount of acknowledgement should be made to Shawn Brink, of Seven (and subsequent) Forums.
    He produces a large amount of excellent stuff, and his sites are well worth visiting!
    BATcher

    Time prevents everything happening all at once...

  11. The Following User Says Thank You to BATcher For This Useful Post:

    satrow (2015-05-16)

  12. #10
    Star Lounger
    Join Date
    Dec 2009
    Location
    Ithaca, New York, USA
    Posts
    64
    Thanks
    1
    Thanked 11 Times in 8 Posts
    Quote Originally Posted by BATcher View Post
    I think a fair amount of acknowledgement should be made to Shawn Brink, of Seven (and subsequent) Forums.
    He produces a large amount of excellent stuff, and his sites are well worth visiting!
    BATcher,
    I 100% agree with you. I obviously (see embedded comments in ".reg" files) learned how to do it from Shawn. I know of no other way to change the UAC with a BAT file.
    Stu

  13. #11
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Hey Y'all,

    Ok you guys got me to thinking again...you know what that means another PowerShell project to help me learn. So I said to my self why have 4 programs/bat files when you can it with one PowerShell program?

    So here is what I came up with.

    Name this one Set-UACLevel.ps1
    Code:
    <#
     +-----------------------------------------------------------+
     | UAC Switcher                                              |
     | Programmed by: The Computer Mentor (aka WLS: RetiredGeek) |
     | Created      : 16 Jun 2015                                |
     | Version      : 1.0                                        |
     +-----------------------------------------------------------+
    #>
    
    function Add-Row 
     {
      param (
             [int]$Level,
             [string]$Name,
             [int]$Value
            ) 
     
      #Create Row Variable 
          $UACRow = $UACTable.NewRow()
      #Assign items to row variable
          $UACRow.Level = $Level
          $UACRow.Name = $Name
          $UACRow.Value = $Value
      #Add Row to Table using Row Variable
          $UACTable.Rows.Add($UACRow)
    }
    
    function Get-CurrentUAC
    {
      $EnableLUA = Get-ItemProperty -Path $UPath `
          -Name EnableLUA
    
      $CPBA = Get-ItemProperty -Path $UPath `
          -Name ConsentPromptBehaviorAdmin
    
      $POSD = Get-ItemProperty -Path $UPath `
          -Name PromptOnSecureDesktop
    
      if ($EnableLUA.EnableLUA -eq 0) {
        $UACStatus = "OFF"
      }
      Else {
        $UACStatus = "ON"
      }
    
      Write-Host "Current Settings: $UACStatus"
      Write-Host "EnableLUA: $($EnableLUA.EnableLUA)"
      Write-Host "Prompt Behavior: $($CPBA.ConsentPromptBehaviorAdmin)"
      Write-Host "Prompt on Secure Desktop: $($POSD.PromptOnSecureDesktop)"
    
    }  #End function Get-CurrentUAC
    
    Clear-Host
    
    # Create Table
      $UACTable = New-Object system.Data.DataTable "UAC Information"
    #Create Columns for table 
      $UACcol1 = New-Object system.Data.DataColumn Level,([int])       
      $UACcol2 = New-Object system.Data.DataColumn Name,([string])
      $UACcol3 = New-Object System.Data.DataColumn Value,([int])
    #Add Columns to table
      $UACTable.columns.add($UACcol1)
      $UACTable.columns.add($UACcol2)
      $UACTable.columns.add($UACcol3)
    
    # UAC Level 1 Values
      Add-Row -Level 1 -Name 'EnableLUA' -Value 1
      Add-Row -Level 1 -Name 'ConsentPromptBehaviorAdmin' -Value 2
      Add-Row -Level 1 -Name 'PromptOnSecureDesktop' -Value 1
    
    # UAC Level 2 Values
      Add-Row -Level 2 -Name 'EnableLUA' -Value 1
      Add-Row -Level 2 -Name 'ConsentPromptBehaviorAdmin' -Value 5
      Add-Row -Level 2 -Name 'PromptOnSecureDesktop' -Value 1
    
    # UAC Level 3 Values
      Add-Row -Level 3 -Name 'EnableLUA' -Value 1
      Add-Row -Level 3 -Name 'ConsentPromptBehaviorAdmin' -Value 5
      Add-Row -Level 3 -Name 'PromptOnSecureDesktop' -Value 0
    
    # UAC Level 4 Values
      Add-Row -Level 4 -Name 'EnableLUA' -Value 0
      Add-Row -Level 4 -Name 'ConsentPromptBehaviorAdmin' -Value 0
      Add-Row -Level 4 -Name 'PromptOnSecureDesktop' -Value 0
     
    $UPath = `
     "registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\policies\system"
    
    Get-CurrentUAC
    $ans = Read-Host "`nType UAC Level 1-4 `nor 0 to Exit and press the Enter Key"
    
    If ($ans -ge 0 -and $ans -le 4) {
    
      If ($ans -gt 0) {
        ForEach ($Item in $UACTable) {
          if ($Item.Level -eq $ans) {
            Set-ItemProperty -Path $UPath -Name $Item.Name -Value $Item.Value  
           }
        } #ForEach ($Item)
    
        Write-Host "`nUAC set to Level $ans `n"
        Get-CurrentUAC
    
      }   #End If ($ans -gt 0)
      Else {
             Write-Host "User selected Exit"
      }
    }
    Else {
           Write-Host "$ans is an invalid entry!"
    }
    
     Sleep 5   #Give user 5 seconds to read message!
    Of course this does require Admin Privleges so I found (via google) a way to write a batch file that will run any powershell script as Admin as long as the script and the .bat are in the same directory and have the same filename (not file type of course)!

    Name this one Set-UACLevel.bat
    Code:
    PowerShell.exe -Command "& {Start-Process PowerShell.exe -ArgumentList '-ExecutionPolicy Bypass -File ""%~dpn0.ps1""' -Verb RunAs}"
    In lieu of the .bat file you could create a scheduled task to accomplish the same thing.

    In either case don't forget to create a shortcut to the .bat file or scheduled task on your desktop for easy access!

    Any suggestions are welcome.

    BTW: keep an eye on the notification balloons that will tell you when you need to reboot for the settings to take effect!
    Last edited by RetiredGeek; 2015-05-16 at 17:27.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  14. #12
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,191
    Thanks
    48
    Thanked 985 Times in 915 Posts
    You didn't capture the balloon notification and offer to restart?

    cheers, Paul

  15. #13
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Paul,

    I don't know how to do that yet. Care to make the mods so I can learn?
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  16. #14
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,436
    Thanks
    372
    Thanked 1,457 Times in 1,326 Posts
    Hey Y'all,

    New improved version with input error checking and better messages.
    Code:
    <#
     +-----------------------------------------------------------+
     | UAC Switcher                                              |
     | Programmed by: The Computer Mentor (aka WLS: RetiredGeek) |
     | Created      : 16 Jun 2015                                |
     | Updated      : 18 Jun 2015                                |
     | Version      : 1.2                                        |
     +-----------------------------------------------------------+
    #>
    
    function Add-Row 
     {
      param (
             [int]$Level,
             [string]$Name,
             [int]$Value
            ) 
     
      #Create Row Variable 
          $UACRow = $UACTable.NewRow()
      #Assign items to row variable
          $UACRow.Level = $Level
          $UACRow.Name = $Name
          $UACRow.Value = $Value
      #Add Row to Table using Row Variable
          $UACTable.Rows.Add($UACRow)
    }
    
    function Get-CurrentUAC
    {
      $EnableLUA = Get-ItemProperty -Path $UPath `
          -Name EnableLUA
    
      $CPBA = Get-ItemProperty -Path $UPath `
          -Name ConsentPromptBehaviorAdmin
    
      $POSD = Get-ItemProperty -Path $UPath `
          -Name PromptOnSecureDesktop
    
      if ($EnableLUA.EnableLUA -eq 0) {
        $UACStatus = "OFF"
        $UACLevel = 4
      }
      Else {
        $UACStatus = "ON"
        if ($POSD.PromptOnSecureDesktop -eq 0) {
          $UACLevel = 3
        }
        Else {
              if ($CPBA.ConsentPromptBehaviorAdmin -eq 5) {
                $UACLevel = 2
              }
              Else {
                     $UACLevel = 1
              }
        }
      }
    
      Write-Host "`nUAC is $UACStatus Level: $UACLevel`n"
      Write-Host "Settings:"
      Write-Host "`tEnableLUA: $($EnableLUA.EnableLUA)"
      Write-Host "`tPrompt Behavior: $($CPBA.ConsentPromptBehaviorAdmin)"
      Write-Host "`tPrompt on Secure Desktop: $($POSD.PromptOnSecureDesktop)"
    
    }  #function Get-CurrentUAC
    
    Clear-Host
    
    # Create Table
      $UACTable = New-Object system.Data.DataTable "UAC Information"
    #Create Columns for table 
      $UACcol1 = New-Object system.Data.DataColumn Level,([int])       
      $UACcol2 = New-Object system.Data.DataColumn Name,([string])
      $UACcol3 = New-Object System.Data.DataColumn Value,([int])
    #Add Columns to table
      $UACTable.columns.add($UACcol1)
      $UACTable.columns.add($UACcol2)
      $UACTable.columns.add($UACcol3)
    
    # UAC Level 1 Values
      Add-Row -Level 1 -Name 'EnableLUA' -Value 1
      Add-Row -Level 1 -Name 'ConsentPromptBehaviorAdmin' -Value 2
      Add-Row -Level 1 -Name 'PromptOnSecureDesktop' -Value 1
    
    # UAC Level 2 Values
      Add-Row -Level 2 -Name 'EnableLUA' -Value 1
      Add-Row -Level 2 -Name 'ConsentPromptBehaviorAdmin' -Value 5
      Add-Row -Level 2 -Name 'PromptOnSecureDesktop' -Value 1
    
    # UAC Level 3 Values
      Add-Row -Level 3 -Name 'EnableLUA' -Value 1
      Add-Row -Level 3 -Name 'ConsentPromptBehaviorAdmin' -Value 5
      Add-Row -Level 3 -Name 'PromptOnSecureDesktop' -Value 0
    
    # UAC Level 4 Values
      Add-Row -Level 4 -Name 'EnableLUA' -Value 0
      Add-Row -Level 4 -Name 'ConsentPromptBehaviorAdmin' -Value 0
      Add-Row -Level 4 -Name 'PromptOnSecureDesktop' -Value 0
     
    $UPath = `
     "registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\policies\system"
    
    Get-CurrentUAC
    
    do {
        try {
            $numOk = $true
            [int]$NewUACLevel = Read-host "`nType UAC Level 1-4 `nor 0 to Exit and press the Enter Key"
            } # end try
        catch {$numOK = $false}
        } # end do 
    until (($NewUACLevel -ge 0 -and $NewUACLevel -le 4) -and $numOK)
    
      If ($NewUACLevel -gt 0) {
        
        ForEach ($Item in $UACTable) {
          if ($Item.Level -eq $NewUACLevel) {
            Set-ItemProperty -Path $UPath -Name $Item.Name -Value $Item.Value  
           }
        } #ForEach ($Item)
    
        Get-CurrentUAC
    
      }   #End If ($NewUACLevel -gt 0)
      Else {
             Write-Host "`nUser Selected Exit"
      }
    
     Sleep 5   #Give user 5 seconds to read message
    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  17. #15
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,191
    Thanks
    48
    Thanked 985 Times in 915 Posts
    Quote Originally Posted by RetiredGeek View Post
    I don't know how to do that yet
    http://blogs.technet.com/b/heyscript...le-part-1.aspx
    http://blogs.technet.com/b/heyscript...-a-reboot.aspx

    cheers, Paul

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •