You are here

SetACL functions for AutoIt and NSIS

2 posts / 0 new
Last post
wraithdu
Offline
Last seen: 10 years 10 months ago
Developer
Joined: 2007-06-27 20:22
SetACL functions for AutoIt and NSIS

SetACL - http://setacl.sourceforge.net/

SetACL is a set of routines for managing Windows permissions (ACLs) from the command line, from scripts and from programs.

Here is a function / macro that can be used to delete stubborn registry keys (like those left behind after driver uninstallations in the HKLM\SYSTEM\CurrentControlSet\Enum\Root\LEGACYxxx keys). At least a few people might find this useful.

AutoIt -

$setacl = '"X:\path\to\SetACL.exe"'

Func _SetACL_DeleteKey($key)
	; check if key exists
	RegRead($key, "")
	If @error  0 And @error  -1 Then
		SetError(@error)
	Else
		; set owner / permissions and delete key
		RunWait($setacl & ' -on "' & $key & '" -ot reg -rec yes ' & _
					'-actn clear -clr "dacl" ' & _
					'-actn setowner -ownr "n:Administrators" ' & _
					'-actn ace -ace "n:Everyone;p:full"' _
					, "", @SW_HIDE)
		RegDelete($key)
	EndIf
EndFunc

NSIS -
(requires Registry plugin)

!include Registry.nsh

Var setacl

!define SetACL_DeleteKey "!insertmacro _SetACL_DeleteKey"

!macro _SetACL_DeleteKey key
	Push $0
        ; check if key exists
	${registry::KeyExists} "${key}" $0
	StrCmp $0 0 0 End
                ; set owner / permissions and delete key
		ExecWait '"$setacl" -on "${key}" -ot reg -rec yes \
					-actn clear -clr "dacl" \
					-actn setowner -ownr "n:Administrators" \
					-actn ace -ace "n:Everyone;p:full"'
		${registry::DeleteKey} "${key}" $0
	End:
	Pop $0
!macroend

Section
        StrCpy $setacl "X:\path\to\SetACL.exe"
        ${SetACL_DeleteKey} "key\to\delete"
SectionEnd
._.
Offline
Last seen: 11 years 10 months ago
Joined: 2011-03-04 23:26
I don't understand

hey.. i tried this with NSIS but it doesn't seem to work for me.

i copied:

Var setacl

!define SetACL_DeleteKey "!insertmacro _SetACL_DeleteKey"

!macro _SetACL_DeleteKey key
Push $0
; check if key exists
${registry::KeyExists} "${key}" $0
StrCmp $0 0 0 End
; set owner / permissions and delete key
ExecWait '"$setacl" -on "${key}" -ot reg -rec yes \
-actn clear -clr "dacl" \
-actn setowner -ownr "n:Administrators" \
-actn ace -ace "n:Everyone;p:full"'
${registry::DeleteKey} "${key}" $0
End:
Pop $0
!macroend

Section
StrCpy $setacl "${NSISDIR}\bin\SetACL.exe"
SectionEnd

Saved into NSIS's 'Include' directory as 'SetACL_DeleteKey.nsh'.

and in my script i have:

!nclude "SetACL_DeleteKey.nsh"

Section
${SetACL_DeleteKey} "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\Root\LEGACY_BCM43XX"
SectionEnd

setcacl.exe is in the bin directory of NSIS of course.

Can you tell me where im going wrong?
everything compiles, runs, and terminates..
but the key is not being deleted?
Thanks

F.Y.I
i have also tried AccessControl plugin without success.
I can't seem to delete this key in Windows 7.
I found a program that is able to that grants 'System' rights..
but i can't seem to figure that out with AccessControl .

Log in or register to post comments