Solved

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

Posted on 2003-11-25
4
620 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
  • 3
4 Comments
 
LVL 7

Accepted Solution

by:
wsteegmans earned 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
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…
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

839 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