Page 1 of 1 1
Topic Options
#85114 - 2002-02-14 12:35 AM Add to Your ADSI Code Library
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
FYI

Here is a link over at 15seconds.com that shows many ADSI routines. There in VB, but many if not all can be converted to KiXtart.
http://www.15seconds.com/issue/020130.htm

Home Page is: http://www.15seconds.com/

Top
#85115 - 2002-02-16 09:30 PM Re: Add to Your ADSI Code Library
JensKalski Offline
Starting to like KiXtart

Registered: 2000-12-13
Posts: 186
Loc: Germany
Hi,
I've read the article and I think that there are two little errors:

In 1.1 I think it must be "For Each Domain in objNamespace"

In 2.4 I think it must be "Response.Write Computer.PasswordHistoryLength"

_________________________
Jens Kalski

Top
#85116 - 2002-02-24 08:32 AM Re: Add to Your ADSI Code Library
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Doc,

I think this is a more concise list -

ADSI FAQ

Here are these converted over.

Adding a User to a Group with ADSI

code:

$DomainString = "DomainName"
$UserString = "jdoe"
$GroupString = "GroupName"
$GroupObj = GetObject("WinNT://" + $DomainString + "/" + $GroupString)
$GroupObj.Add ("WinNT://" + $DomainString + "/" + $UserString)
$DomainObj = ""
$GroupObj = ""

Adding a Domain User to a Group with ADSI

code:

$PdcName = "ComputerName"
$ComputerName = "ComputerName"
$UserString = "jdoe"
$GroupString = "GroupName"
$GroupObj = GetObject("WinNT://" + $ComputerName + "/" $ $GroupString)

$GroupObj.Add ("WinNT://" + PdcName + "/" + UserString)
$DomainObj = ""
$GroupObj = ""


Changing passwords with ADSI

code:

$UserObj = GetObject("WinNT://ComputerName/UserName")
$UserObj.ChangePassword "oldpassword", "newpassword"
$UserObj.SetInfo
$UserObj = ""

Changing a User's Description with ADSI

code:

$UserObj = GetObject("WinNT://ComputerName/UserName")
$UserObj.Description = "New Description"
$UserObj.SetInfo
$UserObj = ""

Confirming a Password Change with ADSI

code:

On @Error Resume Next

$UserObj = GetObject("WinNT://ComputerName/UserName")
$UserObj.ChangePassword "oldpassword", "newpassword"
$UserObj.SetInfo
$UserObj = ""

If @Error = 0
? "Password Change Failed"
Else
? "Password Change Was Successful"
Endif


Creating a Share with ADSI

code:

$FservObj = GetObject("WinNT://ComputerName/lanmanserver")

$newshare = $FservObj.create("fileshare","test")
$newshare.path = "C:\temp"
$newshare.setinfo
$newshare = ""


Creating a User with ADSI

code:

$DomainObj = GetObject("WinNT://Domain")
$UserObj = $DomainObj.Create("user", "jdoe")
$UserObj.SetInfo
$UserObj = ""

Deleting a Group from a Domain

code:

$DomainString = "Domain"
$GroupString = "Group"
$DomainObj = GetObject("WinNT://" + $DomainString)
$DomainObj.Delete("group", $GroupString)
$DomainObj = ""

Delete a Share using ADSI

code:

$fserv = GetObject("WinNT://ComputerName/lanmanserver")
$fserv.delete "fileshare","test"

Deleting a User from a Domain with ADSI

code:

$DomainString = "Domain"
$UserString = "jdoe"
$DomainObj = GetObject("WinNT://" + $DomainString)
$DomainObj.Delete("user", $UserString)
$DomainObj = ""

Disabling an Account with ADSI

code:

$UserObj = GetObject("WinNT://ComputerName/UserName")
$UserObj.AccountDisabled = "True"
$UserObj.SetInfo
$UserObj = ""

Displaying Domains with ADSI

code:

$NameSpaceObj = GetObject("WinNT:")
$NameSpaceObj.Filter = Array("domain")

For Each $DomObj in $NameSpaceObj
?$DomObj.Name + "," + $DomObj.Class
next


Displaying Groups with ADSI

code:

