Jump to content

Using DLLCall and Microsoft Network Management Functions


jonesy
 Share

Recommended Posts

Hi,

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!!):

$servername="\\dgx321"
$localgroupname="administrators"

$LOCALGROUP_MEMBERS_INFO_3=""
$level=3
$prefmaxlen=255
$entriesread=0
$totalentries=0
$resumehandle=0

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

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

msgbox(0,"", "NET_API_STATUS [" & $NET_API_STATUS & "]" & @CRLF & _
         "LOCALGROUP MEMBERS [" & StringLen($LOCALGROUP_MEMBERS_INFO_3) & "]=[" & $LOCALGROUP_MEMBERS_INFO_3 & "]")
Link to comment
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
Link to comment
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
    Wend
    $output = stringtrimleft($output,stringinstr($output,"----------"&@crlf,0,-1)+11)
    $output = stringreplace($output,"The command completed successfully.","")
    return stringsplit(stringstripws($output,3),@crlf,1)
EndFunc

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

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

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

http://www.autoitscript.com/forum/index.php?showtopic=31931

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

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...