Update Computer Description in AD with Domain credentials

I need a Vbscript that will allow me to add a description to a computer account in AD but it need to allow input of Domain credentials so the script can run on any computer on the domain without having to login as Domain Admin. HTA would be even better so our techs in the field have the ability to do this without calling in.
Marvinc1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobSampsonCommented:
Hi there, I just wrote this HTA that should do the job for you.  All you need to do is run it on the target computer, and enter your credentials.

Regards,

Rob.

<Html>
<Head>
<Title>Reset Computer Description</Title>
 
<HTA:Application
Caption = Yes
Border = Thick
ShowInTaskBar = Yes
SingleInstance = Yes
MaximizeButton = Yes
MinimizeButton = Yes>
 
<script Language = VBScript>

	Sub Window_OnLoad
		intWidth = 700
		intHeight = 350
		Me.ResizeTo intWidth, intHeight
		Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
		Set objADSysInfo = CreateObject("ADSystemInfo")
		Set objComputer = GetObject("LDAP://" & objADSysInfo.ComputerName)
		txt_currentdescription.Value = objComputer.description
 	End Sub

	Sub Exit_HTA
		Window.Close
	End Sub

	Sub Set_Computer_Description
		Set objADSysInfo = CreateObject("ADSystemInfo")
		Const ADS_SECURE_AUTHENTICATION = 1
		Const ADS_PROPERTY_CLEAR = 1 
		strComputer = "LDAP://" & objADSysInfo.GetAnyDCName & "/" & objADSysInfo.ComputerName
		Set objRootDSE = GetObject("LDAP:")
		Set objSysInfo = CreateObject("ADSystemInfo")
		On Error Resume Next
		Set objComputer = objRootDSE.OpenDSObject(strComputer, txt_username.Value, txt_password.Value, ADS_SECURE_AUTHENTICATION)
		If Err.Number = -2147023570 Then
			MsgBox "Invalid username or password."
		Else
			On Error Resume Next
			If txt_newdescription.value <> "" Then
				objComputer.description = txt_newdescription.value
			Else
				objComputer.PutEx ADS_PROPERTY_CLEAR, "description", 0
			End If
			objComputer.SetInfo
			If Err.Number = 0 Then
				MsgBox "Computer description updated."
			Else
				MsgBox "Error " & Err.Number & ": " & Err.Description
				Err.Clear
			End If
		End If
		Err.Clear
		On Error GoTo 0
	End Sub

</script>
<body style="background-color:#B0C4DE;">
	<table width= "90%" border="0" align="center">
		<tr>
			<td align="center" colspan="2">
				<h2>Reset Computer Description</h2>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				Enter credentials with permissions to change the computer description:
			</td>
		</tr>
		<tr>
			<td>
				Username:
			</td>
			<td>
				<input type="text" id="txt_username" name="txt_username" size="50">
			</td>
		</tr>
		<tr>
			<td>
				Password:
			</td>
			<td>
				<input type="password" id="txt_password" name="txt_password" size="20">
			</td>
		</tr>
		<tr>
			<td>
				Current computer description:
			</td>
			<td>
				<input type="text" id="txt_currentdescription" name="txt_currentdescription" size="50" readonly>
			</td>
		</tr>
		<tr>
			<td>
				Enter new computer description:
			</td>
			<td>
				<input type="text" id="txt_newdescription" name="txt_newdescription" size="50">
			</td>
		</tr>
		<tr>
			<td align="center" colspan="2">
				<br>
				<button name="btn_setdescription" id="btn_setdescription" accessKey="s" onclick="vbs:Set_Computer_Description"><u>S</u>et Description</button>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<button name="btn_exit" id="btn_exit" accessKey="x" onclick="vbs:Exit_HTA">E<u>x</u>it</button><br>
			</td>
		</tr>
	</table>
</body>
</head>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.