Page 2 of 2 <12
Topic Options
#92420 - 2003-07-12 09:14 PM Re: Connecting to AD using different user credentials
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I was not considering SU and task scheduler. I have previously suggested using OpenDsObject but redbird seems to want to use an ADO query. It would seem that we should be able to authenticate with the OPEN method. My first attempt failed but I am going to try again.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92421 - 2003-07-12 10:37 PM Re: Connecting to AD using different user credentials
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Something along these lines:
code:
$oConnect = CreateObject("ADODB.Connection")
$oConnect.Provider = "ADsDSOObject"
$oConnect.Properties("User ID") = $stUser
$oConnect.Properties("Password") = $stPass
$oConnect.Properties("Encrypt Password") = not 0
$oConnect.Open "DS Query", $stUser, $stPass

Adapted from Searching with ActiveX Data Objects (ADO)
_________________________
There are two types of vessels, submarines and targets.

Top
#92422 - 2003-07-13 04:56 AM Re: Connecting to AD using different user credentials
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Jens, I am using 4.21 and have tried that syntax without success. Can you or someone else actually confirm some working code along these lines?


Break ON
$previousstate = SetOption( "WrapAtEOL", "ON" )

; Create the connection and command object.
$oConnection1 = CreateObject("ADODB.Connection")
? "@error @serror"
$oCommand1 = CreateObject("ADODB.Command")
? "@error @serror"

; Open the connection.
$oConnection1.Provider = "ADsDSOObject" ; This is the ADSI OLE-DB provider name
? "@error @serror"
$oConnection1.Properties("Password") = "ABC123xyz"
? "@error @serror"
$oConnection1.Properties("Encrypt Password") = not 0
? "@error @serror"
$oConnection1.Properties("User ID") = "domain\user1"
? "@error @serror"
$oConnection1.Open ("Active Directory Provider", "tycoelectronics\us035355", "ABC123xyz")
? "@error @serror"

; Create a command object for this connection.
$oCommand1.ActiveConnection = $oConnection1
? "@error @serror"

; Compose a search string.
$oCommand1.CommandText = "select name, objectClass from 'LDAP://us-tyco-e/DC=us,DC=tycoelectronics,DC=com' " +
"WHERE objectClass='user'" ; and objectClass<>'computer'"

; Execute the query.
$rs = $oCommand1.Execute
? "ex: @error @serror"


Result:

c:\data\scripts>C:\Data\Kix2001\KiX2001.421\kix32 test2.kix

0 The operation completed successfully.
0 The operation completed successfully.
0 The operation completed successfully.Password
ERROR : unexpected command!
Script: c:\data\scripts\test2.kix
Line : 13

[ 13. July 2003, 04:59: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92423 - 2003-07-13 05:10 AM Re: Connecting to AD using different user credentials
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
obviously the error comes from:
$oConnection1.Properties("Password") = "ABC123xyz"

now, can kixtart even do what you want here?
"properties" is a collection of properties...
but can kixtart point to the pasword property and set the pass.
thinking here but can't think of succesfull example
_________________________
!

download KiXnet

Top
#92424 - 2003-07-13 05:15 AM Re: Connecting to AD using different user credentials
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I think Shawn was pondering this type of syntax previously, but I can't remember what the topic was about.

[ 13. July 2003, 13:51: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92425 - 2003-07-13 05:17 AM Re: Connecting to AD using different user credentials
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
The $x.Properties("PropName") seems like it should be redundant since the OPEN method permits the use of a user and password as well. I have tried the code without the $x.Preoperties("") lines without success.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92426 - 2003-07-13 05:33 AM Re: Connecting to AD using different user credentials
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
indeed, new kixforms has (at least planned [i haven't tested]) object collections...

anyway, some times kix can give error on wrong line.
even though previous line shows error as 0 the error can be there too.

do you have any place I can read about these ado things?
any linky for quick ref?
_________________________
!

download KiXnet

Top
#92427 - 2003-07-13 01:55 PM Re: Connecting to AD using different user credentials
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
The best place would http://msdn.microsoft.com. There is also a reference to it in the ADSI SDK documentation.

I know this isn't the quick link you requested but you may be able to find the correct page that eluded me by searching.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92428 - 2003-07-13 08:41 PM Re: Connecting to AD using different user credentials
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
This might be of help:

Microsoft OLE DB Provider for Microsoft Active Directory Service in combinations with a SQL query through the DBCommand() UDF maybe?
_________________________
There are two types of vessels, submarines and targets.

Top
#92429 - 2003-07-14 09:21 AM Re: Connecting to AD using different user credentials
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Misc information.

You cannot specify credentials in a WMI Moniker. Monikers are used with VBScript GetObject function. To specify credentials, you must use VBScript's CreateObject function in combination with the WMI Scripting Library's "WbemScripting.SWbemLocator" object. SWbemLocator provides a single method named ConnectServer that accepts alternate credentials

There are two ways to connect to WMI - GetObject("winmgmts:") and CreateObject("WbemScripting.SWbemLocator"). You must use the latter if you want to supply alternate credentials

ALSO - Other method
'----Binding to a domain with alternate credentials
Set dso = GetObject("WinNT:")
Set dom = dso.OpenDSObject("WinNT://" & domainName, userName, password, ADS_SECURE_AUTHENTICATION)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netdir/adsi/ads_authentication_enum.asp

[ 14. July 2003, 09:23: Message edited by: NTDOC ]

Top
#92430 - 2003-07-14 03:19 PM Re: Connecting to AD using different user credentials
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
The SWbemLocator/ConnectServer method is illustrated in fnWMIAuthentication() - Authenticates against a local or remote WMI provider
_________________________
There are two types of vessels, submarines and targets.

Top
#92431 - 2003-07-18 05:17 PM Re: Connecting to AD using different user credentials
redbird Offline
Fresh Scripter

Registered: 2002-06-26
Posts: 10
Loc: Illinois State University - No...
Jens,

Could you give me an example of how I would apply your function to this application? I am a bit confused on where I would use this. I have a kix script that can call another script, but would kix32 be the application that would run under the other credentials?

Top
Page 2 of 2 <12


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 507 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.061 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org