Become a Columnist Microsoft Exchange Site Microsoft Support SiteMSDN Exchange Site

   

Subscribe to OutlookExchange
Anderson Patricio
Ann Mc Donough
Bob Spurzem
Brian Veal
Catherine Creary
Cherry Beado
Colin Janssen
Collins Timothy Mutesaria
Drew Nicholson
Fred Volking
Glen Scales
Goran Husman
Guy Thomas
Henrik Walther
Jason Sherry
Jayme Bowers
John Young
Joyce Tang
Justin Braun
Konstantin Zheludev
Kristina Waters
Kuang Zhang
Mahmoud Magdy
Martin Tuip
Michael Dong
Michele Deo
Mitch Tulloch
Nicolas Blank
Pavel Nagaev
Ragnar Harper
Ricardo Silva
Richard Wakeman
Russ Iuliano
Santhosh Hanumanthappa
Steve Bryant
Steve Craig
Todd Walker
Tracey J. Rosenblath
 
 

Logon and Logoff scripts for Roaming with Instant Messaging Contacts 

One of the major issues you may experience with IM ( if you are not using roaming profiles), is that your contacts don’t roam with you when you go from PC to PC as explained in Q271952.  The MSN messenger client when used with Exchange stores its IM contacts in the HKEY_CURRENT_USER\Microsoft\Exchange\Messenger\Profiles registry key. The following are scripts that I have written to read the information stored in the registry and write it to a file on the users home drive. Then when the logon script executes it recreates the contacts by reading this saved file. Click to download scripts

 

RegObj.dll

 

To use the VBS scripts shown here you need to install this dll on your workstation (if you haven’t already). Its been written by Microsoft and can be obtained from MSDN http://premium.microsoft.com/download/vbasic/RegObji.exe (if your registered) or from http://www.comptrends.com/vbscriptfiles.asp?curpage=2. The reason this file is needed is it provides the ability to enumerate registry keys, this just can’t be done well enough with the normal WSH stuff. Kix32 will work straight of the bat and is still one of my favourite scripting tools.

 

Methods

 

I’ve written two versions of these scripts to suit different peoples needs, the first one is a VBS and KIX32 version of a logoff script (For Windows2000). These scripts write out the Instant Messaging contacts to a Regini format text file. For people who don’t know Regini it’s a NT resource kit utility that allows you to do some registry scripting. It’s very efficient and fast in logons and is my preferred method when adding a lot of registry entries. It also avoids clutter in your logon script.
The second method uses a vbs script for both logon and logoff, the main difference from the first method is the text written to the file is in a format the logon script can read and use to create registy entries.

 

Method 1

 

This method use’s a logoff script to write a regini format text file to the users home drive. At logon you would need to include a line in your logon script such as the following to execute the Regini scripts and create the registry entries.   “Regini h:\contact.im”

 

VBS Logoff to a Regini Txt file

 

set objRegistry = CreateObject("RegObj.Registry")

Set fso = CreateObject("Scripting.FileSystemObject")

if (fso.FileExists("H:\contact.im")) Then

            fso.deletefile("H:\contact.im")

End If

Set objRegKey = objRegistry.RegKeyFromString("\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Exchange\Messenger\Profiles\")

set wfile =  fso.opentextfile("H:\contact.im",2,true)

For Each objRegKey In objRegKey.SubKeys

    wfile.write ("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Exchange\Messenger\Profiles" & vbCRLF)

    wfile.write (vbTab & objregkey.name & vbCRLF)

    wfile.write (vbTab & vbTab & "Contacts"& vbCRLF)

    strprofile = objRegKey.Fullname + "\Contacts\"

    set objRegkey1 =  objRegistry.RegKeyFromString(strprofile)  

    For Each objRegKey1 In objRegKey1.values

            wfile.write (vbTab & vbTab & vbTab & objRegKey1.name & " = " & objRegKey1.name & vbCRLF)

    Next

Next

wfile.close

 

 

Kix32 Logoff to a Regini file

 

IF EXIST ("H:\contact.im") = 1

            DEL "H:\contact.im"

ENDIF

OPEN (4,"H:\contact.im",5)

$Index = 0

:Loop1

$keyname = ENUMKEY("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Exchange\Messenger\Profiles\", $Index)

If @ERROR = 0

            $wr = WRITELINE(4, "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Exchange\Messenger\Profiles" + Chr(13) + Chr(10))

            $wr = WRITELINE(4, Chr(9) + $keyname + Chr(13) + Chr(10))

            $wr = WRITELINE(4, Chr(9) + Chr(9) +"Contacts" + Chr(13) + Chr(10))

            $keyname = ("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Exchange\Messenger\Profiles\" + $keyname + "\Contacts")

            $Index1 = 0

            :Loop2

            $ValueName = ENUMVALUE($keyname, $Index1)

            If @ERROR = 0

                        $wr = WRITELINE(4, Chr(9) + Chr(9) + Chr(9) + $Valuename + " = " + $Valuename + Chr(13) + Chr(10))

                        $Index1 = $Index1 + 1

                        goto Loop2

            Endif

            $Index = $Index + 1

            goto Loop1

Endif

 

Method 2

 

The second method I have used use’s VBS files for both Logon and Logoff. 

VBS for Logoff

 

set objRegistry = CreateObject("RegObj.Registry")

Set fso = CreateObject("Scripting.FileSystemObject")

if (fso.FileExists("h:\contact.im")) Then

            fso.deletefile("h:\contact.im")

End If

Set objRegKey = objRegistry.RegKeyFromString("\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Exchange\Messenger\Profiles\")

set wfile =  fso.opentextfile("h:\contact.im",2,true)

For Each objRegKey In objRegKey.SubKeys

    strprofile = objRegKey.Fullname + "\Contacts\"

    set objRegkey1 =  objRegistry.RegKeyFromString(strprofile)  

    For Each objRegKey1 In objRegKey1.values

            strvalname = strprofile + objRegKey1.name

            strvalname1 = replace(strvalname, "\HKEY_CURRENT_USER", "HKCU")

            wfile.write ( strvalname1 & "," & objregkey1.name &  vbCRLF)

    Next

Next

wfile.close

 

VBS for Logon

 

set objRegistry = CreateObject("RegObj.Registry")

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

Set fso = CreateObject("Scripting.FileSystemObject")

if (fso.FileExists("H:\contact.im")) Then

set wfile =  fso.opentextfile("H:\contact.im",1,true)

Do until wfile.AtEndOfStream = True

inpline = wfile.readline

            rem WshShell.RegWrite inpline, 1 ,"REG_DWORD"

            slen = instr(inpline,",")

            strkname = mid(inpline,1,(slen - 1))

            strvname = mid(inpline,(slen + 1),100)

            WshShell.RegWrite strkname , strvname

loop

wfile.close        

End If 

 

Windows 9x and NT4 Machines 

Because these machines don’t have a logoff script capability it does pose somewhat of a challenge in dealing with roaming users. It is possible to combine the above scripts into one intelligent logon script or use the logoff and logon parts as batch files users click to update their contacts. There needs to be some customisation done and it depends on the state and requirements of your current environment. The RegObj.dll does work cross platform on NT4 and Wins9x so once this DLL has been registered these scripts should work. 

Download Scripts


Disclaimer: Your use of the information contained in these pages is at your sole risk. All information on these pages is provided "as is", without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by Stephen Bryant or Pro Exchange. OutlookExchange.Com, Stephen Bryant and Pro Exchange shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.

Copyright Stephen Bryant 2008