473,386 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Visual Basic 2008 and Active Directory computer descriptionmodifications

ok, it appears that i have run into a spot that i am not able to
figure out on my own. Let me first say that i have hobbled together
this SUB from things i found on the internet and tutorials. Here is my
issue...I can search AD for the description of the computer and
display it out but am unable to figure out if the

"
If dirEntry.Properties.Contains("description") Then
dirEntry.Properties("description")(0) = "Turek, Brett
- Dell Laptop - Modified by VB program"
Else
dirEntry.Properties("description").Add("Turek, Brett -
Dell Laptop - Modified by VB program")
End If
dirEntry.CommitChanges()
"

part will actually do what i want, change the description in AD of the
computer. Can anyone look this over and let me know if i am on the
right path? How about some examples of how to change things in AD?

*******************
Complete Code:
*******************
Imports System
Imports System.Management
Imports System.Windows.Forms
Imports System.DirectoryServices

Public Sub Button5_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles Button5.Click
'Rename Machine
'SHELL("NETDOM RENAMECOMPUTER /NewName:" + TextBox3.Text + " /
UserD:domain\username /PasswordD:password /Force /Reboot:300")

'Rename Description
Dim userID = "Domain\username"
Dim password = "PASSWORD"
Dim dirEntry As New DirectoryEntry("LDAP://
OU=Computers,OU=Abingdon,OU=MAR,OU=Customer,DC=us, DC=company,DC=com",
userID, password)
Dim mySearcher As DirectorySearcher = New
DirectorySearcher(dirEntry)

mySearcher.Filter = String.Format("(CN=computerName)")
mySearcher.PropertiesToLoad.Add("cn")
mySearcher.PropertiesToLoad.Add("description")

Dim resEnt As SearchResult
resEnt = mySearcher.FindOne

If resEnt Is Nothing Then
MsgBox("User not found")
Else
MsgBox("Found: " +
resEnt.GetDirectoryEntry().Properties("cn").Value + " :: " +
resEnt.GetDirectoryEntry().Properties("description ").Value)
If dirEntry.Properties.Contains("description") Then
dirEntry.Properties("description")(0) = "Turek, Brett
- Dell Laptop - Modified by VB program"
Else
dirEntry.Properties("description").Add("Turek, Brett -
Dell Laptop - Modified by VB program")
End If
dirEntry.CommitChanges()

MsgBox(resEnt.GetDirectoryEntry().Properties("desc ription").Value)
End If
End Sub
Oct 2 '08 #1
2 6573
Brett,

I am not sure what you try to achieve.

The directory.service is for your active directory
http://msdn.microsoft.com/en-us/libr...58(VS.85).aspx

The my class (my.computer my.user) a special VB class is

for your computer

http://msdn.microsoft.com/en-us/libr...12(VS.80).aspx
http://msdn.microsoft.com/en-us/libr...hw(VS.80).aspx

Cor
"brett" <pl*********@gmail.comschreef in bericht
news:ad**********************************@i76g2000 hsf.googlegroups.com...
ok, it appears that i have run into a spot that i am not able to
figure out on my own. Let me first say that i have hobbled together
this SUB from things i found on the internet and tutorials. Here is my
issue...I can search AD for the description of the computer and
display it out but am unable to figure out if the

"
If dirEntry.Properties.Contains("description") Then
dirEntry.Properties("description")(0) = "Turek, Brett
- Dell Laptop - Modified by VB program"
Else
dirEntry.Properties("description").Add("Turek, Brett -
Dell Laptop - Modified by VB program")
End If
dirEntry.CommitChanges()
"

part will actually do what i want, change the description in AD of the
computer. Can anyone look this over and let me know if i am on the
right path? How about some examples of how to change things in AD?

*******************
Complete Code:
*******************
Imports System
Imports System.Management
Imports System.Windows.Forms
Imports System.DirectoryServices

Public Sub Button5_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles Button5.Click
'Rename Machine
'SHELL("NETDOM RENAMECOMPUTER /NewName:" + TextBox3.Text + " /
UserD:domain\username /PasswordD:password /Force /Reboot:300")

'Rename Description
Dim userID = "Domain\username"
Dim password = "PASSWORD"
Dim dirEntry As New DirectoryEntry("LDAP://
OU=Computers,OU=Abingdon,OU=MAR,OU=Customer,DC=us, DC=company,DC=com",
userID, password)
Dim mySearcher As DirectorySearcher = New
DirectorySearcher(dirEntry)

mySearcher.Filter = String.Format("(CN=computerName)")
mySearcher.PropertiesToLoad.Add("cn")
mySearcher.PropertiesToLoad.Add("description")

Dim resEnt As SearchResult
resEnt = mySearcher.FindOne

If resEnt Is Nothing Then
MsgBox("User not found")
Else
MsgBox("Found: " +
resEnt.GetDirectoryEntry().Properties("cn").Value + " :: " +
resEnt.GetDirectoryEntry().Properties("description ").Value)
If dirEntry.Properties.Contains("description") Then
dirEntry.Properties("description")(0) = "Turek, Brett
- Dell Laptop - Modified by VB program"
Else
dirEntry.Properties("description").Add("Turek, Brett -
Dell Laptop - Modified by VB program")
End If
dirEntry.CommitChanges()

MsgBox(resEnt.GetDirectoryEntry().Properties("desc ription").Value)
End If
End Sub
Oct 2 '08 #2
I found this article that helped a little.

http://www.experts-exchange.com/Prog..._21699772.html

My new SUB looks like this and it works:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
'Rename Machine
'SHELL("NETDOM RENAMECOMPUTER /NewName:" + TextBox3.Text + " /
UserD:domain\username /PasswordD:password /Force /Reboot:300")

Try
'Rename Description
Dim userID = "domain\username"
Dim password = "password"
Dim dirEntry As New DirectoryEntry("LDAP://
OU=Computers,OU=Abingdon,OU=MAR,OU=Customer,DC=us, DC=company,DC=com",
userID, password)
Dim mySearcher As DirectorySearcher = New
DirectorySearcher(dirEntry)

mySearcher.Filter = String.Format("(CN=computerName)")
mySearcher.PropertiesToLoad.Add("cn")
mySearcher.PropertiesToLoad.Add("description")

Dim resEnt As SearchResult
resEnt = mySearcher.FindOne()

If resEnt Is Nothing Then
MsgBox("Computer not found")
Else
MsgBox("Found: " +
resEnt.GetDirectoryEntry().Properties("cn").Value + " :: " +
resEnt.GetDirectoryEntry().Properties("description ").Value)
'dirEntry.Properties("description").Add("Turek, Brett
- Dell Laptop - Modified by VB program")
'dirEntry.CommitChanges()

'echo out after changes - doesnt work
'MsgBox("Change1: " +
resEnt.GetDirectoryEntry().Properties("description ").Value)

'new commit change works
Dim newComputerDesc =
dirEntry.Children.Find("CN=computerName", "computer")
newComputerDesc.Properties("description").Value =
"Turek, Brett - Dell Laptop"
newComputerDesc.CommitChanges()

'echo out after changes
'MsgBox("Change2: " +
resEnt.GetDirectoryEntry().Properties("description ").Value)
End If
Catch generatedExceptionName As Exception
MsgBox(generatedExceptionName)
End Try
End Sub
Oct 2 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kenneth Keeley | last post by:
Hi, I have been working on a Login page that uses ADSI to authenicate the users. I had this all working on my test system and on a second system connected to the live domain. Now it will only work...
0
by: RTT | last post by:
here is my current situation. I develop a program on my computer's localhost. From there i contact Active directory succesfull using a connectionstring like:...
2
by: Robert Mileski | last post by:
I've made some program in Visual Basic 2005 that works with changing files and folders. After I've finished it, the main problem is to refresh the Windows OS. I mean the same thing as when we press...
97
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
1
by: pauloetiago | last post by:
Hello!! We are Paulo and Tiago, two portugueses students. We need to create an application which connect the Visual Basic and the Active Directory. Can you help us in that work? We need the code...
1
by: =?Utf-8?B?Rmxhbm1hbg==?= | last post by:
I have a tutorial I was working on with Visual Web Developer 2005 express. Very basic stuff intro to asp.net. All was working fine a few days ago. I took my pc home and installed the visual studion...
6
by: Miro | last post by:
I can run an exe ( and its install ) i have created on my machine. The exe has a button that populates a dataset and then shoots it to a crystal report. But... Installing the setup.exe on my...
4
by: Miro | last post by:
<i have also added this reply to the other newsgroup - now that I have realizd ( and assuming ) it is not a localized error directly to vb.> I have found this link on the website:...
0
jwwicks
by: jwwicks | last post by:
Introduction This tutorial describes how to use Visual Studio to create a new C++ program, compile/run a program, resume work on an existing program and debug a program. It is aimed at the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.