Solved

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
video playback resume on webpages 2 82
ColdFusion Rereplace 3 87
Run a Radio Station (Streaming media) with web interface 10 51
Code Coverage and Coding Standards 2 46
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…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

756 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