locked
Office Communicator 2005 sign-in name, auto populate after install somehow? RRS feed

  • Question

  • Does anyone know of a way to have the sign in name in communicator, auto filled in after an install or doing the install..

    Basically every user has the same format.. first.lastname@domain for the login.

    I'd prefer to find a way to have this info auto entered after the install when it first tries to open.

    I'll be using communicator as a "broadcast" method.. and alot of users probably wont take the time to enter their info when I have it set to auto start/connect on windows start up.

    Thanks

    Wednesday, February 7, 2007 9:59 PM

Answers

  • I've found a way to do this..

    Basically when the client gets installed.. I have a batch file.. It pulls the email address from AD and then uses that to create the registry entry for the sign in name.. Something like this (I may have to tweak this, havent fully tested it yet):

    This would be part of a .vbs file.. which gets run from a file, say called setup.bat (first line would be the email.vbs, second line the msiexec.exe command line to install communicator):

    xxxxxxxxxxxxxxxxxxxxxx

    Option Explicit
    'On Error Resume Next

    Dim objUser, objADSysInfo,test

    Set objADSysInfo = CreateObject("ADSystemInfo")
    Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)
    'WScript.Echo objUser.Mail

    'UserMicrosoft RTC Instant Messaging

    Dim WshShell
    Set WshShell=WScript.CreateObject("WScript.Shell")

    'test = WshShell.RegRead ("HKCU\Software\Microsoft\Communicator\UserMicrosoft RTC Instant Messaging")
    'Wscript.Echo test

    WshShell.RegWrite "HKCU\Software\Microsoft\Communicator\UserMicrosoft RTC Instant Messaging", objUser.Mail, "REG_SZ"
    xxxxxxxxxxxxxxxxxxx

    I also finally figured out how to use the wmi script with the resource kit to populate their contacts list and even add to groups.. now I'm struggling with how to make it create a contact in two groups simultaneously.. so far it appears to be only one group at a time (cant automatically put a contact in two groups at once, but it will work if the end user, manually copies it)...

     

     

    Monday, February 19, 2007 3:03 PM

