Solved

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

Posted on 2003-11-25
4
617 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

760 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now