Sign in to follow this  
Followers 0
Ghost1987

WinAPI Question

22 posts in this topic

I need help with 2 api functions that I intend to use in my script:

1. NetGroupGetUsers()

2. NetUserChangePassword()

Please some one with experience in winapi and autoit post how to use this api calls in autoit, so I could finish and release my script to public.

Share this post


Link to post
Share on other sites



I need help with 2 api functions that I intend to use in my script:

1. NetGroupGetUsers()

2. NetUserChangePassword()

Please some one with experience in winapi and autoit post how to use this api calls in autoit, so I could finish and release my script to public.

Those are complicated function using DLL structs from NetAPI32.dll. If you don't know how to do that, why try to release a script implementing it?

Learn to use the DLL* functions in AutoIt first.

For now, just use Run() with "NET GROUP" and "NET USER" command lines.

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I know it is complicated this is why I am asking for help. Console won't work. I use russian windows and build in group names in cyrilic. Net command can't work with those symbols.

Share this post


Link to post
Share on other sites

Couldn't you use the "WinNT:" or "LDAP:" com objects for this?

Yes, I've could.

But other functionality is already implemented in WinAPI, so it wouldn't be good programming.

I am talking about 3 api functions NetAddGroupMembers, NetDelGroupMembers, NetUsersEnum that already in script.

Really people no one can share his winapi knowledge?

Share this post


Link to post
Share on other sites

Yes, I've could.

But other functionality is already implemented in WinAPI, so it wouldn't be good programming.

I am talking about 3 api functions NetAddGroupMembers, NetDelGroupMembers, NetUsersEnum that already in script.

Really people no one can share his winapi knowledge?

I doubt it's a matter of "Can", I think it's a matter of you wanting someone to go out of their way to do it when a viable substitution has been provided for you already.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I would suggest following PsaltyDS's advice and learning how AutoIt handles DLL's is the best way for now and in the future.

Not knowing how to use the DLLs will only result in work rounds :D Just my 2 cents.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

I doubt it's a matter of "Can", I think it's a matter of you wanting someone to go out of their way to do it when a viable substitution has been provided for you already.

Think yourself how the code will look like?

How script will stop respond then com objects are used?

And how exactly I can test user password using com objects?

And well I can admit I prefer using winapi over com objects.

Share this post


Link to post
Share on other sites

I would suggest following PsaltyDS's advice and learning how AutoIt handles DLL's is the best way for now and in the future.

Not knowing how to use the DLLs will only result in work rounds :D Just my 2 cents.

See this is the problem no real winapi tutorials exists as good debuggers for autoit.

So I am really can't even check what happens when I try to write code.

And how this is simpler then c++?

Which by the way I can't really comprehend.

Share this post


Link to post
Share on other sites

Its only hard if you make it harder... :D

Well I don't have much free time and experience to hack winapi for autoit.

By the way this function that I have mentioned should be be default in Security UDF, because SID manipulation functions

that already present in this UDF are useless without user and group manipulation.

Share this post


Link to post
Share on other sites

Hows this for a tip.

You just cannot come here and expect someone to write something for you because you cannot get off your fat arse to do it.

The least you can do is attempt it. Anything less than that will not gain you much if any help.

So go away, try to write some code, get it working and post it back here.

Also remember not to bump your posts more than ONCE in a 24 hour period.

Cheers,

Brett

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Hows this for a tip.

You just cannot come here and expect someone to write something for you because you cannot get off your fat arse to do it.

The least you can do is attempt it. Anything less than that will not gain you much if any help.

So go away, try to write some code, get it working and post it back here.

Also remember not to bump your posts more than ONCE in a 24 hour period.

Cheers,

Brett

Yes BIG and informative tip.

I am not expecting from anyone to write any code for me I am simply asking to share code if someone already done this kind of thing before.

lol

"So go away, try to write some code, get it working and post it back here. "

Yes and does this correlates with sentence what you wrote above

"You just cannot come here and expect someone to write something for you because you cannot get off your fat arse to do it."

Soon I'll post compiled version of my script so it would be easier to explain what this script needs.

Edited by Ghost1987

Share this post


Link to post
Share on other sites

This script was inspired by Aaron Margosis "MakeMeAdmin" script, which is very useful for lua environment but unusable with localized system accounts.

Currently it lucks embedded check for correct user password and check if user (runas) already in admin group.

So this is why I've asked for those winapi function implementations.

Password thing is not so important, but the check for admin group is!

Just imagine what will become of admin user if he runs this script with he's credentials, it will remove him from admin group

and this user will not have any group membership and would not be able to logon.

Please test this script out and post you comments.

Share this post


Link to post
Share on other sites

Have you tried searching the example scripts section?

