Link to home
Start Free TrialLog in
Avatar of Rodders1000
Rodders1000Flag for United Kingdom of Great Britain and Northern Ireland

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\Software\Microsoft\Communicator]
"AutoRunWhenLogonToWindows"=dword:00000001

Else if msRTCSIP-Userenabled is FALSE then then run script2
[HKEY_CURRENT_USER\Software\Microsoft\Communicator]
"AutoRunWhenLogonToWindows"=dword:00000000

Thanks for any assistance
ASKER CERTIFIED SOLUTION
Avatar of morpheios
morpheios
Flag of Russian Federation 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
And if you dont want to use "adsysteminfo"

use
Set WshShell = WScript.CreateObject("WScript.Shell")
user = WshShell.ExpandEnvironmentStrings("%USERNAME%")

Open in new window


but first code better
Avatar of Rodders1000

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 :(

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

Open in new window

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.
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