Rodders1000
asked on
Using an environment variable to query AD in VBS
HI there I would like a VBS script to turn off the auto start for office communitor on a standard build by using the users AD attributes.I am not sure where to start but if someone can point me in the right direction that would be great,
I think this is the easiest way to do it automatically, is to....
Read the variable %username% and check for varable against the AD sAMAccountName attribute located in user objects in the AD.
From that object that matches the username and sAMAccount get attribute msRTCSIP-Userenabled attribute.
If msRTCSIP-Userenabled is TRUE then modify
[HKEY_CURRENT_USER\Softwar
"AutoRunWhenLogonToWindows
Else if msRTCSIP-Userenabled is FALSE then then run script2
[HKEY_CURRENT_USER\Softwar
"AutoRunWhenLogonToWindows
Thanks for any assistance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for that Morpheios,
I had to modify the objRegistry to be oRegistry, thats cool.
But the value from the attribute doesnt seem to come back correctly so when comparing the TRUE or FALSE it isnt sure what tot do and so does nothing :(
I had to modify the objRegistry to be oRegistry, thats cool.
But the value from the attribute doesnt seem to come back correctly so when comparing the TRUE or FALSE it isnt sure what tot do and so does nothing :(
ASKER
OK I have echo'd out the results and the values returned are
TRUE = -1
FALSE = 0
I have altered your code to reflect this and it works fab. See attached.
Now why would I not want to use adsysteminfo ? Does this have ADSI as a pre req ?
Dim adsinfo, oUser, oShell, oRegistry
Set oRegistry = CreateObject("Wscript.shell")
Set adsinfo = CreateObject("adsysteminfo")
Set oUser = GetObject("LDAP://" & adsinfo.UserName)
if oUser.Get("msRTCSIP-Userenabled") = -1 Then
oRegistry.RegWrite "HKCU\Software\Microsoft\Communicator\AutoRunWhenLogonToWindows", 1, "REG_DWORD"
End if
if oUser.Get("msRTCSIP-Userenabled") = 0 Then
oRegistry.RegWrite "HKCU\Software\Microsoft\Communicator\AutoRunWhenLogonToWindows", 0, "REG_DWORD"
End if
wscript.quit
Sorry. My domain hasnt "msRTCSIP-Userenabled" properties, so i cant test script.
Dont warry. No problem with "adsysteminfo". Any domain computer has this object and its work correctly. I sad about that only becouse you ask about "environments variables" - only show how expand such variables in VBS.
Dont warry. No problem with "adsysteminfo". Any domain computer has this object and its work correctly. I sad about that only becouse you ask about "environments variables" - only show how expand such variables in VBS.
ASKER
Thanks for such a great response. I wasn't expecting someone to write the code for me !!!!
Save me days finding out how to do this and now I understand it my self.
Thanks again
Save me days finding out how to do this and now I understand it my self.
Thanks again
use
Open in new window
but first code better