Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running a VB Script from a locally logged on PC

Status
Not open for further replies.

TreforG

IS-IT--Management
Jun 18, 2010
2
GB
Hi

I have a script that works as long as the PC/Laptop is logged on to our domain. However, I need certain users to be able to run the script from their PC/Laptop when not logged on to that domain.

Any ideas pleas?


Code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Const ADS_SECURE_AUTHENTICATION = 1

Dim objRoot, objDomain, objOU, objUser, objRootDSE
Dim strUser, strPassword
Dim strContainer, strLastUser, strDNSDomain, intAccValue

strAdminUser = "mydomain\vbs.admin"
strPassword = "P455W0RD"

Set objRoot = GetObject("LDAP:")
Set objDomain = objRoot.OpenDSObject("LDAP://dc=mydomain,dc=local",strAdminUser,strPassword,ADS_SECURE_AUTHENTICATION)

' Set the value to enable the account(S) [512 = Enable, 514 = Disable]
intAccValue = 512

' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' ~~~~~ Change OU= to reflect desired OU ~~~~~
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set objOU = GetObject("LDAP://ou=Exam Accounts,ou=Students,ou=Brookfield Users, dc=brookfield, dc=local")
For each objUser in objOU
If objUser.class="user" then
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' ~~~~~ Enable/disable users ~~~~~
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
objUser.Put "userAccountControl", intAccValue
objUser.SetInfo
End if
next

' End
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


 
your Set objDomain = call is using credentials to bind with
your Set objOU = call is not using credentials to bind with

my suggest would be you need to make your Set objOU call in such a way that it binds using credentials
 
Thanks for that. I've edited the script (below). It still works on a domain connected pc but not on a locally logged on laptop which returns the following Script Host error:

Error: The specified domain either does not exist or could not be contacted.
Code: 8007054B


Script:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Const ADS_SECURE_AUTHENTICATION = 1

Dim objRoot, objDomain, objOU, objUser, objRootDSE
Dim strUser, strPassword
Dim strContainer, strLastUser, strDNSDomain, intAccValue

strAdminUser = "brookfield\vbs.admin"
strPassword = "P455W0RD"

' Set the value to enable the account(S) [512 = Enable, 514 = Disable]
intAccValue = 512

' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' ~~~~~ Change OU= to reflect desired OU ~~~~~
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Set objRoot = GetObject("LDAP:")
set objOU = objRoot.OpenDSObject("LDAP://ou=Exam Accounts,ou=Students,ou=Brookfield Users,dc=brookfield,dc=local", _
strAdminUser,strPassword,ADS_SECURE_AUTHENTICATION)

For each objUser in objOU

If objUser.class="user" then

' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' ~~~~~ Enable/disable users ~~~~~
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
objUser.Put "userAccountControl", intAccValue
objUser.SetInfo

End if

next

' End


 
beg you pardon, you wiill need to supply the domain name in the query, you non domain client will not know about the OU;s or DC=

where strDC_FQDN with be the name of the domain? presuming the client can resolve the dns name to get a domain controller? or just put the FQDN of the domain controller to start off with

Call DisplayMsg ("GetDefault_SiteProperties: LDAP://" & strDC_FQDN & "/" & strBindDomain, False, True)
Set objTarget = adsNamespace.OpenDSObject("LDAP://" & strDC_FQDN & "/" & strBindDomain, strUsername, strPassword, 1)
strTemp = objTarget.Name
Set objTarget = Nothing
Call DisplayMsg ("GetDefault_SiteProperties:" & strTemp, False, True)
If strTemp = "" Then
Call DisplayMsg ("GetDefault_SiteProperties:unable to bind to domain " & "LDAP://" & strDC_FQDN & "/" & strBindDomain, False, True)
GetDefault_SiteProperties = False
Exit Function
End If
'
Set objTarget = adsNamespace.OpenDSObject("LDAP://" & strDC_FQDN & "/CN=" & strADSiteName & ",CN=Sites,CN=Configuration," & strBindDomain, strUsername, strPassword, 1)
strTemp = objTarget.Name
Call DisplayMsg ("GetDefault_SiteProperties:" & strTemp, False, True)
If strTemp = "" Then
Call DisplayMsg ("GetDefault_SiteProperties:unable to bind to target " & "LDAP://" & strDC_FQDN & "/" & strOU & "," & strBindDomain, False, True)
GetDefault_SiteProperties = False
Exit Function
End If
 
sorry, this goes first


Dim objTarget, adsNameSpace, strTemp
'
GetDefault_SiteProperties = False
'
Set adsNameSpace = GetObject("LDAP:")
 
dont tell me about the Exit Function statements, not very stylish i know, i think i am picking up bad habits from my chums in the sandals
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top