SHARE
TWEET

Lync Custom Presence HTA

Moktart Aug 9th, 2012 1,409 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3. <title>Lync Custom Presence Editor</title>
  4. <HTA:APPLICATION
  5.   APPLICATIONNAME="Lync Custom Presence Tool"
  6.   ID="LyncCustomPresenceTool"
  7.   SCROLL=No
  8.   VERSION="1.0"
  9.   MAXIMIZEBUTTON="no"
  10.   />
  11. </head>
  12.  
  13. <script language="VBScript">
  14. Option Explicit  
  15.  
  16. Dim wshshell, objfso, xmldoc
  17. Dim profilepath, username, PresenceXML, PresenceREG, root
  18. Set wshShell = CreateObject("WScript.Shell")
  19. Set objFso = CreateObject("Scripting.FileSystemObject")
  20. Set xmlDoc = CreateObject( "Microsoft.XMLDOM" )
  21. XMLDoc.setProperty "SelectionLanguage", "XPath"
  22. profilepath = wshShell.ExpandEnvironmentStrings("%userprofile%")
  23. username = wshShell.ExpandEnvironmentStrings("%username%")
  24. PresenceXML = profilepath & "\presence.xml"
  25. PresenceREG = profilepath & "\CustomLyncPresence.reg"
  26.  
  27. Sub Window_OnLoad
  28.         Dim span, list, Checkbox, listbox, textbox, paragraph, root, readnode, availability, objOption, i
  29.         window.resizeto 450,260
  30.         Set span = document.getElementById("MainSpan")
  31.         list = Array("Online","Busy","Do-Not-Disturb")
  32.         For i = 1 To 4 'Yep, only four.  Look it up.
  33.                 Set Checkbox = document.createElement("input")  'This dynamically populates the inputs, except for the two buttons.
  34.                         Checkbox.type="Checkbox"                                        'Dynamically making those (with working onclick events) is hard, and using innerhtml is a cop-out!
  35.                         Checkbox.id = "Status" & i & "Enable"           'Also, I hate using "with" for assigning less than 6 attributes.  Deal with it!
  36.                         Checkbox.name = "Status" & i & "Enable"
  37.                 span.appendchild Checkbox
  38.                 Set listbox = document.createElement("select")
  39.                         listbox.size = "1"
  40.                         listbox.name = "Status" & i & "Type"
  41.                         listbox.id = "Status" & i & "Type"
  42.                 For Each availability In list
  43.                         Set objoption = document.createElement("option")
  44.                         objoption.text = availability
  45.                         objoption.value = availability
  46.                         listbox.add objoption          
  47.                 Next
  48.                 span.appendchild listbox
  49.                 Set textbox = document.createElement("input")
  50.                         textbox.type = "text"
  51.                         textbox.name = "Status" & i & "Text"
  52.                         textbox.id = "Status" & i & "Text"
  53.                         textbox.size = 40
  54.                 span.appendchild textbox
  55.                 Set paragraph = document.createElement("p")
  56.                 span.appendchild paragraph
  57.         Next
  58.                
  59.         If objFso.fileexists(PresenceXML) Then
  60.                 xmlDoc.Async = "False"
  61.                 xmlDoc.Load(PresenceXML)
  62.                 Set root = xmlDoc.DocumentElement
  63.                 For i = 1 To 4
  64.                         Set readnode = root.selectsinglenode("customState[contains(@ID,'" & i & "')]")
  65.                         If Not readnode Is Nothing Then
  66.                                 populateform i,readnode.attributes.item(1).value,readnode.text
  67.                         End If
  68.                 Next
  69.         End If
  70. End Sub
  71.  
  72. function OnClickButtonRemove()
  73.         RegControl "delete"
  74.         If objFso.fileexists(PresenceXML) Then objfso.deletefile(PresenceXML)
  75.         If objFso.fileexists(PresenceREG) Then objfso.deletefile(PresenceREG)
  76.         location.reload(True)
  77.         MsgBox "Removed! Sign out and back in to see the changes."
  78. End Function
  79.  
  80.  
  81. sub OnClickButtonSet()
  82.         Dim Check, i
  83.         Check = 0
  84.         For i = 1 To 4
  85.                 If document.getElementById("Status" & i & "Enable").Checked = true Then Check = 1
  86.         Next
  87.         If Check = 0 Then
  88.                 MsgBox "Nothing to do!"
  89.                 Exit Sub
  90.         End If
  91.         RegControl("add")
  92.         Set xmldoc = nothing
  93.         Set xmlDoc = CreateObject( "Microsoft.XMLDOM" )
  94.         Set root = xmlDoc.createElement("customStates")
  95.         xmlDoc.appendChild root
  96.         For i = 1 To 4
  97.                 If document.getElementById("Status" & i & "Enable").Checked = True Then
  98.                         AddStatus i, document.getElementById("Status" & i & "Type").value, document.getElementById("Status" & i & "Text").value
  99.                 End if
  100.         Next
  101.         xmlDoc.Save PresenceXML
  102.         MsgBox "Set! Sign out and back in to see the changes."
  103. End Sub
  104.  
  105.  
  106. Function AddStatus(id, availability, text)
  107.         Dim objState, objActivity
  108.         Set objState = xmlDoc.createElement("customState")
  109.         objState.SetAttribute "ID", id
  110.         objState.SetAttribute "availability",availability
  111.         root.appendChild objState
  112.         Set objActivity = xmlDoc.createElement("activity")  
  113.         objActivity.Text = text
  114.         objActivity.SetAttribute "LCID","1033"
  115.         objState.appendChild objActivity
  116. end function
  117.  
  118. Function populateform(id, availability, text)
  119.         document.getElementById("Status" & id & "Enable").Checked = True
  120.         document.getElementById("Status" & id & "Type").value = availability
  121.         document.getElementById("Status" & id & "Text").value = text
  122. End Function
  123.  
  124. Function RegControl(state)
  125.         Dim regfile, return
  126.     Set regFile = objfso.createTextfile(PresenceREG, True)
  127.     return = wshshell.run("reg query HKCU\Software\Policies\Microsoft\Communicator /v EnableSipHighSecurityMode",7,True)
  128.     If state = "add" Then
  129.         If return = 1 Then
  130.                 regFile.writeline "Windows Registry Editor Version 5.00" & vbNewline & "[HKEY_CURRENT_USER\SOFTWARE\Policies\Microsoft\Communicator]" & vbNewline & """CustomStateURL""=""file:///c:/users/" & Username & "/presence.xml""" & vbNewline & """EnableSIPHighSecurityMode""=dword:00000000"
  131.                 regFile.Close
  132.                         wshShell.Run "regedit /s " & PresenceREG
  133.                 End If
  134.         ElseIf state = "delete" Then
  135.                 If return = 0 Then
  136.                         regFile.writeline "Windows Registry Editor Version 5.00" & vbNewline & "[HKEY_CURRENT_USER\SOFTWARE\Policies\Microsoft\Communicator]" & vbNewline & """CustomStateURL""=-" & vbNewline & """EnableSIPHighSecurityMode""=-"
  137.                         regFile.Close
  138.                     wshShell.Run "regedit /s " & PresenceREG
  139.             End If
  140.     End if  
  141. End Function
  142.  
  143. </script>
  144. <body bgcolor="white">
  145. <span ID="mainspan"></span>
  146. <input type ="button" name="Set" ID="Set" value="Set" style="height:25px; width=200px;" onclick="onclickbuttonSet">
  147. <input type ="button" name="Remove" ID="Remove" value="Remove" style="height:25px; width=200px;" onclick="onclickbuttonremove">
  148. </body>
  149. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top