Page 1 of 1 1
Topic Options
#84930 - 2002-01-21 04:57 PM WMI
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
here is the VB script i am converting.

code:

You can also use WMI. Here's the example from the
Win32_LogicalFileSecuritySetting docs...
' The folder named "testfolder" must exist on the C:\ drive.
' Connect to WMI and get the file security object for the testfolder
directory
Set wmiFileSecSetting = GetObject
("winmgmts:Win32_LogicalFileSecuritySetting.path='c:\\testfolder'")

' Use the Win32_LogicalFileSecuritySetting Caption property to create a
simple header before
' dumping the discretionary access control list (DACL)
Wscript.Echo wmiFileSecSetting.Caption & ":" & vbCrLf

' Call the Win32_LogicalFileSecuritySetting GetSecurityDescriptor
' method to retrieve an instance of the Win32_SecurityDescriptor class
' for the target object, that is, C:\TestFolder. Note that this is achieved
by
' passing an empty variable to GetSecurityDescriptor, which
' GetSecurityDescriptor in turn initializes with an instance of the
' Win32_SecurityDescriptor class that corresponds to the security
' descriptor for the target object.
RetVal = wmiFileSecSetting.GetSecurityDescriptor(wmiSecurityDescriptor)

' After the security descriptor is retrieved, you can use the properties
provided by the
' Win32_SecurityDescriptor class to dissect the security descriptor's access
control lists
' (DACL and SACL) and access control entries (ACEs).


' Retrieve the content of Win32_SecurityDescriptor DACL property.
' The DACL is an array of Win32_ACE objects.
DACL = wmiSecurityDescriptor.DACL

For each wmiAce in DACL

wscript.echo "Access Mask: " & wmiAce.AccessMask
wscript.echo "ACE Type: " & wmiAce.AceType

' Get Win32_Trustee object from ACE
Set Trustee = wmiAce.Trustee
wscript.echo "Trustee Domain: " & Trustee.Domain
wscript.echo "Trustee Name: " & Trustee.Name

' Get SID as array from Trustee
SID = Trustee.SID

For i = 0 To UBound(SID) - 1
strsid = strsid & SID(i) & ","
Next
strsid = strsid & SID(i)
wscript.echo "Trustee SID: {" & strsid & "}"

Next

wscript.echo "ReturnValue is: " & RetVal

Requirements


here is what i have in kix so far.

code:

$wmiFileSecSetting = GetObject("winmgmts:Win32_LogicalFileSecuritySetting.path='%temp%'")
$wmiFileSecSetting.Caption ?


; Call the Win32_LogicalFileSecuritySetting GetSecurityDescriptor
; method to retrieve an instance of the Win32_SecurityDescriptor class
; for the target object, that is, C:\TestFolder. Note that this is achievedby
; passing an empty variable to GetSecurityDescriptor, which
; GetSecurityDescriptor in turn initializes with an instance of the
; Win32_SecurityDescriptor class that corresponds to the security
; descriptor for the target object.
$RetVal = $wmiFileSecSetting.GetSecurityDescriptor($wmiSecurityDescriptor)


; After the security descriptor is retrieved, you can use the properties
; provided by the Win32_SecurityDescriptor class to dissect the security
; descriptor's access control lists (DACL and SACL) and access control
; entries (ACEs).

; Retrieve the content of Win32_SecurityDescriptor DACL property.
; The DACL is an array of Win32_ACE objects.
$DACL = $wmiSecurityDescriptor.DACL


the problem is that this line

$RetVal = $wmiFileSecSetting.GetSecurityDescriptor($wmiSecurityDescriptor)

is supposed to return an object named $wmiSecurityDescriptor, but i can not figure out why it is not. $RetVal is just a return code that equals 0 if successful a number if not. I am getting successful return codes both @error and $RetVal = 0, but my object handle is no where to be found.

Bryce

Top
#84931 - 2002-01-21 06:06 PM Re: WMI
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Bryce,

This line:

$RetVal = $wmiFileSecSetting.GetSecurityDescriptor($wmiSecurityDescriptor)

is not very kixtart (scripting) friendly. I don't know what the hell MS was thinking when they designed this sucker. This intent (I think) is to pass $wmiSecurityDescriptor as an empty object variable that is initialized by the COM object itself ... kinda like passing a variable by reference. It works in VBS but probably not a lot of other scripting languages. That is why they came out with these COM reskit utils, like ADsid and ADsSecurity.

ADsSecurity handles this nicely, here's a working kixtart version:


