Use setacl to change Power Options: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
 
m (Fixed bug -- SetACL will only work with a DOS batch file)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
== Description ==
== Description ==
This script creates an installer that changes the Registry on Windows XP computers allowing Limited user accounts to change the Power Options in the Control Panel. It uses the freeware application "setacl" to change the registry and "Powercfg.exe" that comes with Windows.
This script creates an installer that changes the Registry on Windows XP computers allowing Limited user accounts to change the Power Options in the Control Panel. It uses the freeware application "setacl" to change the registry and "Powercfg.exe" that comes with Windows. You have to create two files a DOS batch with the commands that run SetACL and an NSIS installer to extract and run the batch.


NOTE: Other than putting this into an .exe this is not my work. Thanks should go specifically to "Murmansk" and "Darth Scream" on Aaron Margosis' MSDN blog. I just copied and pasted their examples and it worked!  
NOTE: Other than putting this into an .exe this is not my work. Thanks should go specifically to "Murmansk" and "Darth Scream" on Aaron Margosis' MSDN blog. I just copied and pasted their examples and it worked!  


== The Script ==
== The Script ==
<highlight-nsis>
<highlight-nsis>
; Installer:    Fix_Power_Settings.exe
; Installer:    Fix_Power_Settings.exe
Line 19: Line 18:
;  http://setacl.sourceforge.net/
;  http://setacl.sourceforge.net/
;  http://blogs.msdn.com/aaron_margosis/archive/2005/02/09/370263.aspx
;  http://blogs.msdn.com/aaron_margosis/archive/2005/02/09/370263.aspx
;
; NOTE:
;  Must use a DOS batch file when executing SetACL and Powercfg -- Execwait will not work!
;
;
; JCH -- 27 April 2006 -- New
; JCH -- 27 April 2006 -- New
; JCH -- 04 May 2006 -- Changed to use batch file "power.bat"
; ------------------------------------------------------------------------------------------------
; ------------------------------------------------------------------------------------------------
; HM NIS Edit Wizard helper defines
; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "Fix Power Settings"
!define PRODUCT_NAME "Fix Power Settings"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_VERSION "1.1"
!define PRODUCT_PUBLISHER "Air Power, Inc."
!define PRODUCT_PUBLISHER "Air Power, Inc."
!define PRODUCT_WEB_SITE "http://www.airpower-usa.com"
!define PRODUCT_WEB_SITE "http://www.airpower-usa.com"
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_FINISHPAGE_TEXT "Fix complete.\r\n\nThe power settings on this computer have been set to 'Alays On'."
!define MUI_FINISHPAGE_TEXT "Fix complete.\r\n\nThe power settings on this computer have been set to 'Always On'."
;!define MUI_FINISHPAGE_RUN "$SYSDIR\RUNDLL32.EXE SHELL32.DLL,SHHelpShortcuts_RunDLL PrintersFolder"
;!define MUI_FINISHPAGE_RUN "$SYSDIR\RUNDLL32.EXE SHELL32.DLL,SHHelpShortcuts_RunDLL PrintersFolder"
;!define MUI_FINISHPAGE_RUN_NOTCHECKED
;!define MUI_FINISHPAGE_RUN_NOTCHECKED
Line 77: Line 80:
   ;Display text above progress bar
   ;Display text above progress bar
   SetDetailsPrint textonly
   SetDetailsPrint textonly
   DetailPrint "Changing the registry"
   DetailPrint "Running batch file to change permissions"
   SetDetailsPrint none
   SetDetailsPrint none


   ExecWait 'c:\install\setacl\setacl.exe -silent -on "\\%computername%\HKLM\SOFTWARE\MICROSOFT\Windows\CurrentVersion\Controls Folder\PowerCfg\GlobalPowerPolicy" -ot reg -actn ace -ace "n:%computername%\users;p:full"'
   ExecWait 'c:\install\setacl\power.bat'
  ExecWait 'c:\install\setacl\setacl.exe -silent -on "\\%computername%\HKLM\SOFTWARE\MICROSOFT\Windows\CurrentVersion\Controls Folder\PowerCfg\PowerPolicies" -ot reg -actn ace -ace "n:%computername%\users;p:full"'
  ExecWait 'c:\install\setacl\setacl.exe -silent -on "\\%computername%\HKLM\SOFTWARE\MICROSOFT\Windows\CurrentVersion\Controls Folder\PowerCfg" -ot reg -actn ace -ace "n:%computername%\users;p:full"'
SectionEnd


;Tweak registry
Section "Set_Power" SEC15
  ;Display text above progress bar
  SetDetailsPrint textonly
  DetailPrint "Setting Power Scheme"
  SetDetailsPrint none
  ExecWait 'powercfg.exe /setactive "always on"'
SectionEnd
Section -Post
SectionEnd
SectionEnd
</highlight-nsis>
== DOS Batch File ==
SetACL appears to only work when run as part of a batch file. Using "ExecWait" within NSIS did not work. The installer will execute this batch which I called "power.bat" and stuck in the SetACL folder.
<highlight-nsis>
@ECHO OFF
c:\install\setacl\setacl.exe -on "\\%computername%\HKLM\SOFTWARE\MICROSOFT\Windows\CurrentVersion\Controls Folder\PowerCfg\GlobalPowerPolicy" -ot reg -actn ace -ace "n:%computername%\users;p:full"
c:\install\setacl\setacl.exe -on "\\%computername%\HKLM\SOFTWARE\MICROSOFT\Windows\CurrentVersion\Controls Folder\PowerCfg\PowerPolicies" -ot reg -actn ace -ace "n:%computername%\users;p:full"
c:\install\setacl\setacl.exe -on "\\%computername%\HKLM\SOFTWARE\MICROSOFT\Windows\CurrentVersion\Controls Folder\PowerCfg" -ot reg -actn ace -ace "n:%computername%\users;p:full"
powercfg.exe /setactive "Always On"'
</highlight-nsis>
</highlight-nsis>


