-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiTeams.vbs
202 lines (134 loc) · 5.17 KB
/
MultiTeams.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
Option Explicit
'************************************************
'* *
'* More information at: *
'* https://github.com/jonasroslund/multiteams *
'* *
'************************************************
'***************************************************************
' Define constants
'***************************************************************
Const VERIFICATION_FILE_NAME = "This is a custom Teams folder.txt"
'***************************************************************
' Define support function(s)
'***************************************************************
Function ValidProfileName(Name)
' Checks if profile name can be used as a folder name
Dim BadChars, k
BadChars = ":\/?*<>|"""
For k = 1 To Len(BadChars)
If InStr(Name, Mid(BadChars, k, 1)) > 0 Then
ValidProfileName = False
Exit Function
End If
Next
ValidProfileName = True
End Function
Function CreateDeepFolder(FolderName)
' Create folder, with parent folders if needed
Dim FSO, TotalPath, Folder
Set FSO = CreateObject("Scripting.FileSystemObject")
If Right(FolderName, 1) = "\" Then FolderName = Left(FolderName, Len(FolderName) - 1)
TotalPath = ""
For Each Folder In Split(FolderName, "\")
TotalPath = TotalPath & Folder & "\"
If FSO.FileExists(TotalPath) Then
CreateDeepFolder = False
Exit Function
ElseIf Not FSO.FolderExists(TotalPath) Then
FSO.CreateFolder(TotalPath)
End If
Next
CreateDeepFolder = True
End Function
Function CheckVerificationFileInFolder(FolderName)
' Check if folder has a file verifying it as a custom Teams folder
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
CheckVerificationFileInFolder = FSO.FileExists(FolderName & "\" & VERIFICATION_FILE_NAME)
End Function
Function CreateVerificationFileInFolder(FolderName)
' Create a file to identify folder as a custom Teams folder
Dim FSO, File
Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.CreateTextFile(FolderName & "\" & VERIFICATION_FILE_NAME)
File.WriteLine("Custom Teams folder")
File.Close()
End Function
'***************************************************************
' Begin Main Script
'***************************************************************
Dim FSO
Dim Arg, ProfileName, Wsh, Env, Res
Dim MyUserProfile
Dim DefaultCustomFolderLocation, CustomFolder
Dim ScriptName, DotPos
Set Arg = WScript.Arguments
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Wsh = CreateObject("WScript.Shell")
Set Env = Wsh.Environment("Process")
MyUserProfile = Env("USERPROFILE")
DefaultCustomFolderLocation = MyUserProfile & "\AppData\Local\Microsoft\Teams\CustomProfiles"
'----------------
' Check argument
'----------------
If Arg.Count > 0 Then
If InStr(Arg(0), "\") = 0 Then
' Argument is a profile name
ProfileName = Arg(0)
' Validate profile name, to be used as a folder name
If Not ValidProfileName(ProfileName) Then
MsgBox "Invalid profile name:" & vbNewLine & ProfileName
WScript.Quit
End If
CustomFolder = DefaultCustomFolderLocation & "\" & ProfileName
Else
' Argument is a folder path
CustomFolder = Arg(0)
End If
Else
' Use script file name as profile name
ScriptName = WScript.ScriptName
DotPos = InStrRev(ScriptName, ".")
If DotPos = 0 Then
ProfileName = ScriptName
Else
ProfileName = Left(ScriptName, DotPos - 1)
End If
CustomFolder = DefaultCustomFolderLocation & "\" & ProfileName
End If
'------------------------------------------------------
' Check if folder is suitable as a custom Teams folder
'------------------------------------------------------
If FSO.FolderExists(CustomFolder) Then
' Folder does not exist
If Not CheckVerificationFileInFolder(CustomFolder) Then
' Verification file does not exist
' Get confirmation from user to continue anyway
Res = MsgBox("Folder exists, but does not seem to contain custom Teams data." & vbNewLine & _
"Continue anyway?", vbOKCancel)
If Not Res = vbOK Then
WScript.Quit
End If
' Create verification file
CreateVerificationFileInFolder(CustomFolder)
End If
Else
Res = MsgBox("Folder does not exist." & vbNewLine & _
"Continue setting up new custom Teams folder?", vbOKCancel)
If Not Res = vbOK Then
WScript.Quit
End If
' Create folder and verification file
CreateDeepFolder(CustomFolder)
CreateVerificationFileInFolder(CustomFolder)
End If
'----------------------
' Set up and run Teams
'----------------------
' Set fake user profile folder, to trick Teams
Env("USERPROFILE") = CustomFolder
' Set working directory
Wsh.CurrentDirectory = MyUserProfile & "\AppData\Local\Microsoft\Teams"
' Start Teams, initiating data if it doesn't exist
Wsh.Run("""" & MyUserProfile & "\AppData\Local\Microsoft\Teams\Update.exe"" --processStart ""Teams.exe""")