Jump to content
Sign in to follow this  
water

Call a COM method with argument set to NULL

Recommended Posts

water

I use OpenDSObject to connect to the Active Directory. OpenDSObject needs the DC, username, password and flags as parameters.

According to Microsoft "The IADsOpenDSObject method uses the default credentials when UserName and Password are set to NULL."

How can I set a parameter to NULL?

I searched the forum but all threads talk about DLLCall and neither of the solutions works. I tried "DEFAULT" , "", 0, 0x0 but always get an error message (Default gives 8002000F - parameter not optional, all other give 80020009 - Invalid username or password).

I would be gratefull for any suggestions!

Global $objDSO = ObjGet("LDAP:")
Const $ADS_SERVER_BIND= 512
Global $username = "Domain\user"
Global $username = "password"
$obj1 = $objDSO.OpenDSObject("LDAP://DC.microsoft.com", $username, $password, $ADS_SERVER_BIND)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
PsaltyDS

I don't know why "" doesn't work for null.

But if you do provide the username, doesn't it need to be like this?

Global $username = "cn=user,ou=users,dc=microsoft,dc=com"

:blink:


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
ProgAndy

I think the correct value would be Ptr(0), but up to now AutoIt doesn't support Pointers as COM-Parameters. This means, you can't skip username and password.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
SmOke_N

DaleHohm came up with a method using ScriptControl for NULL.

Went something like:

Global $o_vb_null = ObjCreate("ScriptControl")
$o_vb_null.language = "VBScript"
Global Const $NULL = $o_vb_null.eval("vbNullString")
$o_vb_null = 0

Then you use $NULL where you need to.


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.

Share this post


Link to post
Share on other sites
DaleHohm

Here's a pointer to my writeup on this: http://www.autoitscript.com/forum/index.php?showtopic=64966&st=0&p=483555&hl=nothing&fromsearch=1&#entry483555

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
water

Hi guys,

thanks a lot for the fast answers!

I will have a look at them as soon as I find some spare time and post thre results.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Richard Robertson

I don't know why "" doesn't work for null.

I am ashamed at you. You're an experienced user and should know the difference between null and an empty string.

Share this post


Link to post
Share on other sites
trancexx

This works for me:

Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")


Const $ADS_SERVER_BIND = 512

$sUserName = "" 
$sPassword = ""  

$objDSO = ObjGet("WinNT:")
$oObject = $objDSO.OpenDSObject("WinNT://localhost/Administrators", $sUserName, $sPassword, $ADS_SERVER_BIND)

ConsoleWrite("ADsPath:" & $oObject.ADsPath & @CRLF)
ConsoleWrite("Class:" & $oObject.Class & @CRLF)
ConsoleWrite("GUID:" & $oObject.GUID & @CRLF)
ConsoleWrite("Name:" & $oObject.Name & @CRLF)
ConsoleWrite("Parent:" & $oObject.Parent & @CRLF)
ConsoleWrite("Schema:" & $oObject.Schema & @CRLF)

ConsoleWrite("-------------------" & @CRLF)

$sUserName =  "trancexx"
$sPassword =  "MyRealPassword"

$objDSO = ObjGet("WinNT:")
$oObject = $objDSO.OpenDSObject("WinNT://localhost/Administrators", $sUserName, $sPassword, $ADS_SERVER_BIND)

ConsoleWrite("ADsPath:" & $oObject.ADsPath & @CRLF)
ConsoleWrite("Class:" & $oObject.Class & @CRLF)
ConsoleWrite("GUID:" & $oObject.GUID & @CRLF)
ConsoleWrite("Name:" & $oObject.Name & @CRLF)
ConsoleWrite("Parent:" & $oObject.Parent & @CRLF)
ConsoleWrite("Schema:" & $oObject.Schema & @CRLF)



Func _ErrFunc()
    ConsoleWrite("! COM Error !  Number: 0x" & Hex($oError.number, 8) & "   ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF)
EndFunc

Same results both for ("", "") and ("trancexx", "MyRealPassword"). Other random stuff produces errors.

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
PsaltyDS

This works for me:

; ...

$objDSO = ObjGet("WinNT:")
$oObject = $objDSO.OpenDSObject("WinNT://localhost/Administrators", $sUserName, $sPassword, $ADS_SERVER_BIND)

;...
Same results both for ("", "") and ("trancexx", "MyRealPassword"). Other random stuff produces errors.
I think the issue is related to using the LDAP provider, and MSDN specifically warns against using .OpenDSObject() with the WinNT provider:

Important: It is not recommended that you use this method with the WinNT Provider. For more information, please see KB article 218497, User Authentication Issues with the Active Directory Service Interfaces WinNT Provider.

I am ashamed at you. You're an experienced user and should know the difference between null and an empty string.

I can live with that, 'cause I'm still so pretty!

:blink:

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
water

Thanks a lot for all the hints!

After re-thinking my requirements I was able to eliminate the need for NULL in the OpenDSObject call ;)

But again, thank you very much for your efforts!

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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  

×