• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 628
  • Last Modified:

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
0
Rodders1000
Asked:
Rodders1000
  • 3
  • 3
1 Solution
 
morpheiosCommented:
  
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") = "TRUE" Then
  objRegistry.RegWrite "HKCU\Software\Microsoft\Communicator\AutoRunWhenLogonToWindows", 1, "REG_DWORD" 
End if 
if oUser.Get("msRTCSIP-Userenabled") = "FALSE" Then
  objRegistry.RegWrite "HKCU\Software\Microsoft\Communicator\AutoRunWhenLogonToWindows", 0, "REG_DWORD"
End if 
wscript.quit

Open in new window

0
 
morpheiosCommented:
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
0
 
Rodders1000Author Commented:
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 :(
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Rodders1000Author Commented:

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

0
 
morpheiosCommented:
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.
0
 
Rodders1000Author Commented:
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
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now