/
configure.vbs
104 lines (93 loc) · 2.82 KB
/
configure.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
On Error Resume Next
set WshShell = WScript.CreateObject("WScript.Shell")
'
' Obtain currently logged on user's DN
' stored in the value: ADSysInfo.UserName
'
Set ADSysInfo = CreateObject("ADSystemInfo")
'
' Query user's SIP URI and home server DN
' using the following WMI class:
'
' class MSFT_SIPESUserSetting
' {
' string DisplayName;
' boolean Enabled;
' string HomeServerDN;
' [key] string InstanceID;
' string PrimaryURI;
' string TargetServerDNIfMoving;
' string UserDN;
' };
'
Set oUsers = GetObject("winmgmts:\\").ExecQuery("SELECT * FROM MSFT_SIPESUserSetting WHERE UserDN = '" & ADSysInfo.UserName & "'")
' Since the user DN is unique, we're expecting a single result.
for each User in oUsers
sipURI = User.PrimaryURI
poolDN = User.HomeServerDN
next
' Exit if user is not enabled for Live Communications.
if IsEmpty(sipURI) then
Wscript.echo "ERROR: user is not enabled for Live Communications"
Wscript.Quit
end if
' Exit if user is orphaned.
if IsNull(poolDN) then
Wscript.echo "ERROR: user is not assigned to a home server"
Wscript.Quit
end if
'
' Convert home server DN into FQDN
' using the following WMI class:
'
' class MSFT_SIPPoolSetting
' {
' string BackEndDBPath;
' [key] string InstanceID;
' uint32 MajorVersion;
' uint32 MinorVersion;
' string PoolDisplayName;
' string PoolDN;
' string PoolFQDN;
' string [] PoolMemberList;
' string PoolType;
' };
'
Set oServers = GetObject("winmgmts:\\").ExecQuery("SELECT * FROM MSFT_SIPPoolSetting WHERE PoolDN = '" & poolDN & "'")
' Since the pool DN is unique, we're only expecting a single FQDN.
for each HS in oServers
poolFQDN = HS.PoolFQDN
next
' Exit if user's home server FQDN can not be determined.
if IsEmpty(poolFQDN) then
Wscript.echo "ERROR: failed to determine user's home server FQDN"
Wscript.Quit
end if
'
' Retrieve user's domain
'
domain = WshShell.ExpandEnvironmentStrings("%USERDOMAIN%")
'
' Parse the SIP URI into the format:
' 'sip:user@company.com' -> 'user@company.com %domain%\user'
' where %domain% is the user's domain name
'
Set myRegExp = New RegExp
myRegExp.IgnoreCase = True
myRegExp.Global = True
myRegExp.Pattern = "sip:([^~]+)@([^~]+)"
replaceString = "$1@$2 " & domain & "\$1"
userURI = myRegExp.Replace(sipURI, replaceString)
'
' Configure Communicator registry keys
'
WshShell.RegWrite "HKCU\Software\Microsoft\Communicator\UserMicrosoft RTC Instant Messaging", userURI, "REG_SZ"
WshShell.RegWrite "HKCU\Software\Microsoft\Communicator\ServerAddress", poolFQDN, "REG_SZ"
WshShell.RegWrite "HKCU\Software\Microsoft\Communicator\ConfigurationMode", 1, "REG_DWORD"
' Set type to 2 for TCP or set type to 4 for TLS
const TransportType = 2
WshShell.RegWrite "HKCU\Software\Microsoft\Communicator\Transport", TransportType, "REG_DWORD"
'
' Start Communicator.exe so user doesn't experience any delays
'
WshShell.Run "Communicator.exe", 1