Jump to content

DllCall() way of thinking


Recommended Posts

I am trying to figure out how the use DllCall().

The sample below makes me wonder how en where to start.

First thing is that I dont know what dll functions there are available, probably pretty much .. .. Now how do I find a function that I can use? When I know of the existence of a function how do I implement it, looking at the sample var $result is build up complex. How the heck do I know what to put in there?

; Example 1 - calling the MessageBox API directly
$result = DllCall("user32.dll", "int", "MessageBox", "hwnd", 0, "str", "Some text", "str", "Some title", "int", 0)

; Example 2 - calling a function that modifies parameters
$hwnd = WinGetHandle("Untitled - Notepad")
$result = DllCall("user32.dll", "int", "GetWindowText", "hwnd", $hwnd, "str", "", "int", 32768)
msgbox(0, "", $result[0]); number of chars returned
msgbox(0, "", $result[2]); Text returned in param 2

Having explained my basic problem id like to explain why I think I need a DllCall. I am building a small program (my second_) that has to do some stuff whit local / domain groups en users accounts. I want to check states of ingroup members en add or remove local / global groups from accounts.

plz help meh :"> :(

Grtx Sno. The Novice Newbie.

Link to comment
Share on other sites

what states are you checking for?

Lar.

<{POST_SNAPBACK}>

I mean by that to check group population by other (user/group) objects.

Like " net localgroup administrators | findstr @username"

but then more advanced whitout having to use dos commands.

Hope this makes it more clear.

Grtx Sno. The Novice Newbie.

Link to comment
Share on other sites

building a small program (my second_) that has to do some stuff whit local / domain groups en users accounts. I want to check states of ingroup members en add or remove local / global groups from accounts.

Instead of using DllCall you could also use ADSI (Active Directory Service Interfaces). Here is some code. Check the MSDN URL for the API docu. It works on my machine, which is not part of a domain, but it should work as well for a request to a domain. Please check the several ADSI service providers at this URL MSDN - ADSI Page

; ADSI Samples by /dev/null
;

$domain = "YOUR COMPUTER NAME HERE" ; <<=== CHANGE THIS !!

;************************************************************
;** Get all ADSI objects from this machine
;************************************************************
$adsi_objs = ObjGet("WinNT://" & $domain & ",computer")
for $obj in $adsi_objs

  ;*********************************************************
  ;** If it is a user, then show it's name
  ;*********************************************************
   if $obj.Class = "User" then
      msgbox(4096,"","User: " & $obj.name) 
   endif

  ;*********************************************************
  ;** If it is a group, then show it's members
  ;*********************************************************
   if $obj.Class = "Group" then
      $allmembers = "All members of: " & $obj.name & @CRLF
      for $member in $obj.members
          $allmembers = $allmembers & $member.name & @CRLF
      next 
      msgbox(4096,"",$allmembers) 
   endif
next

;************************************************************
;** ADD a user to a group
;************************************************************
msgbox(4096,"","Adding User now")

$user = "Guest" ;  <=== CHANGE THIS !!
$group = "Administrators" ;  <=== CHANGE THIS !!

$group_obj = ObjGet("WinNT://" & $domain & "/" & $group)

; THIS WILL FAIL if user already member of group
$group_obj.Add ("WinNT://" & $domain & "/" & $user)

$allmembers = "All members of: " & $group_obj.name & @CRLF
for $member in $group_obj.members
    $allmembers = $allmembers & $member.name & @CRLF
next 
msgbox(4096,"",$allmembers) 

;************************************************************
;** REMOVE a user from a group
;************************************************************
msgbox(4096,"","Deleting user now...")

$group_obj = ObjGet("WinNT://" & $domain & "/" & $group)
$group_obj.Remove ("WinNT://" & $domain & "/" & $user)

$allmembers = "All members of: " & $group_obj.name & @CRLF
for $member in $group_obj.members
    $allmembers = $allmembers & $member.name & @CRLF
next 
msgbox(4096,"",$allmembers)

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Thx for this nice sample, its a good alternative. But i really want to build a exe, this is more pointing in the direction of vbs. And as it is, some computers are not yet compatible whit running vbs code.

Grtx Sno. The Novice Newbie.

Link to comment
Share on other sites

Thx for this nice sample, its a good alternative. But i really want to build a exe, this is more pointing in the direction of vbs. And as it is, some computers are not yet compatible whit running vbs code.

VBS code?? Maybe you got something wrong. This is pure AutoIT code, using the COM interface of windows, AND you can make an executable of it simply by compiling the script. See help file for compiling AU3 scripts.

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

:( I am sry, i wants paying attention. I keep getting distracted here and the use of COM did my mind wander of in the direction of vbs.

Grtx Sno. The Novice Newbie.

Link to comment
Share on other sites

:( I am sry, i wants paying attention.

No problem. Just run the script and you will see how it works within AutoIT. However, you will have to change the marked sections!!

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Guys!

Excuse my stupid ness but i still don t know where to start.

Can someone plz explain me how he or she develops a

piece of code that calls a APi function?

Edited by sno

Grtx Sno. The Novice Newbie.

Link to comment
Share on other sites

  • 6 months later...

results in

$adsi_objs = ObjGet("WinNT://" & $domain & ",computer")

$adsi_objs = ^ ERROR

Unknown function name.:

Can anyone please tell me why ?

You need the AutoIt beta version.

If you've already installed the beta, press Alt+F5 to run the script in SciTe

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...