Use setacl to change Power Options: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
 
No edit summary
Line 109: Line 109:
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]]

Revision as of 13:45, 28 April 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.

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
;
; JCH -- 27 April 2006 -- New
; ------------------------------------------------------------------------------------------------
; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "Fix Power Settings"
!define PRODUCT_VERSION "1.0"
!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 'Alays 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 "Changing the registry"
  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\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

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