Link to home
Start Free TrialLog in
Avatar of karephre
karephre

asked on

run vbscript with alternate credentials

Hello I use a local script to query my active directory. On the part that deletes a user or computer object. i would like that to run on administrator credentials.

I know how to set it up if I was using VB to run on a remote system, but cant figur out how to get it to run on a local one. with out doing run as admin.
Below is the part of my code I want to run under admin.

thanks experts

Public Function delMac(macName,macLoc)
On Error Resume Next 
Set objOU = GetObject("LDAP://"& macLoc &"")
objOU.Delete "user", "cn="& macName &""

End Function 

Public Function delCom(ComDn)
On Error Resume Next
	set objComputer = GetObject("LDAP://" & ComDn & "")
objComputer.DeleteObject (0)
	
End Function 

Open in new window

Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, you can use OpenDSObject.

      Const ADS_SECURE_AUTHENTICATION = 1
      Set objNS = GetObject("LDAP:")
      Set objOU = objNS.OpenDSObject("LDAP://" & macLoc, "test\admin", "password",ADS_SECURE_AUTHENTICATION)
        objOU.Delete "user", "cn=" & macName

Open in new window


Regards,

Rob.
Avatar of karephre
karephre

ASKER

Below is what I added to my code, and im getting object already exists. After the computers are deleted I create them again.

Public Function delMac(macName,macLoc)
On Error Resume Next 
Const ADS_SECURE_AUTHENTICATION = 1
Set objOU = GetObject("LDAP://"& macLoc ,"d.hot", "THer$#2",ADS_SECURE_AUTHENTICATION)
objOU.Delete "user", "cn="& macName &""

End Function 

Public Function delCom(ComDn)
On Error Resume Next
Const ADS_SECURE_AUTHENTICATION = 1
	set objComputer = GetObject("LDAP://" & ComDn ,"d.hot", "THer$#2",ADS_SECURE_AUTHENTICATION)
objComputer.DeleteObject (0)
	
End Function 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Work like a champ ... Thanks RobSampson
No problem. Thanks for the grade.

Rob.