Hi all,

this is kind of a continuation of another thread.

Maybe I should state what I'm actually trying to get as an output?
Maybe there is another/better way than what I'm doing...??

I would like to output a users CN, followed by all groups that the user is a member of.
ie: sowen, admins, InternetUsers, HS_Location, Everyone

where "sowen" is the CN, and all the rest are all the group names that sowen is a member of.

Right now I seemed to be stopped at NWDSRead giving a "-322" error.

here is my current code (in AutoHotkey).
Comment lines are started with a ";"
************************************************** *************
; AutoHotkey Version: 1.x
; Language: English
; Platform: Win9x/NT
; Author: A.N.Other <myemail@nowhere.com>
; Script Function:
; Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder)

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

; initializes NWCallsInit
nwrc :=DllCall("calwin32\NWCallsInit", UInt, 0, UInt, 0 )
If nwrc <> 0
MsgBox Error: NWCallsInit was not successful. That's all I know.

; pre-load NetWare netwin32 utility DLL
hModule := DllCall("LoadLibrary", "str", "netwin32.Dll")
if !hModule {
MsgBox Error: Can't load netwin32 DLL. are you SURE the Novell client is on this machine?

; Create new context handle
cCode := DllCall("netwin32.Dll\NWDSCreateContextHandle", "Int*", ctx, "Int")
if cCode <> 0
MsgBox Error: NWDSCreateContextHandle was not successful. %cCode%.

; Authenticated ??
; cCode := DllCall("netwin32.Dll\NWIsDSAuthenticated", UInt, 0)
; if cCode <> 1
; {
; MsgBox Error: you are not logged in. %cCode%.
; Exit
; }

; NWDSSetContext -- set context to root
retcode := DllCall("netwin32.Dll\NWDSSetContext", "Int", ctx, "Int", 3, "Int", DS_ROOT_NAME)
;msgbox, %Errorlevel%
If retcode <> 0
MsgBox, NWDSSetContext returned error %retcode%

;get default DS tree name from our context (root)
VarSetCapacity(DS_ROOT_NAME, 48)
retcode := DllCall("netwin32.Dll\NWDSGetContext", "Int", ctx, "Int", 11, "Str", DS_ROOT_NAME)
If retcode <> 0
MsgBox, NWDSGetContext returned error %retcode%
; this produces the correct tree name
;msgbox, %DS_ROOT_NAME%

; NWDS who am I.
VarSetCapacity(me, 48)
cCode2 := DllCall("netwin32.Dll\NWDSWhoAmI", "Int", ctx, "Str", me)
if cCode2 <> 0
MsgBox Error: NWDSWhoAmI was not successful. %cCode2%.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;
; this prints CN=USERNAME (with context)
;msgbox, %me%

;add leading "." to Common Name for eDir FQDN
me = .%me%
;msgbox, %me%


; setup inbuf
VarSetCapacity(inBuf, 22) ; t_buf (three shorts + four 32-bit integers (i.e. {4*4=16 + 3*2=6} = 22
,NumPut(0x0003, inBuf, 0, "uint") ; operation
,NumPut(0x0001, inBuf, 4, "uint") ; flags
,NumPut(64512, inBuf, 8, "uint") ; maxLen
,NumPut(0, inBuf, 12, "uint") ; curLen
,NumPut(0, inBuf, 16, "ushort") ; lastCount
,NumPut(0, inBuf, 18, "ushort") ; curPos
,NumPut(0, inBuf, 20, "ushort") ; data
retcode := DllCall("netwin32.Dll\NWDSAllocBuf", "UShort*", %DEFAULT_MESSAGE_LEN%, "Uint*", inBuf)
;msgbox, %Errorlevel%
If retcode <> 0
MsgBox, Alloc Buffer inbuf returned error %retcode%

; setup outbuf
retcode := DllCall("netwin32.Dll\NWDSAllocBuf", "UShort*", %DEFAULT_MESSAGE_LEN%, "Uint*", outBuf)
;msgbox, %Errorlevel%
If retcode <> 0
MsgBox, Alloc Buffer outbuf returned error %retcode%

; initialize the inBuf
retcode := DllCall("netwin32.Dll\NWDSInitBuf", "Int", ctx, "UInt", 3, "UInt", inBuf)
;msgbox, %Errorlevel%
If retcode <> 0
MsgBox, Init Buffer inbuf returned error %retcode%

; Write "Group Membership" to the inbuf buffer
retcode := DllCall("netwin32.Dll\NWDSPutAttrName", "Int", ctx, "UInt", inBuf, "Str", "Group Membership")
;msgbox, %Errorlevel%
If retcode <> 0
MsgBox, Put Attrib Name "Group Membership" returned error %retcode%

;msgbox % nStr.=chr( *str++ )
;;;;;;;;;; after a few ascii chars. this displays the string "Group Membership (no ending quote..but it might be at the end of the buffer data ??)
;;;;;;;;;; this leads me to believe that "Group Membership" is being written correctly to the inBuf.
;;;;;;;;;; I have to press "OK" twice for each letter (Unicode?)

;;;;;;;;;;;sets the var "SetIterHandl" to contain NO_MORE_ITERATIONS

VarSetCapacity(IterationHandle, 4)
,NumPut(&SetIterHandl, IterationHandle, 0, "UInt")
;;;;;;;;;;;;; sets the capacity of iterationHandle to 4 bytes (the size of 1 32-bit integer)
;;;;;;;;;;;;; puts the address of "SetIterHandl" in the "0" (first) offset of the variable "IterationHandle" and assigns it as an UInt.

;;;;;;;;;;look at the data in IterationHandle;;;;;;;;;;;;;;;;;;;
MyHandle := NumGet(IterationHandle, 0)
msgbox, %MyHandle%
;;;;;;;;;;;;; this produces a pointer (positive integer) as %MyHandle%

;msgbox % nStr.=chr( *str++ )
;;;;;;;;;;;;;;; if I use this to step through "MyHandle" I can see the text "NO_MORE_ITERATIONS" (unquoted);;;;;;;;;;;;;;;;;

;Read the attrib values etc from NDS
retcode := DllCall("netwin32.Dll\NWDSRead", "Int", ctx, "Str", me, "UInt", 1, "UInt", False, "UInt", inBuf, "UInt", &IterationHandle, "UInt", outBuf)
msgbox, %ctx%
msgbox, %me%
msgbox, %inBuf%
msgbox, %IterationHandle%
msgbox, %outbuf%
msgbox, %Errorlevel%
If retcode <> 0
MsgBox, NWDSRead returned error %retcode%

************************************************** **************************************

I believe I am following the correct process as outlined here:

But I keep getting a "-322" for a retcode on the NWDSRead call.

After the initial call the var %IterationHandle% reads as ascii code.

"UInt *", MyHandle
"UInt", &IterationHandle

produces a positive integer (pointer) for %MyHandle%, but still produces a -322 NDS error.
Any ideas on how to handle the Iteration handle???