All replies

  • I would be interested in this solution too. Communicator 2005 can pick out information from Active directory - why cant it pick out their sip name (or email address) too and so not bother the user for these credentials?
    Monday, February 19, 2007 1:22 PM
  • I've found a way to do this..

    Basically when the client gets installed.. I have a batch file.. It pulls the email address from AD and then uses that to create the registry entry for the sign in name.. Something like this (I may have to tweak this, havent fully tested it yet):

    This would be part of a .vbs file.. which gets run from a file, say called setup.bat (first line would be the email.vbs, second line the msiexec.exe command line to install communicator):

    xxxxxxxxxxxxxxxxxxxxxx

    Option Explicit
    'On Error Resume Next

    Dim objUser, objADSysInfo,test

    Set objADSysInfo = CreateObject("ADSystemInfo")
    Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)
    'WScript.Echo objUser.Mail

    'UserMicrosoft RTC Instant Messaging

    Dim WshShell
    Set WshShell=WScript.CreateObject("WScript.Shell")

    'test = WshShell.RegRead ("HKCU\Software\Microsoft\Communicator\UserMicrosoft RTC Instant Messaging")
    'Wscript.Echo test

    WshShell.RegWrite "HKCU\Software\Microsoft\Communicator\UserMicrosoft RTC Instant Messaging", objUser.Mail, "REG_SZ"
    xxxxxxxxxxxxxxxxxxx

    I also finally figured out how to use the wmi script with the resource kit to populate their contacts list and even add to groups.. now I'm struggling with how to make it create a contact in two groups simultaneously.. so far it appears to be only one group at a time (cant automatically put a contact in two groups at once, but it will work if the end user, manually copies it)...

     

     

    Monday, February 19, 2007 3:03 PM
  • Very useful - thanks. I did see a post somewhere that suggested running:

    reg add HKCU\Software\Microsoft\Communicator /v "UserMicrosoft RTC Instant Messaging" /t reg_sz /d "%username%@domain.com" /f > null

    But that doesnt work in our environment as Communicator 2005 expects the person's email address so your script works perfectly!

    Also I needed to add our domain to the access control list in communicator to allow all members of our firm to see availability and add other menbers of our firm to their lists without getting bothered by lots of prompts. The process is described here:

    http://msgoodies.blogspot.com/2006/03/populating-users-in-office.html

    I would have thought that this sort of thing would have been easier to do and manage, without the need for scripting - AD or the LCS server /farm or even group policy would be the obvious places. Oh well... maybe in the next version?!!

     

    Thanks again.

    Tuesday, February 20, 2007 4:55 PM
  •  Samlw wrote:

    Very useful - thanks. I did see a post somewhere that suggested running:

    reg add HKCU\Software\Microsoft\Communicator /v "UserMicrosoft RTC Instant Messaging" /t reg_sz /d "%username%@domain.com" /f > null

    But that doesnt work in our environment as Communicator 2005 expects the person's email address so your script works perfectly!

    Also I needed to add our domain to the access control list in communicator to allow all members of our firm to see availability and add other menbers of our firm to their lists without getting bothered by lots of prompts. The process is described here:

    http://msgoodies.blogspot.com/2006/03/populating-users-in-office.html

    I would have thought that this sort of thing would have been easier to do and manage, without the need for scripting - AD or the LCS server /farm or even group policy would be the obvious places. Oh well... maybe in the next version?!!

     

    Thanks again.

     

    You said to you needed to be able to allow other members to add others to their lists without prompts, I believe you can do so manually in the settings in the LCS snapin.. On the properties of an LCS user.. Allow/edit.. add.. "ALL" or something similar...

    So far the only real issue I'm having with our setup is Groups.. if I have/want one contact in both groups and I run two different scripts for each group, then that user only appears in one group or the other, the end user has to manually copy the user to the other group, for them to appear in both.

    The other issue is with Vista, as there is no remote assistance.. (and no remote assistance under more actions if using Presence information on Portal Intranet or in Office 2007).. I'm assuming with Communicator 2007 this will be fixed..

     

     

    Tuesday, February 20, 2007 10:05 PM
  •  

    I've also set this up in the batch file at install time as well (causes communicator to run right after install and the user gets logged in automatically):

    (No reboot required)

    At time of install I run this from my install batch file (call it.. something.vbs):

    Dim WshShell
    Set WshShell=WScript.CreateObject("WScript.Shell")

    WshShell.RegWrite "HKCU\Software\Microsoft\Communicator\AddToFirewallExceptionList", 0, "REG_DWORD"
    WshShell.RegWrite "HKCU\Software\Microsoft\Communicator\RTCState", 01000000, "REG_BINARY"

    Then in the same batch file at the end of the install I simply execute communicator via "start communicator" and instantly the user is signed in.

    Tuesday, February 27, 2007 10:33 PM
  • I have been doing something similar, except I also set a couple of other options - see below: Not too sure if they are necessary, but it appears to work quite nicely (except the user may need to log in twice before communicator runs at login, I could force it to run the first time, but we didnt really need it to)....

    Option Explicit
    Dim objUser, objADSysInfo,test
    Set objADSysInfo = CreateObject("ADSystemInfo")
    Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)
    Dim WshShell
    Set WshShell=WScript.CreateObject("WScript.Shell")
    WshShell.RegWrite "HKCU\Software\Microsoft\Communicator\UserMicrosoft RTC Instant Messaging", objUser.Mail, "REG_SZ"
    WshShell.RegWrite "HKCU\Software\Microsoft\Communicator\AutoRunWhenLogonToWindows", "1", "REG_DWORD"
    WshShell.RegWrite "HKCU\Software\Microsoft\Communicator\FirstTimeUser", "0", "REG_DWORD"
    WshShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Run\Communicator", """C:\Program Files\Microsoft Office Communicator\Communicator.exe""", "REG_SZ"
    WshShell.RegWrite "HKCU\Software\Microsoft\Communicator\AddToFirewallExceptionList", 0, "REG_DWORD"
    WshShell.RegWrite "HKCU\Software\Microsoft\Communicator\RTCState", 01000000, "REG_BINARY"

     

    Thursday, March 1, 2007 7:38 AM
  • For those of us who are more comfortable with batch scripting than VBScript, here is the script I use for automated Communicator installs, if you do not have SMS or another deployment method available.

    Some notes about this script:

    Our company is set up that office employees have S: drives available that replicate with all our offices around the world.  Remote users (ones who dialup or use VPN to get into our network) do not get S: drives, so the first part of the script does three things:  1, detects if Communicator is already installed by seeing if it has a key present in the LOCAL_MACHINE portion of the registry (if the script throws an error here, don't panic, this is normal) and 2, checks that the S: drive exists and the installation file exists, and 3, installs Windows Installer 3.1 before installing Communicator, just in case the workstation is behind on updates.

    The second part of the script checks to see if the user logging in already has Communicator configured for them.  If yes, then the script simply exits, but otherwise it sets up in the registry the defaults that we use:  don't play the tour, don't open main window at startup (optional, REM'ed out below--as shown, window will open), disable Customer Experience Improvement Program participation, sets received files to go into user's My Documents instead of a subdirectory inside My Documents, configures their sign-in name, runs automatically at next logon, and automatically signs in user even from the first execution.

    Thanks to Samlw for inspiring me to add a few more keys into this and do as much behind the scenes configuration as possible.

    On to the script!

    @echo off
    set OCINST=
    set USERCFG=
    REM    ***    TEST FOR COMMUNICATOR PRESENT ON SYSTEM    ***
    echo Checking for presence of Office Communicator...
    reg query "HKLM\Software\Microsoft\Communicator" >NUL && set OCINST=YES
    echo Checked registry, processing result...
    if "%OCINST%"=="YES" goto CONFIGUSER
    echo Installing Office Communicator.
    if not exist S:\nul goto NOCORP
    if not exist S:\Install\Communicator.msi goto NOINST
    S:\Install\WindowsInstaller-KB893803-v2-x86.exe /quiet /norestart
    S:\Install\Communicator.msi /passive

    REM    ***    TEST FOR COMMUNICATOR CONFIGURATION FOR CURRENT USER    ***

    :CONFIGUSER

    reg query HKCU\Software\Microsoft\Communicator /v "UserMicrosoft RTC Instant Messaging" >NUL && set USERCFG=YES
    if "%USERCFG%"=="YES" goto :EOF
    echo Configuring Office Communicator for current user.
    reg add "hkcu\Software\Microsoft\Communicator" /v TourPlayed /t REG_DWORD /d 1 /f
    REM reg add "hkcu\Software\Microsoft\Communicator" /v AutoOpenMainWindowWhenStartup /t REG_DWORD /d 0 /f
    reg add "hkcu\Software\Microsoft\Communicator" /v "CEIP Preference" /t REG_DWORD /d 0 /f
    reg add "hkcu\Software\Microsoft\Communicator" /v FtReceiveFolder /t REG_SZ /d "%USERPROFILE%\My Documents" /f
    reg add "hkcu\Software\Microsoft\Communicator" /v "UserMicrosoft RTC Instant Messaging" /t REG_SZ /d "%USERNAME%@<<YOURDOMAIN>>.com" /f
    reg add "hkcu\Software\Microsoft\Windows\CurrentVersion\Run" /v "Communicator" /t REG_SZ /d "%ProgramFiles%\Microsoft Office Communicator\Communicator.exe" /f
    reg add "hkcu\Software\Microsoft\Communicator" /v "RTCState" /t REG_BINARY /d 01000000 /f
    reg add "hkcu\Software\Microsoft\Communicator" /v AutoRunWhenLogonToWindows /t REG_DWORD /d 1 /f
    reg add "hkcu\Software\Microsoft\Communicator" /v FirstTimeUser /t REG_DWORD /d 0 /f

    goto :EOF

    :NOCORP

    echo No Corporate S: drive found.  Unable to continue.
    goto :EOF

    :NOINST

    echo Installation file not found.  Unable to continue.
    goto :EOF

    Wednesday, March 7, 2007 5:08 PM
  • Did you ever figure out how to put a contact in two groups at once via the .wsf scripts??
    Wednesday, April 4, 2007 8:56 PM
  • And how do you use "start communicator" to get Communicator to actually start after the installation?

     

    I can install it and even configure it the way I want, but I can not get it to start when the process is complete - and "start communicator" simply doesn't work.  Is there a switch for the *.msi?  Something that I've missed?

    Wednesday, May 2, 2007 12:29 PM
  • Hi There,

     

    The script work great except my organization uses firstname_lastname@domain for you e-mail address but lastname first initial for the user name. is there any varible like %username% that i can use instead to accomplish the same thing?

     

    Thanks

    Mike

     

    Thursday, May 3, 2007 8:36 PM
  •  Scatterbrain wrote:

    And how do you use "start communicator" to get Communicator to actually start after the installation?

     

    I can install it and even configure it the way I want, but I can not get it to start when the process is complete - and "start communicator" simply doesn't work.  Is there a switch for the *.msi?  Something that I've missed?

     

    When you tried the start communicator.. what happened?  For this to work it had to be fired off from the batch file like this:

     

     

    c:

    start communicator.exe

     

    I'm not sure, but i think the whole c:  was the key.. if you do this via the run prompt, it wont work.

     

    On the note asked about if I got the thing to work publishing one contact to two groups.. No.. not as of yet.

     

    There is also a limit on how many users you can put in one group as I found out.. its around 29 or 30.

     

    What I really wish I could figure out was a way to detect if Communicator was running, ie: logged in (not just if the process was running, because this isnt enough).. I had a little batch file that i ran via SMS every hour or so, so if the user logged out of communicator, it would relaunch the program signing them back in Smile

     

    Problem is... if its running, even hidden, and you fire this off, you end up with two instances of the same program.  It needs a way to know if running and if signed in...

     

     

     

    Thursday, May 3, 2007 8:55 PM
  • This part of my script should take care of that:

     

    Set objADSysInfo = CreateObject("ADSystemInfo")
    Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)

     

     

    Thursday, May 3, 2007 10:06 PM
  • Actually, when I was testing - I had somehow "semi-uninstalled" Communicator.  (I can't explain it other than several of the key components of Communicator, including the communicator.exe were missing.)  Once I cleared that up, the "start communicator" command sequence works.

     

    Sorry for the confusion.

    Friday, May 4, 2007 12:41 PM
  • Mark,

    If you could provide me with the information on how to populate the contacts list groups that would be awesome.  I'm a Windows PC technician (until just recently being thrust into some server support - not saying that is a bad thing) and my company wants to deploy Communicator but not until I can populate the user list for everyone.

    I've done several searches and you're the only one I've seen so far that seems to have done it successfully.

    Any help you could provide would be greatly appreciated.

    Mike
    Wednesday, July 18, 2007 7:50 PM
  • I use these commands in a batch file:  (I call this batch file "domain wide updater (ALL, support).bat"):

    ------------------

    lcsaddcontacts.wsf /usersfile:usersall.txt /contactsfile:contacts.txt /contactsgroup:EVERYONE

    lcsaddcontacts.wsf /usersfile:contacts.txt /contactsfile:contactsadmin.txt /contactsgroupTongue Tiedupport

    -------------------

    where the first line creates a group called "EVERYONE", uses the users file called usersall.txt and the contacts file contacts.txt.  Usersall.txt is the users you actually want this change/update to show up on, while contacts.txt is the complete list of users.

     

    The format for usersall.txt is this (in our case we go by their full email address):

     

    sip:first1.last1@domain.com

    sip:first2.last2@domain.com

     

    ^note you cant have any blank spaces in either of these user files.

     

    The format for contacts.txt is basically the same, this file contains the list of contacts you want to show up in the ALL group.

     

    The second line of the above scripts updates/creates the Support contact group.  In this case the contactsadmin.txt contains only two entries.. one for each of our two admins.  These people will show up in the "Support".  It is important to distinguish here, as you cant have the same contact automatically put in both groups via script (a user can manually move the contact if they want, but any time these update scripts get run, their groups will reset, in fact, any groups they have made will be erased and be reset to these two, it kinda sucks, i'm hoping 2007 will fix this).

     

    I believe the code for the lcsaddcontacts.wsf file is somewhere in the 2005 server install/support files.. but here it is to be complete (LONG):  I hope this was useful...

     

    --------

    <?xml version="1.0"?>
    <package>

    <comment>
    LCSAddContacts.wsf
    This WMI script progmatically adds Contacts for LCS Users.
    </comment>

    <job>
    <?job error="True" debug="True" ?>
    <runtime>
      <named
        name="usersfile"
        helpstring="Input file with the sip addresses of users, distinguished names of Active Directory containers containing users or both."
        type="string"
        required="true"
      />
      <named
        name="contactsfile"
        helpstring="Input file with the contacts to be added for the users specified in the users input file."
        type="string"
        required="true"
      />
      <named
        name="contactsgroup"
        helpstring="If specified contacts will be added to this group."
        type="string"
        required="false"
      />
      <named
        name="delete"
        helpstring="If specIfied contacts will be deleted instead of being added."
        type="simple"
        required="false"
      />

      <example>Example:
        CScript LCSAddContacts.wsf /usersfile:users.txt /contactsfile:contacts.txt /contactsgroupTongue Tiedupportstaff
        CScript LCSAddContacts.wsf /usersfile:users.txt /contactsfile:contacts.txt /delete
      </example>
    </runtime>

    <script language="VBScript">
    <![CDATA[
    ' VBScript source code
    Option Explicit

    ' Contant decleration section
    Const cComputer = "."
    Const cWMINameSpace = "root/cimv2"
    Const cWMIUserClass = "MSFT_SIPESUserSetting"
    Const cWMIUserContactGroupClass = "MSFT_SIPESUserContactGroupData"
    Const cWMIUserContactClass = "MSFT_SIPESUserContactData"
    Const cWMIUserACEClass = "MSFT_SIPESUserACEData"

    '-------------------------------------------------------------------------------
    ' Function:  GetUsersInContainer
    ' Description: This function will return the PrimaryUserAddress
    '      of the users in the given Active Directory container
    ' Parameters: ByVal strDN - Name of DN
    '      to retrieve the list of Users from.
    ' Returns:  Variant array of LCS users in the specified container
    '-------------------------------------------------------------------------------
    Function GetUsersInContainer(ByVal strDN)
     Dim vReturn
     ReDim vReturn(0)

     Dim objContainer
     Dim objMember

     On Error Resume Next
     Set objContainer = GetObject("LDAP://" & strDN)
     If Err.number <> vbEmpty Then
      WScript.Echo "[Err] " & Err.number & ": " & Err.Description & ", Could not connect to " & strOU
      On Error Goto 0
     Else
      On Error Goto 0
      ' apply a filter to retrieve only objects of class User
      objContainer.Filter = Array("User")
      ' iterate all members within the Container
      For Each objMember In objContainer
       If Trim(vReturn(0)) <> "" Then
        ReDim Preserve vReturn(UBound(vReturn) + 1)
       End If
       On Error Resume Next
       vReturn(UBound(vReturn)) = objMember.Get("msRTCSIP-PrimaryUserAddress")
       On Error Goto 0
      Next
     End If
     GetUsersInContainer = vReturn
    End Function

    '-------------------------------------------------------------------------------
    ' Function:  GetUserInstanceID
    ' Description: This function will return the InstanceID of SIP User
    ' Parameters: ByVal strPrimaryURI - SIP address of User
    '      whoes InstanceID has to be retrived
    ' Returns:  Variant string - (either -1 or InstanceID of SIP User)
    '-------------------------------------------------------------------------------
    Function GetUserInstanceID (ByVal strPrimaryURI)
     Dim vReturn  : vReturn = -1
     If Not IsEmpty(strPrimaryURI) Then
      Dim oUserInstances : Set oUserInstances = GetObject("winmgmts:\\" & cComputer).ExecQuery("SELECT * FROM " & cWMIUserClass & " WHERE PrimaryURI = '" & strPrimaryURI & "'")
      If Not oUserInstances.Count < 1 Then
       Dim oInstance
       For Each oInstance In oUserInstances
        vReturn = oInstance.InstanceID
       Next
      End If
     End If
     GetUserInstanceID = vReturn
    End Function

    '-------------------------------------------------------------------------------
    ' Function:  ParseUserLineItem
    ' Description: This function will parse each line item from text file
    '      with the users and add contacts for them.
    ' Parameters: ByVal strLineItem - Line item that has to be parsed
    '      for user for which contacts have to be added.
    ' Returns:
    '-------------------------------------------------------------------------------
    Function ParseUserLineItem (strLineItem)
     Dim vItems  : vItems = Split(strLineItem, ":")
     If UBound(vItems) > 0 Then
      Dim vUsers
      Dim vUser
      Select Case UCase(vItems(0))
       Case "SIP"
        vUser = "sip:" & Trim(vItems(1))
        AddContacts(vUser)
       Case "DN"
        ''WScript.Echo ""
        ''WScript.Echo "@------------------------------------------------------------"
        ''WScript.Echo "@ Adding Contacts for users in " & vItems(1)
        'WScript.Echo "@------------------------------------------------------------"
        'WScript.Echo "@------------------------------------------------------------"
        vUsers = GetUsersInContainer(Trim(vItems(1)))
        For Each vUser In vUsers
         AddContacts(vUser)
        Next
       Case Else
        'WScript.Echo ""
        'WScript.Echo "@------------------------------------------------------------"
        WScript.Echo "[Err] Invalid Line item in " & strUsersFile & ": '" & strLineItem & "'"
        'WScript.Echo "@------------------------------------------------------------"
      End Select
     Else
      'WScript.Echo ""
      'WScript.Echo "@------------------------------------------------------------"
      WScript.Echo "[Err] Invalid Line in " & strUsersFile & ": '" & strLineItem & "'"
      'WScript.Echo "@------------------------------------------------------------"
     End If
    End Function

    '-------------------------------------------------------------------------------
    ' Function:     AddContacts
    ' Description:  Add contacts for given User
    ' Parameters:   ByVal strPrimaryURI - SIP address of User
    '                 for whom contacts have to be added
    ' Returns:
    '-------------------------------------------------------------------------------
    Function AddContacts (ByVal strPrimaryURI)
     If Not IsEmpty(strPrimaryURI) Then
      Dim strUserInstanceId : strUserInstanceId = GetUserInstanceID(strPrimaryURI)
      If Not IsNumeric(strUserInstanceId) Then
       Dim strGroupID
       Dim strContactLineItem
       If Not IsNull(strContactGroup) Then
        strGroupID = AddContactGroup(strUserInstanceId, strContactGroup)
       End If
       'WScript.Echo ""
       'WScript.Echo "@------------------------------------------------------------"
       'WScript.Echo "@ Adding contacts..."
       'WScript.Echo "@  PrimaryURI:     " & strPrimaryURI
       'WScript.Echo "@  InstanceID:     " &  strUserInstanceId
       'WScript.Echo "@  ContactGroupID: " &  strGroupID
       'WScript.Echo "@------------------------------------------------------------"
       For Each strContactLineItem In vContacts
        If Not (ParseAndAddContact(strUserInstanceId, strContactLineItem, strGroupID) = 0) Then
         WScript.Echo "[Err] Invalid line in " & strContactsFile & ": '" & strContactLineItem & "'"
        End If
       Next
      Else
       'WScript.Echo ""
       'WScript.Echo "@------------------------------------------------------------"
       WScript.Echo "[Err] Invalid User(User might not be SIP enabled) in " & strUsersFile & ": '" & strPrimaryURI & "'"
       'WScript.Echo "@------------------------------------------------------------"
      End If
     End If
    End Function

    '-------------------------------------------------------------------------------
    ' Function:     ParseAndAddContact
    ' Description:  Parse line item and call AddContact() for given User
    ' Parameters:   ByVal strUserInstanceId - InstanceID of User
    '                 for whom contact has to be added
    '    ByVal strContactInfo - Line item with the Contact information
    '    ByVal strGroupID - GroupID of ContactGroup
    ' Returns:  Variant rReturn - (Either -1, Err.Number or 0)
    '-------------------------------------------------------------------------------
    Function ParseAndAddContact(ByVal strUserInstanceId, ByVal strContactInfo, ByVal strGroupID)
     Dim vReturn : vReturn = -1
     Dim intPos : intPos = InStr(strContactInfo, "sip:")
     If Not (intPos = 0) Then
      Dim vContactItems : vContactItems = Split(strContactInfo, "sip:")
      Dim intCount  : intCount = UBound(vContactItems)

      'Stronger version of trim to remove tabs etc.
      Dim strName
      Dim oRegExp : Set oRegExp = New RegExp
      oRegExp.Pattern = "\s{2,}"
      strName = Trim(oRegExp.Replace(vContactItems(0), ""))

      If intCount = 1 Then
       If Not fDelete Then
        If Len(strName) = 0 Then ' if no name exists
         vReturn = AddContact(strUserInstanceId, "sip:" & Trim(vContactItems(1)), strGroupID, null, true)
        Else ' if name exists
         vReturn = AddContact(strUserInstanceId, "sip:" & Trim(vContactItems(1)), strGroupID, strName, true)
        End If
       Else
        vReturn = DeleteContact(strUserInstanceId, "SIP:" & Trim(vContactItems(1))) ' Notice SIP is in all caps
       End If
      End If
     End If
     ParseAndAddContact = vReturn
    End Function

    '-------------------------------------------------------------------------------
    ' Function:     AddContact
    ' Description:  Adds Contact for given User
    ' Parameters:   UserInstanceID, SIPURI, GroupID, Name, Subscribed
    ' Returns:  Variant rReturn - (Either -1, Err.Number or 0)
    '-------------------------------------------------------------------------------
    Function AddContact(ByVal UserInstanceID, ByVal SIPURI, ByVal GroupID, ByVal Name, ByVal Subscribed)
     Dim vReturn  : vReturn = -1

     Dim vGroupID : vGroupID = null
     If Not IsNull(GroupID) And Not IsEmpty(GroupID) Then
      Redim vGroupID(0)
      vGroupID(0) = GroupID
     End If

     Dim oInstances
     Dim oInstance

     Set oInstances = GetObject("winmgmts:\\" & cComputer).Get(cWMIUserContactClass)
     Set oInstance = oInstances.SpawnInstance_

     oInstance.UserInstanceID = UserInstanceID
     oInstance.SIPURI = SIPURI
     oInstance.GroupID = vGroupID
     oInstance.Name = Name
     oInstance.Subscribed = Subscribed
      
     On Error Resume Next
     oInstance.Put_ 0 'Put flag 0 for createOrUpdate

     If Err.number = vbEmpty Then
       'Wscript.Echo "[+]   Put successful for contact: " & Name & " (" & SIPURI & ")"
       vReturn = 0
     Else
       Wscript.Echo "[-]   Put failed for contact: " & Name & " (" & SIPURI & ") " & Err.number & ": " & err.description
       vReturn = Err.number
     End If
     On Error Goto 0
     AddContact = vReturn
    End Function

    '-------------------------------------------------------------------------------
    ' Function:     DeleteContact
    ' Description:  Deletes Contact for given a User
    ' Parameters:   UserInstanceID, SIPURI
    ' Returns:  Variant rReturn - (Either -1, Err.Number or 0)
    '-------------------------------------------------------------------------------
    Function DeleteContact(ByVal UserInstanceID, ByVal SIPURI)
     Dim vReturn  : vReturn = -1

     Dim oInstances
     Dim oInstance

     Set oInstances = GetObject("winmgmts:\\" & cComputer).ExecQuery("SELECT * FROM " & cWMIUserContactClass & " WHERE UserInstanceID = '" & UserInstanceID & "'")
     If Not oInstances.Count < 1 Then
      For Each oInstance In oInstances
       If StrComp(SIPURI, oInstance.SIPURI) = 0 Then
        On Error Resume Next
        oInstance.Delete_
        If Err.number = vbEmpty Then
         'WScript.Echo "[+]   Delete successful for contact: " & SIPURI
         vReturn = 0
        Else
         WScript.Echo "[-]   Delete failed for contact: " & SIPURI & " " & Err.number & ": " & Err.Description
         vReturn = Err.number
        End If
        On Error Goto 0
       End If
      Next
     End If
     DeleteContact = vReturn
    End Function

    '-------------------------------------------------------------------------------
    ' Function:     AddContactGroup
    ' Description:  Adds Contact for given User
    ' Parameters:   UserInstanceID, Name
    ' Returns:  Variant rReturn - (Either null or GroupID)
    '-------------------------------------------------------------------------------
    Function AddContactGroup(ByVal UserInstanceID, ByVal Name)
     Dim vReturn : vReturn = null

     Dim oInstances
     Dim oInstance

     Set oInstances = GetObject("winmgmts:\\" & cComputer).Get(cWMIUserContactGroupClass)
     Set oInstance = oInstances.SpawnInstance_

     oInstance.UserInstanceID = UserInstanceID
     oInstance.Name = Name

     On Error Resume Next
     oInstance.Put_ 2 'Put flag 2 for createOnly
     
     Err.Clear
     On Error Goto 0

     Set oInstances = GetObject("winmgmts:\\" & cComputer).ExecQuery("SELECT * FROM " & cWMIUserContactGroupClass & " WHERE UserInstanceID = '" & UserInstanceID & "'")
     If Not oInstances.Count < 1 Then
      For Each oInstance In oInstances
       If StrComp(Name, oInstance.Name) = 0 Then
        vReturn = oInstance.GroupID
       End If
      Next
     End If
     
     AddContactGroup = vReturn
    End Function

        ]]>
        </script>

    <script language="VBScript">
    <![CDATA[
    Option Explicit

    Sub ShowUsage
     WScript.Arguments.ShowUsage
     WScript.Quit
    End Sub

    If Not WScript.Arguments.Named.Exists("contactsfile") OR Not WScript.Arguments.Named.Exists("usersfile") Then
     ShowUsage
    End If

    Dim strContactsFile : strContactsFile = LCase(Trim(WScript.Arguments.Named.Item("contactsfile")))
    Dim strUsersFile : strUsersFile = LCase(Trim(WScript.Arguments.Named.Item("usersfile")))
    Dim strContactGroup : strContactGroup = Trim(WScript.Arguments.Named.Item("contactsgroup"))
    Dim fDelete   : fDelete = WScript.Arguments.Named.Exists("delete")

    Dim fShowUsage  : fShowUsage = false

    If IsEmpty(strContactGroup) Then
     strContactGroup = null
    End If

    'WScript.Echo "@------------------------------------------------------------"
    'WScript.Echo "@ Text file with Users:       " & strUsersFile
    'WScript.Echo "@ Text file with Contacts:    " & strContactsFile
    'WScript.Echo "@ Contact Group for Contacts: " & strContactGroup
    'WScript.Echo "@------------------------------------------------------------"
    'WScript.Echo ""

    Dim vContacts()
    'ReDim vContacts(0)

    Dim oFS    : Set oFS = CreateObject("Scripting.FileSystemObject")
    Dim oContactsFile
    Dim oUsersFile
    Dim i    : i = 0
    Dim fContactsExist : fContactsExist = False

    'Reading Contacts from file
    If oFS.FileExists(strContactsFile) Then
     Set oContactsFile = oFS.OpenTextFile(strContactsFile, 1, false)
     fContactsExist = True
     Dim strContact
     Do Until oContactsFile.AtEndOfStream
      ReDim Preserve vContacts(i)
      strContact = Trim(oContactsFile.ReadLine)
      vContacts(i) = strContact
      i = i+1
     Loop
    Else
     fShowUsage = True
     WScript.Echo "[Err] Invalid contacts input file: " & strContactsFile
    End If

    'Reading Users from file and adding contacts
    If oFS.FileExists(strUsersFile) Then
     If fContactsExist Then
      Set oUsersFile = oFS.OpenTextFile(strUsersFile, 1, false)

      Dim strUserSIPAddress
      Dim strUserInstanceId
      Dim strLineItem

      Do Until oUsersFile.AtEndOfStream
       strLineItem = Trim(oUsersFile.ReadLine)
       ParseUserLineItem(strLineItem) ' Parse each line item and add contacts for it
      Loop
     End If
    Else
     fShowUsage = True
     WScript.Echo "[Err] Invalid users input file: " & strUsersFile
    End If

    If fShowUsage Then
     ShowUsage
    End If

        ]]>
        </script>
      </job>
    </package>

     

    -----------------------------------------------------------

     

     

     

     

     

    Sunday, July 22, 2007 3:12 PM
  • I did a VBS script that looks similar like the above but some difference, it set static a LCS server (comment away that part if you use DNS SRV SIP records) and it reads the SIP address from AD (I seen here above some take for granted it is %username% and .com in the end etc, dangerous that is not always the case, my script however read the REAL SIP address if one exist on the user object).
    It also take away the anoying Welcome window that I never heard is of any use.. ok here is the script: (if format looks strange and more explenation needed please visit http://john.bryntze.net/jbkb/index.php?title=Script-kb5_Script_to_set_Communicator_2005_client_Sign-in_name_(SIP_address)_and_server_address

    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' JBKBSetSIPAdress-Server.vbs '
    ' Author John Bryntze http://john.bryntze.net/jbkb '
    ' Version 1.0 - May 7th 2009 '
    ' VBS script to: '
    ' 1. Set manual Office Communicator server '
    ' 2. Disable the "Automatically open the main window when Communicator starts" '
    ' 3. Read the current users SIP address from AD and set it '
    ' '
    ' Usage: Change line 21 to set ServerAddress to your LCS server '
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Option Explicit
    'Declarations
    Dim JBKBShell, JBKBRegKey, JBKBNetwork, JBKBUser, JBKBDomain, adoJBKBLDAPCon, adoJBKBLDAPRS, strJBKBLDAP, ServerAddress, SIPAddress

    Set JBKBShell = WScript.CreateObject ("WSCript.shell")
    Set JBKBNetwork = CreateObject("Wscript.Network")
    JBKBUser = JBKBNetwork.UserName
    JBKBDomain = JBKBNetwork.UserDomain
    'Set ServerAddress to your LCS server, in this example it is set to
    ServerAddress = "JBKBlcsPool"

    '1. Set manual Office Communicator server (and to manual configuration, for automatic create a DNS SRV SIP record for the server)
    JBKBShell.regwrite"HKEY_CURRENT_USER\Software\Microsoft\Communicator\ConfigurationMode", 1, "REG_DWORD"
    JBKBRegKey = JBKBShell.regread("HKEY_CURRENT_USER\Software\Microsoft\Communicator\ServerAddress")
    If JBKBRegKey = ServerAddress then
    'No changes needed
    Else
    'No or wrong SIP server, set to correct:
    JBKBShell.regwrite"HKEY_CURRENT_USER\Software\Microsoft\Communicator\ServerAddress", ServerAddress, "REG_SZ"
    End If

    '2. Disable the "Automatically open the main window when Communicator starts"
    JBKBShell.regwrite"HKEY_CURRENT_USER\Software\Microsoft\Communicator\AutoOpenMainWindowWhenStartup", 0, "REG_DWORD"

    '3. Read the current users SIP address from AD and set it
    Set adoJBKBLDAPCon = CreateObject("ADODB.Connection")
    adoJBKBLDAPCon.Provider = "ADsDSOObject"
    adoJBKBLDAPCon.Open "ADSI"
    strJBKBLDAP = "'LDAP://" & JBKBDomain & "'"

    Set adoJBKBLDAPRS = adoJBKBLDAPCon.Execute("select msRTCSIP-PrimaryUserAddress from " & strJBKBLDAP & " WHERE objectClass = 'user'"& " And samAccountName = '" & JBKBUser & "'")
    With adoJBKBLDAPRS
    If Not .EOF Then
    SIPAddress = .Fields("msRTCSIP-PrimaryUserAddress")
    Else
    SIPAddress = ""
    End If
    End With
    adoJBKBLDAPRS.Close
    Set adoJBKBLDAPRS = Nothing
    Set adoJBKBLDAPCon = Nothing

    'Remove the "sip:" part of the string.
    SIPAddress = replace(SIPAddress,"sip:","")

    'Set SIPAddress
    JBKBShell.regwrite"HKEY_CURRENT_USER\Software\Microsoft\Communicator\UserMicrosoft RTC Instant Messagning", SIPAddress, "REG_SZ"

    Thursday, May 7, 2009 1:39 PM