Break On


$Security = CreateObject("ADsSecurity")


$SecurityDescriptor = $Security.GetSecurityDescriptor("%temp%")


For Each $ACE in $SecurityDescriptor.DiscretionaryACL
?"Name="$ACE.Trustee
?"Type="$ACE.AceType
?"Mask="$ACE.AccessMask
Next


Exit 1

ADsSecurity is part of the ADSI reskit, available here:

ADSI SDK Download

Just unzip ADsSecurity.dll into system32 and run:

regsvr32 adssecurity.dll

This assumes win2000 or windows xp or nt/9x with ADSI already installed.

Hope this helps

-Shawn

Top
#84932 - 2002-01-21 06:40 PM Re: WMI
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Thanks Shawn,

I have been seeing references to the ADsSecurity COM object, but i did not know you had to add it by hand.

Bryce

Top
#84933 - 2002-01-21 06:57 PM Re: WMI
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
yap - around here, we call them "hand jobs"

-Shawn

Top
#84934 - 2002-01-21 08:00 PM Re: WMI
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
From what little I've been able to glean from ADsSecurity, you can manipulate registry permissions as well.

Cool stuff!

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#84935 - 2002-01-22 03:36 AM Re: WMI
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
I am making progress.....

but this seems to have me stumped.

According to the sdk, the access mask returns a flag value obtained from this table.

code:

ADS_RIGHT_GENERIC_READ = 0x80000000,
ADS_RIGHT_GENERIC_WRITE = 0x40000000,
ADS_RIGHT_GENERIC_EXECUTE = 0x20000000,
ADS_RIGHT_GENERIC_ALL = 0x10000000,
ADS_RIGHT_ACCESS_SYSTEM_SECURITY = 0x1000000,
ADS_RIGHT_SYNCHRONIZE = 0x100000,
ADS_RIGHT_WRITE_OWNER = 0x80000,
ADS_RIGHT_WRITE_DAC = 0x40000,
ADS_RIGHT_READ_CONTROL = 0x20000,
ADS_RIGHT_DELETE = 0x10000,
ADS_RIGHT_DS_CONTROL_ACCESS = 0x100
ADS_RIGHT_DS_LIST_OBJECT = 0x80,
ADS_RIGHT_DS_DELETE_TREE = 0x40,
ADS_RIGHT_DS_WRITE_PROP = 0x20,
ADS_RIGHT_DS_READ_PROP = 0x10,
ADS_RIGHT_DS_SELF = 0x8,
ADS_RIGHT_ACTRL_DS_LIST = 0x4,
ADS_RIGHT_DS_DELETE_CHILD = 0x2,
ADS_RIGHT_DS_CREATE_CHILD = 0x1,

the 0x# is that the value of the flag in hex? and is the value returned by .AccessMask a base 10 number?

I guess my non programmer roots are showing

Bryce

Top
#84936 - 2002-01-22 06:27 AM Re: WMI
New Mexico Mark Offline
Hey THIS is FUN
****

Registered: 2002-01-03
Posts: 223
Loc: Columbia, SC
Hi Bryce:

Your are correct. However, I think it is easier to just think of it as returning a number. So long as it IS a number, internally, the computer always treats it as binary. Decimal and Hex are merely convenient notations for people to use.

Notice that the maximum value returned is 0x80000000. This is 2,147,483,648. Sound familiar? The maximum/minumum values KiXtart can handle are 2,147,483,647 or -2,147,483,648. Because of this, it sounds like it might be easier to "&" the return value for testing.

I frequently use something like this for error codes. I create one error code value, then "|" it with a particular error code bit. It doesn't matter how many times that error occurs, it will only be set once. Then on exit, I can parse the bits in the error code to see which error bits were set.

New Mexico Mark

Top
#84937 - 2002-01-22 01:46 PM Re: WMI
Alex.H Offline
Seasoned Scripter

Registered: 2001-04-10
Posts: 406
Loc: France
C and C++ habits
Yes Bryce, as NMM said, 0x... stand for hexadecimal value. Much easier to read most of the time, but have to deal with the system returning decimal value.
_________________________
? getobject(Kixtart.org.Signature)

Top
#84938 - 2002-01-22 09:07 PM Re: WMI
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Ahem - Guys..

Shawn and I had quite a thread going on this very subject last summer.

Check this out - http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=2&t=002078

Have fun!

- Kent

_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#84939 - 2002-01-23 03:28 AM Re: WMI
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
I was wondering where that thread went.....

Bryce

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.063 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org