$DomainString = "DOMAINNAME"
$DomainObj = GetObject("WinNT://" + $DomainString)
$DomainObj.Filter = Array("group")

For Each $GroupObj In $DomainObj
If $GroupObj.Class = "Group"
$List = $List + $GroupObj.Name
EndIf

Next

? List
$DomainObj = ""
$GroupObj = ""


Displaying Groups of a User with ADSI

code:

$DomainString="ComputerName"
$UserString = "jdoe"

$UserObj = GetObject("WinNT://" + $DomainString + "/" + $UserString)

For $Each GroupObj In $UserObj.Groups
$List = $List + $GroupObj.Name
Next

? $List

$UserObj = ""
$GroupObj = ""


Getting the Users of a Group

code:

$DomainString="ComputerName"
$GroupString = "GroupName"
$GroupObj = GetObject("WinNT://" + $DomainString + "/" + $GroupString)
For each $UserObj in $GroupObj.Members
$List = $List + $UserObj.Name
Next
? $List

Renaming a user/b]

code:

$oDomain = GetObject("WINNT:\\DOMAIN")
$oUser = $oDomain.GetObject("user", "Logon ID")
$oDomain.MoveHere $oUser.AdsPath, "New Logon ID"

[b]Setting a User's Account Expiration with ADSI/b]

code:

$UserObj = GetObject("WinNT://ComputerName/UserName")
$UserObj.AccountExpirationDate = @DATE + " " + @TIME
$UserObj.SetInfo
$UserObj = ""

[b]Setting a User's Home Directory with ADSI

code:

$UserObj = GetObject("WinNT://ComputerName/UserName")
$UserObj.put "HomeDirectory", "Directory Path"
$UserObj.put "HomeDirDrive", "H:"
$UserObj.SetInfo
$UserObj = ""

Setting Password Expiration with ADSI

code:

$UserObj = GetObject("WinNT://ComputerName/UserName")
$UserObj.Put "PasswordExpired", "1"
$UserObj.SetInfo
$UserObj = ""

Setting a Required Password with ADSI

code:

$UserObj = GetObject("WinNT://ComputerName/UserName")
$UserObj.PasswordRequired = "True"
$UserObj.SetInfo
$UserObj = ""

Setting a User's Login Script with ADSI

code:

$UserObj = GetObject("WinNT://ComputerName/UserName")
$UserObj.LoginScript = "Login script file name"
$UserObj.SetInfo
$UserObj = ""

Setting a User's Full Name with ADSI

code:

$UserObj = GetObject("WinNT://ComputerName/UserName")
$UserObj.FullName = "John Doe"
$UserObj.SetInfo
$UserObj = ""

Setting a User's Profile with ADSI

code:

$UserObj = GetObject("WinNT://ComputerName/UserName")
$UserObj.Profile = "New Profile Path"
$UserObj.SetInfo
$UserObj = ""

Starting an NT service
How do I start the browser service using ADSI?

code:

$BrowserServiceObj = GetObject("WinNT://ComputerName/browser")
$BrowserServiceObj.start
$BrowserServiceObj = ""

Stopping an NT serviceb
How do I stop the messenger service using ADSI?

code:

$MessengerServiceObj = GetObject("WinNT://ComputerName/messenger")
$MessengerServiceObj.stop
$MessengerServiceObj = ""

Realizing there are more on the page referenced above, these should be pretty easy to convert over to KIX.

Not really into ADSI, well here are some for WMI FAQ.

Thanks!

- Kent

[ 24 February 2002: Message edited by: kdyer ]

_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#85117 - 2002-02-26 11:43 AM Re: Add to Your ADSI Code Library
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
Kent, great post. I have almost the same routines in my user creation web page

Something I use:

If you only want to do 1 thing to an object, you can shortcut by doing this

before

code:

$MessengerServiceObj = GetObject("WinNT://ComputerName/messenger")$MessengerServiceObj.stop$MessengerServiceObj = ""

after

code:

GetObject("WinNT://ComputerName/messenger").stop

By not creating an object reference variable, you don't have to delete it afterwards. It does remove a level of error checking though, but generally the error code you get from this will let you know what is failing.

my AUD 0.02

cj

Top
Page 1 of 1 1


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

Who's Online
0 registered and 2312 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.056 seconds in which 0.029 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