Solved

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

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jquery validation by class 12 52
CSS Question.. 3 87
Lines Not Lining Up 2 70
php mysql check email already in database. (second check) 7 30
Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

809 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