There are more examples on how to use DLL functions there then you possible look at - thats how I learnt and I suspect most ppl here learnt.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

Have you tried searching the example scripts section?

There are more examples on how to use DLL functions there then you possible look at - thats how I learnt and I suspect most ppl here learnt.

That is how I've got 3 other winapi functions ;-)

Share this post


Link to post
Share on other sites

I've tried to do some winapi coding on my own, but can't really find what is wrong with this code?

Please help!

#NoTrayIcon
#RequireAdmin
#include <Array.au3>

$aRet = _NetUserGetGroups("Администратор")
_ArrayDisplay($aRet, "Display Array")

Func _NetUserGetGroups($sUsername, $sServer = "")
    Local $tBufPtr = DllStructCreate("ptr")
    Local $tEntriesRead = DllStructCreate("dword")
    Local $tTotalEntries = DllStructCreate("dword")
    Local $aRet = DllCall("Netapi32.dll", "int", "NetUserGetGroups", "wstr", $sServer, "wstr", $sUsername, "dword", 0, "ptr", DllStructGetPtr($tBufPtr), "dword", -1, "ptr", DllStructGetPtr($tEntriesRead), "ptr", DllStructGetPtr($tTotalEntries))
    If $aRet[0] Then Return SetError(1, $aRet[0])
    Local $iEntriesRead = DllStructGetData($tEntriesRead,1)
    Local $pBuf = DllStructGetData($tBufPtr,1)
    Local $sGroupUsersInfo0 = "ptr"
    Local $tGroupUsersInfo0 = DllStructCreate($sGroupUsersInfo0)
    Local $zGroupUsersInfo0 = DllStructGetSize($tGroupUsersInfo0)
    For $i=1 To $iEntriesRead
        $tGroupUsersInfo0 = DllStructCreate($sGroupUsersInfo0, $pBuf+($i-1)*$zGroupUsersInfo0)
        $tGroupName = DllStructCreate("wchar[256]", DllStructGetData($tGroupUsersInfo0,1))
    Next
    DllCall("Netapi32.dll", "int", "NetApiBufferFree", "ptr", $pBuf)
    Return $aRet
EndFunc     ;_NetUserGetGroups

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

I've tried to do some winapi coding on my own, but can't really find what is wrong with this code?

Please help!

#NoTrayIcon
#RequireAdmin
#include <Array.au3>

$aRet = _NetUserGetGroups("Администратор")
_ArrayDisplay($aRet, "Display Array")

Func _NetUserGetGroups($sUsername, $sServer = "")
    Local $tBufPtr = DllStructCreate("ptr")
    Local $tEntriesRead = DllStructCreate("dword")
    Local $tTotalEntries = DllStructCreate("dword")
    Local $aRet = DllCall("Netapi32.dll", "int", "NetUserGetGroups", "wstr", $sServer, "wstr", $sUsername, "dword", 0, "ptr", DllStructGetPtr($tBufPtr), "dword", -1, "ptr", DllStructGetPtr($tEntriesRead), "ptr", DllStructGetPtr($tTotalEntries))
    If $aRet[0] Then Return SetError(1, $aRet[0])
    Local $iEntriesRead = DllStructGetData($tEntriesRead,1)
    Local $pBuf = DllStructGetData($tBufPtr,1)
    Local $sGroupUsersInfo0 = "ptr"
    Local $tGroupUsersInfo0 = DllStructCreate($sGroupUsersInfo0)
    Local $zGroupUsersInfo0 = DllStructGetSize($tGroupUsersInfo0)
    For $i=1 To $iEntriesRead
        $tGroupUsersInfo0 = DllStructCreate($sGroupUsersInfo0, $pBuf+($i-1)*$zGroupUsersInfo0)
        $tGroupName = DllStructCreate("wchar[256]", DllStructGetData($tGroupUsersInfo0,1))
    Next
    DllCall("Netapi32.dll", "int", "NetApiBufferFree", "ptr", $pBuf)
    Return $aRet
EndFunc;_NetUserGetGroups
It (sort of) works for me. The only thing you return is $aRet, which looks right. You are doing other processing (i.e. for $tGroupName), but I don't see the results of that going into $aRet, so what's it for? The group names seem to go in the struct $tGroupName, which gets overwritten with each name, and never gets returned.

Try this:

#include <Array.au3>

Global $sGroupNames; Receives struct with group names

Global $avRETURN = _NetUserGetGroups("UserName")
_ArrayDisplay($avRET, "Debug: $avRETURN")
$sGroupNames = StringTrimRight($sGroupNames, 2)
ConsoleWrite(@LF & "Final Groups = " & $sGroupNames & @LF)

