Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using a form button with VBScript to delete a computer account in Active Directory

Posted on 2003-11-25
4
Medium Priority
?
625 Views
Last Modified: 2011-09-20
I have a VBScript called on a web page to delete a computer from our Active Directory site. The script portion works great in a stand-alone VBS file. But no such luck using this method from a web page though. Any ideas? FYI Permission is not the issue... running both from same machine.


Script Code:
<script language="VBScript">
<!--
Function Submit_OnClick
MsgBox "Delete command was accepted."
strComputer = "TESTCPU1"
Domain = "MIDWEST"

Set objComputer = GetObject("LDAP://CN=" & strComputer & ",CN=Computers,DC=" & Domain & ",DC=com")
objComputer.DeleteObject(0)

End Function
-->
</script>


Button/Form Code
  <form name="frm" method="post">
    <input type="submit" name="Submit" value="Delete from Active Directory">
  </form>
0
Comment
Question by:TWCMIL
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 7

Accepted Solution

by:
wsteegmans earned 1500 total points
ID: 9821741
Because we're dealing with an ASP page here, this means our page will be running under the Internet Guest Account. This Account is very unlikely to have permission to delete a computername, like in your case.

We must bind with an Alternate Credential. OpenDSObject will do this for us. The OpenDSObject method binds to an ADSI object, using the given credentials, and retrieves an IDispatch pointer on the specified object.

Try something like this (couldn't test it ...)

' bind to the ADSI object and authenticate Username and password

  Dim oADsObject
  Dim strADsNamespace
  Dim strADsPath
  Dim oADsNamespace

  strADsPath = "LDAP://CN=" & strComputer & ",CN=Computers,DC=" & Domain & ",DC=com"
  Set oADsObject = GetObject(strADsPath)

  strADsNamespace = left(strADsPath, instr(strADsPath, ":"))
  set oADsNamespace = GetObject(strADsNamespace)
  Set oADsObject = oADsNamespace.OpenDSObject(strADsPath, strUserName, strPassword, 0)

  ' we're only  bound if err.number = 0
  if not (Err.number = 0) then
    Response.Write "Failed to bind to object <b>" & strADsPath & "</b><br>"
    response.write err.description & "<p>"
    Response.write "Error number is " & err.number & "<br>"
  else
    objComputer.DeleteObject(0)
    Response.write "Computer " & strComputer & " deleted!"
  end if

0
 
LVL 1

Author Comment

by:TWCMIL
ID: 9943723
this doesn't do anything...
any other ideas?
0
 
LVL 1

Author Comment

by:TWCMIL
ID: 10077132
POINTS INCREASED TO 500 !! !! !!
0
 
LVL 1

Author Comment

by:TWCMIL
ID: 10817856
Any luck binding to the ADSI object?
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to count occurrences of each item in an array.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question