Jump to content
Sign in to follow this  

Using DLLCall and Microsoft Network Management Functions

Recommended Posts


Eventually, I want to be able to use AutoIT to call any of the functions defined here: Network Management Functions

I'm just starting out on trying to do this however, and the first function I want to call is this: NetLocalGroupGetMembers - I want to get hold of a list of Administrators on a PC.

There does appear to be a problem however. If you call one of these functions to Retrieve Data then the documentation here on Network Management Function Buffers, states that "The system allocates the buffer for the returned information. The caller must pass a pointer variable to the function on input. On successful return, the pointer receives the address of the system-allocated buffer that contains the returned information.".

So is it possible to call one of these types of functions at all? You cannot pre-allocate the Struct to receive the data, merely access it after calling the DLL. How can I do this?

I know there are alternatives, using calls to external EXE files that have been recorded elsewhere, but that means ensuring the external EXE file is available etc. I'm sure that AutoIT should be able to do this, it is after all the best...

I am using AutoIT v3.2.0.1

Here is the code I have got so far (There may be errors in the parameters as well - It doesn't work!!):



; Make the DllCall
$NET_API_STATUS=DLLCall("netapi32.dll", "int", "NetLocalGroupGetMembers", _
    "wstr", $servername, _
    "wstr", $localgroupname, _
    "int", $level, _
    "int", $prefmaxlen, _
    "long_ptr", $entriesread, _
    "long_ptr", $totalentries, _
    "long_ptr", $resumehandle);

if @error Then
    MsgBox(0,"","Error in DllCall " & @error);

msgbox(0,"", "NET_API_STATUS [" & $NET_API_STATUS & "]" & @CRLF & _

Share this post

Link to post
Share on other sites

Help !!!!!!!!!!!

Has nobody got a suggestion?

This is driving me to distraction. Is it something that can be done, and I'm making a mistake?

Is it something that can't be done, and I need to suggest it as an improvement in the Ideas Lab?

Edited by jonesy

Share this post

Link to post
Share on other sites

Well, this is a little bit lower tech, but you can get the local members of a group this way:

#include <Constants.au3>
#include <array.au3>

$aMembers = EnumLocalGroup("Administrators")
_ArrayDisplay($aMembers,"Administrator Members")

func EnumLocalGroup($groupname)
    $foo = Run(@ComSpec & " /c net localgroup "&$groupname, @SystemDir, @SW_HIDE, $STDOUT_CHILD)
    $output = ""
    While 1
        $output &= StdoutRead($foo)
        If @error Then ExitLoop
    $output = stringtrimleft($output,stringinstr($output,"----------"&@crlf,0,-1)+11)
    $output = stringreplace($output,"The command completed successfully.","")
    return stringsplit(stringstripws($output,3),@crlf,1)

BTW, search the forum for netapi32.dll - it sounds like it might be that you just can't use it with AutoIt yet.

Edited by lod3n

Share this post

Link to post
Share on other sites

I take that back, it looks like joell has used netapi32.dll here:


However he doesn't post the function strToUnicode() or explain what $domn is, but it looks like a lead. Good luck!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...