Line 109: Line 107:
http://hmne.sourceforge.net/
http://hmne.sourceforge.net/


 
Installer to Change Permissions created using code above (for those who do not want to create their own installer):
http://www.duncarin.com/wp2/?p=5


[[Category:Real World Installers]]
[[Category:Real World Installers]]

Latest revision as of 15:33, 5 May 2006

Description

This script creates an installer that changes the Registry on Windows XP computers allowing Limited user accounts to change the Power Options in the Control Panel. It uses the freeware application "setacl" to change the registry and "Powercfg.exe" that comes with Windows. You have to create two files a DOS batch with the commands that run SetACL and an NSIS installer to extract and run the batch.

NOTE: Other than putting this into an .exe this is not my work. Thanks should go specifically to "Murmansk" and "Darth Scream" on Aaron Margosis' MSDN blog. I just copied and pasted their examples and it worked!

The Script

; Installer:    Fix_Power_Settings.exe
; Date created: 27 April 2006
; Created by:   Charles Haven (jchaven@airpower-usa.com)
;
; This script is used to modify the registry and change the Power Settings for user running
; under Limited accounts. Limited users are restrictaed from changing the Power settings or
; selecting different pre-defined Power Schemes, such as, "Always On".
;
; ADDITIONAL RESOURCES:
;  http://support.microsoft.com/default.aspx?scid=kb;en-us;307066 <-- STUPID MS ANSWER!
;  http://setacl.sourceforge.net/
;  http://blogs.msdn.com/aaron_margosis/archive/2005/02/09/370263.aspx
;
; NOTE:
;   Must use a DOS batch file when executing SetACL and Powercfg -- Execwait will not work!
;
; JCH -- 27 April 2006 -- New
; JCH -- 04 May 2006 -- Changed to use batch file "power.bat"
; ------------------------------------------------------------------------------------------------
; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "Fix Power Settings"
!define PRODUCT_VERSION "1.1"
!define PRODUCT_PUBLISHER "Air Power, Inc."
!define PRODUCT_WEB_SITE "http://www.airpower-usa.com"
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_FINISHPAGE_TEXT "Fix complete.\r\n\nThe power settings on this computer have been set to 'Always On'."
;!define MUI_FINISHPAGE_RUN "$SYSDIR\RUNDLL32.EXE SHELL32.DLL,SHHelpShortcuts_RunDLL PrintersFolder"
;!define MUI_FINISHPAGE_RUN_NOTCHECKED
;!define MUI_FINISHPAGE_RUN_TEXT "Open Printers Folder"
 
; MUI 1.67 compatible ------
!include "MUI.nsh"
 
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
 
; Welcome page
!insertmacro MUI_PAGE_WELCOME
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!insertmacro MUI_PAGE_FINISH
 
; Language files
!insertmacro MUI_LANGUAGE "English"
 
; MUI end ------
 
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Fix_Power_Settings.exe"
InstallDir "C:\Temp\JCH-INSTALL"
ShowInstDetails nevershow
 
 
Section "Extract_Files" SEC05
  ;Extract SetAcl files to "Install" folder
  SetOutPath "C:\Install\"
  SetOverwrite try
 
  ;Display text above progress bar
  SetDetailsPrint textonly
  DetailPrint "Extracting SetACL files to Install folder"
  SetDetailsPrint none
  ; Get all files in directory
  File /r "SetACL"
 
SectionEnd
 
 
;Tweak registry
Section "Tweak_Registry" SEC10
  ;Display text above progress bar
  SetDetailsPrint textonly
  DetailPrint "Running batch file to change permissions"
  SetDetailsPrint none
 
  ExecWait 'c:\install\setacl\power.bat'
 
SectionEnd

DOS Batch File

SetACL appears to only work when run as part of a batch file. Using "ExecWait" within NSIS did not work. The installer will execute this batch which I called "power.bat" and stuck in the SetACL folder.

@ECHO OFF
c:\install\setacl\setacl.exe -on "\\%computername%\HKLM\SOFTWARE\MICROSOFT\Windows\CurrentVersion\Controls Folder\PowerCfg\GlobalPowerPolicy" -ot reg -actn ace -ace "n:%computername%\users;p:full"
c:\install\setacl\setacl.exe -on "\\%computername%\HKLM\SOFTWARE\MICROSOFT\Windows\CurrentVersion\Controls Folder\PowerCfg\PowerPolicies" -ot reg -actn ace -ace "n:%computername%\users;p:full"
c:\install\setacl\setacl.exe -on "\\%computername%\HKLM\SOFTWARE\MICROSOFT\Windows\CurrentVersion\Controls Folder\PowerCfg" -ot reg -actn ace -ace "n:%computername%\users;p:full"
powercfg.exe /setactive "Always On"'

Additional Resources

Aaron Margosis' MSDN blog detailing the problem and several ways around it (look at the comments by "Murmansk" and "Darth Scream"): http://blogs.msdn.com/aaron_margosis/archive/2005/02/09/370263.aspx

SetACL.exe on Sourceforge: http://setacl.sourceforge.net/

HM NIS Editor: http://hmne.sourceforge.net/

Installer to Change Permissions created using code above (for those who do not want to create their own installer): http://www.duncarin.com/wp2/?p=5