Func _NetUserGetGroups($sUsername, $sServer = "")
    Local $tBufPtr = DllStructCreate("ptr")
    Local $ptBufPtr = DllStructGetPtr($tBufPtr)

    Local $tEntriesRead = DllStructCreate("dword")
    Local $ptEntriesRead = DllStructGetPtr($tEntriesRead)

    Local $tTotalEntries = DllStructCreate("dword")
    Local $ptTotalEntries = DllStructGetPtr($tTotalEntries)

    Local $aRet = DllCall("Netapi32.dll", "int", "NetUserGetGroups", _
            "wstr", $sServer, "wstr", $sUsername, "dword", 0, "ptr", $ptBufPtr, _
            "dword", -1, "ptr", $ptEntriesRead, "ptr", $ptTotalEntries)
    If $aRet[0] Then Return SetError(1, $aRet[0])

    Local $iEntriesRead = DllStructGetData($tEntriesRead, 1)

    Local $pBuf = DllStructGetData($tBufPtr, 1)

    Local $sGroupUsersInfo0 = "ptr"
    Local $tGroupUsersInfo0 = DllStructCreate($sGroupUsersInfo0)
    Local $zGroupUsersInfo0 = DllStructGetSize($tGroupUsersInfo0)
    Local $tGroupName
    For $i = 1 To $iEntriesRead
        $tGroupUsersInfo0 = DllStructCreate($sGroupUsersInfo0, $pBuf + ($i - 1) * $zGroupUsersInfo0)
        $tGroupName = DllStructCreate("wchar[256]", DllStructGetData($tGroupUsersInfo0, 1))
        $sGroupNames &= DllStructGetData($tGroupName, 1) & "; "
    Next
    DllCall("Netapi32.dll", "int", "NetApiBufferFree", "ptr", $pBuf)
    Return $aRet
EndFunc ;==>_NetUserGetGroups

(This kind of hall-of-mirrors stuff reminds me why I hate DLLs!)

:D

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

It (sort of) works for me. The only thing you return is $aRet, which looks right. You are doing other processing (i.e. for $tGroupName), but I don't see the results of that going into $aRet, so what's it for? The group names seem to go in the struct $tGroupName, which gets overwritten with each name, and never gets returned.

Try this:

#include <Array.au3>

Global $sGroupNames; Receives struct with group names

Global $avRETURN = _NetUserGetGroups("UserName")
_ArrayDisplay($avRET, "Debug: $avRETURN")
$sGroupNames = StringTrimRight($sGroupNames, 2)
ConsoleWrite(@LF & "Final Groups = " & $sGroupNames & @LF)

Func _NetUserGetGroups($sUsername, $sServer = "")
    Local $tBufPtr = DllStructCreate("ptr")
    Local $ptBufPtr = DllStructGetPtr($tBufPtr)

    Local $tEntriesRead = DllStructCreate("dword")
    Local $ptEntriesRead = DllStructGetPtr($tEntriesRead)

    Local $tTotalEntries = DllStructCreate("dword")
    Local $ptTotalEntries = DllStructGetPtr($tTotalEntries)

    Local $aRet = DllCall("Netapi32.dll", "int", "NetUserGetGroups", _
            "wstr", $sServer, "wstr", $sUsername, "dword", 0, "ptr", $ptBufPtr, _
            "dword", -1, "ptr", $ptEntriesRead, "ptr", $ptTotalEntries)
    If $aRet[0] Then Return SetError(1, $aRet[0])

    Local $iEntriesRead = DllStructGetData($tEntriesRead, 1)

    Local $pBuf = DllStructGetData($tBufPtr, 1)

    Local $sGroupUsersInfo0 = "ptr"
    Local $tGroupUsersInfo0 = DllStructCreate($sGroupUsersInfo0)
    Local $zGroupUsersInfo0 = DllStructGetSize($tGroupUsersInfo0)
    Local $tGroupName
    For $i = 1 To $iEntriesRead
        $tGroupUsersInfo0 = DllStructCreate($sGroupUsersInfo0, $pBuf + ($i - 1) * $zGroupUsersInfo0)
        $tGroupName = DllStructCreate("wchar[256]", DllStructGetData($tGroupUsersInfo0, 1))
        $sGroupNames &= DllStructGetData($tGroupName, 1) & "; "
    Next
    DllCall("Netapi32.dll", "int", "NetApiBufferFree", "ptr", $pBuf)
    Return $aRet
EndFunc;==>_NetUserGetGroups

(This kind of hall-of-mirrors stuff reminds me why I hate DLLs!)

:D

Strange, this code seems to function but it won't list local admin group if I specify build in admin account name.

It will return Absents.

I thought that this winapi function should work on both local and global group accounts.

I'll try to modify this code to work with NetUserGetLocalGroups and post it.

Thanks by the way for correcting my sloppy code.

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  
Followers 0