home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / free_security / msshared / Shared_Computer_Toolkit_ENU.msi / FileInclude017 < prev    next >
Encoding:
Text (UTF-16)  |  2005-09-02  |  33.5 KB  |  434 lines

  1. ' ***
  2. ' *** ------------------------------------------------------------------------------
  3. ' *** Filename:        UserAccounts.vbs
  4. ' *** ------------------------------------------------------------------------------
  5. ' *** Description:    UserAccounts HTA Script
  6. ' *** ------------------------------------------------------------------------------
  7. ' *** Version:        1.0
  8. ' *** Notes:        Used by UserAccounts.hta
  9. ' *** ------------------------------------------------------------------------------
  10. ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
  11. ' *** ------------------------------------------------------------------------------
  12. ' ***
  13.  
  14. ' ~~~ 
  15. ' ~~~ Force variables to be declared and turn off script error messages unless in DEBUG mode
  16. ' ~~~ 
  17. Option Explicit
  18.  
  19.  
  20. Select Case Window.DialogArguments
  21.      Case "ProfileMgr"
  22.          document.title = L_sManageTitle_TEXT
  23.      Case "Restrictions"
  24.          document.title = L_sRestrictTitle_TEXT
  25. End Select    
  26.  
  27. ' ~~~ -------------------------------------------------------------------------
  28. ' ~~~ Declare variables 
  29. ' ~~~ ------------------------------------------------------------------------
  30. Dim sTool, oUserAccount, colUsers
  31.  
  32. ' ***
  33. ' *** ------------------------------------------------------------------------------
  34. ' *** Name:            Init()
  35. ' *** ------------------------------------------------------------------------------
  36. ' *** Purpose:        This function is executed whilst the spash screen is displayed
  37. ' ***                If this function returns false, the spash screen is not removed
  38. ' *** ------------------------------------------------------------------------------
  39. ' ***
  40. Sub Init
  41.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  42.  
  43.     Dim oCol, colImages, oImage
  44.  
  45.     Set oUserAccount = New UserAccounts
  46.     sTool = Window.DialogArguments
  47.  
  48.     Select Case sTool
  49.         Case "ProfileMgr"
  50.             call oUserAccount.ListAccounts("ProfileMgr")
  51.         Case "Restrictions"
  52.             call oUserAccount.ListAccounts("Restrictions")
  53.     End Select
  54.     
  55.     ' ~~~ Get the images collections and make them invisible
  56.     Set colImages = document.body.GetElementsbyTagname("IMG") 
  57.     
  58.     For Each oImage in colImages
  59.         oImage.Style.Visibility = "hidden"
  60.     Next
  61.     
  62.     ' ~~~ Get the users collection and highlight the first valid user
  63.     Set colUsers = document.body.GetElementsbyTagname("U")
  64.  
  65.     ' ~~~ If the collection is not null then proceed
  66.     If Not IsNull(colUsers) Then
  67.         For each oCol in colUsers 
  68.             oCol.classname = "selectuser"
  69.             document.all("img" & Mid(oCol.id,4)).style.visibility = "visible"
  70.             Call User_mouseover(oCol.id)
  71.             'document.all("td" & Mid(oCol.id,4)).ScrollIntoView( False)
  72.             Exit For
  73.         Next
  74.     End If
  75.     
  76. End Sub
  77.  
  78. ' ***
  79. ' *** ------------------------------------------------------------------------------
  80. ' *** Name:            Load()
  81. ' *** ------------------------------------------------------------------------------
  82. ' *** Purpose:        This subroutine is executed before a wizard page is displayed
  83. ' *** ------------------------------------------------------------------------------
  84. ' ***
  85. Sub Load
  86.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0 
  87.  
  88.     ' ~~~ To enable Esc and Enter when the hta is launched
  89.     oBody.disabled = false    
  90.     document.body.focus()
  91.  
  92. End Sub
  93.  
  94.  
  95. ' ***
  96. ' *** ------------------------------------------------------------------------------
  97. ' *** Name:            UserMain()
  98. ' *** ------------------------------------------------------------------------------
  99. ' *** Purpose:        This function is executed on load of the HTA
  100. ' *** ------------------------------------------------------------------------------
  101. ' ***
  102. Sub UserMain
  103.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  104.  
  105.     ' ~~~ Disable the body on load
  106.     oBody.disabled = True
  107.         
  108.     InitialiseAllObjects()
  109.     
  110.     ' ~~~ set up the screen, load controls and pages
  111.     Call Setup()
  112.  
  113.     ' ~~~ call the tool initalization function
  114.     Call Init()
  115.     
  116.     ' ~~~ Call the tool load function
  117.     Call Load()
  118.             
  119. End Sub
  120.  
  121. ' ***
  122. ' *** ------------------------------------------------------------------------------
  123. ' *** Name:            Validate()
  124. ' *** ------------------------------------------------------------------------------
  125. ' *** Purpose:        This function is executed before a wizard page is exited
  126. ' ***            If this function returns True The page is ready to close.
  127. ' *** ------------------------------------------------------------------------------
  128. ' ***
  129. Function Validate()
  130.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  131.     
  132.     Validate = True
  133. End Function
  134.  
  135. ' ***
  136. ' *** ------------------------------------------------------------------------------
  137. ' *** Name:            Action()
  138. ' *** ------------------------------------------------------------------------------
  139. ' *** Purpose:        This function is executed when enter key/ok button is pressed
  140. ' *** ------------------------------------------------------------------------------
  141. ' ***
  142. Function Action()
  143.     userenter()
  144. End Function
  145.  
  146.  
  147. ' ***
  148. ' *** ------------------------------------------------------------------------------
  149. ' *** Name:            AddUsers(sUserName, bUser, sDisplayName)
  150. ' *** ------------------------------------------------------------------------------
  151. ' *** Purpose:        This function is executed to add the users to display in 
  152. ' ***                the Modal dialog
  153. ' *** ------------------------------------------------------------------------------
  154. ' ***
  155. Sub AddUsers(sUserName, iUser, sDisplayName)
  156.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  157.  
  158.     Dim sHTML1, sHTML2, oRow, oColumn
  159.  
  160.     Select Case iUser
  161.         Case 0 
  162.             sHTML1 = "<img id=""img" + sUserName + """ style=""cursor=hand"" align=""absmiddle"" onclick=""userenter()"" src=""graphics/green_half.gif"">"
  163.             sHTML2 = "<u id=""usr" + sUserName + """ onclick=""User_Select(window.event.srcelement.id)"" onmouseover=""User_mouseover(window.event.srcelement.id)"" style=""cursor:hand;"" class=""unselectuser"">" + sDisplayName + "</u>"
  164.         Case 1
  165.             sHTML1 = ""
  166.             sHTML2 = "<span id=""cln" + sUserName + """ onmouseover=""User_mouseover(window.event.srcelement.id)""  class=""unselectuser"">" + sDisplayName + "</span>"
  167.         Case 2
  168.             sHTML1 = ""
  169.             sHTML2 = "<span id=""adm" + sUserName + """ onmouseover=""User_mouseover(window.event.srcelement.id)""  class=""unselectuser"">" + sDisplayName + "</span>"
  170.         Case 3
  171.             sHTML1 = ""
  172.             sHTML2 = "<span id=""sln" + sUserName + """ onmouseover=""User_mouseover(window.event.srcelement.id)"" class=""unselectuser"">" + sDisplayName + "</span>"
  173.         Case 4
  174.             sHTML1 = "<img id=""img" + sUserName + """ style=""cursor=hand"" align=""absmiddle"" onclick=""userenter()"" src=""graphics/green_half.gif"">"
  175.             sHTML2 = "<u id=""loc" + sUserName + """ onclick=""User_Select(window.event.srcelement.id)"" onmouseover=""User_mouseover(window.event.srcelement.id)""  style=""cursor:hand;"" class=""unselectuser"">" + sDisplayName + "</u>"
  176.         Case 5
  177.             sHTML1 = "<img id=""img" + sUserName + """ style=""cursor=hand"" align=""absmiddle"" onclick=""userenter()"" src=""graphics/green_half.gif"">"
  178.             sHTML2 = "<u id=""dis" + sUserName + """ onclick=""User_Select(window.event.srcelement.id)"" onmouseover=""User_mouseover(window.event.srcelement.id)""  style=""cursor:hand;"" class=""unselectuser"">" + sDisplayName + "</u>"
  179.         Case 6 
  180.             sHTML1 = ""
  181.             sHTML2 = "<span id=""nop" + sUserName + """ onmouseover=""User_mouseover(window.event.srcelement.id)""  class=""unselectuser"">" + sDisplayName + "</span>"
  182.         Case 7
  183.             sHTML1 = ""
  184.             sHTML2 = "<span id=""gst" + sUserName + """ onmouseover=""User_mouseover(window.event.srcelement.id)""  class=""unselectuser"">" + sDisplayName + "</span>"
  185.     End Select
  186.     
  187.     ' ~~~ To add columns in to the table
  188.     Set oRow = tUsers.insertrow()
  189.     Set oColumn = oRow.insertcell()
  190.     oColumn.innerHTML = sHTML1
  191.     oColumn.id = "td" + sUserName
  192.     Set oColumn = Nothing
  193.     
  194.     Set oColumn = oRow.insertcell()
  195.     oColumn.innerHTML = sHTML2
  196.     Set oColumn = Nothing
  197.         
  198. End Sub
  199.  
  200. ' ***
  201. ' *** ------------------------------------------------------------------------------
  202. ' *** Name:            User_Select(sUser)
  203. ' *** ------------------------------------------------------------------------------
  204. ' *** Purpose:        This function is executed on click of the user name
  205. ' *** ------------------------------------------------------------------------------
  206. ' ***
  207. Sub User_Select(sUser)
  208.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  209.     
  210.     Dim sdisplayname
  211.     sdisplayname = document.all(sUser).innerText
  212.     if document.all(sUser).classname = "selectuser" then
  213.         ' ~~~ Extract the user name for Restrictions Tool
  214.         ' ~~~ For ProfileMgr send the user name with the prefix
  215.         
  216.         If Window.DialogArguments = "Restrictions" Then
  217.             sUser = Mid(sUser,4)
  218.         End If
  219.         window.returnValue = Array(sUser,sdisplayname)
  220.         window.close
  221.     End If
  222. End Sub
  223.  
  224. ' ***
  225. ' *** ------------------------------------------------------------------------------
  226. ' *** Name:            User_mouseover(strUser)
  227. ' *** ------------------------------------------------------------------------------
  228. ' *** Purpose:        This function is executed on click of the user name
  229. ' *** ------------------------------------------------------------------------------
  230. ' ***
  231. Sub User_mouseover(strUser)
  232.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  233.  
  234.     Dim oCol
  235.  
  236.     Select Case Left(strUser,3)
  237.         Case "usr"
  238.             if window.DialogArguments = "ProfileMgr" Then
  239.                 document.all(struser).title = document.all("ManageProfile").innerHTML
  240.                 document.all("img" & Mid(struser,4)).title =  document.all("ManageProfile").innerHTML
  241.             Else
  242.                 document.all(struser).title = document.all("RestrictProfile").innerHTML
  243.                 document.all("img" & Mid(struser,4)).title = document.all("RestrictProfile").innerHTML
  244.             End If
  245.         Case "cln"
  246.             document.all(struser).title = document.all("Currentlogon").innerHTML
  247.         Case "sln"
  248.             document.all(struser).title = document.all("switchlogon").innerHTML
  249.         Case "adm"
  250.             document.all(struser).title = document.all("Admin").innerHTML
  251.         Case "dis"
  252.             if window.DialogArguments = "ProfileMgr" Then
  253.                 document.all(struser).title =     document.all("DisabledAcc").innerHTML + " " + document.all("ManageProfile").innerHTML
  254.                 document.all("img" & Mid(struser,4)).title = document.all("DisabledAcc").innerHTML + " " + document.all("ManageProfile").innerHTML
  255.             Else
  256.                 document.all(struser).title = document.all("DisabledAcc").innerHTML + " " + document.all("RestrictProfile").innerHTML
  257.                 document.all("img" & Mid(struser,4)).title = document.all("DisabledAcc").innerHTML + " " + document.all("RestrictProfile").innerHTML
  258.             End If
  259.             
  260.         Case "loc"
  261.             If window.DialogArguments = "ProfileMgr" Then
  262.                 document.all(struser).title = document.all("LockedAccount").innerHTML + " " + document.all("ManageProfile").innerHTML
  263.                 document.all("img" & Mid(struser,4)).title = document.all("LockedAccount").innerHTML + " " + document.all("ManageProfile").innerHTML
  264.             Else
  265.                 document.all(struser).title = document.all("LockedAccount").innerHTML + " " + document.all("RestrictProfile").innerHTML    
  266.                 document.all("img" & Mid(struser,4)).title = document.all("LockedAccount").innerHTML + " " + document.all("RestrictProfile").innerHTML    
  267.             End If
  268.         Case "nop"
  269.             document.all(struser).title = document.all("NoProfile").innerHTML
  270.         Case "gst"
  271.             document.all(struser).title = document.all("Guest").innerHTML
  272.     End Select
  273.     
  274.     ' ~~~ onmouseover high light the user if it is a valid user account
  275.     Select Case Left(strUser,3)
  276.         Case "usr" , "loc" , "dis"
  277.             If Not IsNull(colUsers) Then
  278.                 For each oCol in colUsers 
  279.                     If oCol.classname = "selectuser" Then
  280.                         oCol.classname = "unselectuser"
  281.                         document.all("img" & Mid(oCol.id,4)).style.visibility = "hidden"
  282.                         exit for
  283.                     End If
  284.                 next
  285.             End If
  286.             
  287.             document.all(strUser).classname = "selectuser"
  288.             document.all("img" & Mid(strUser,4)).style.visibility = "visible"
  289.             ' ~~~ Set the focus on to the column holding the images
  290.             'document.all("td" & Mid(strUser,4)).ScrollIntoView (False )
  291.     End Select
  292.     
  293. End Sub
  294.  
  295. ' ***
  296. ' *** ------------------------------------------------------------------------------
  297. ' *** Name:            GetHoverText(strUser)
  298. ' *** ------------------------------------------------------------------------------
  299. ' *** Purpose:        This function is executed when the user hovers the 
  300. ' ***                       mouse over the user account names
  301. ' *** ------------------------------------------------------------------------------
  302. ' ***
  303. Function GetHoverText(strUser)
  304.  
  305. End Function
  306.  
  307. ' ***
  308. ' *** ------------------------------------------------------------------------------
  309. ' *** Name:            HTAKeyDown()
  310. ' *** ------------------------------------------------------------------------------
  311. ' *** Purpose:        This function is called when any key is pressed while the  
  312. ' ***                       useraccount dialog is active
  313. ' *** ------------------------------------------------------------------------------
  314. ' ***
  315. Sub HTAKeyDown()
  316.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  317.  
  318.     If window.event.keycode = 27 Then
  319.         self.Close()
  320.     ElseIf window.event.keycode = 38 Then 
  321.         call moveup()    
  322.     ElseIf window.event.keycode = 40 Then
  323.         call movedown()
  324.     ElseIf window.event.keycode = 13 Then
  325.         Call userenter()
  326.     End If
  327. End Sub
  328.  
  329. ' ***
  330. ' *** ------------------------------------------------------------------------------
  331. ' *** Name:            moveup()
  332. ' *** ------------------------------------------------------------------------------
  333. ' *** Purpose:        This function is executed on click of the user name
  334. ' *** ------------------------------------------------------------------------------
  335. ' ***
  336. Sub moveup
  337.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  338.     Dim ocol, prevUserId,currUserId
  339.         For each ocol in colUsers
  340.             If ocol.classname = "selectuser" Then
  341.                 Set currUserId = ocol
  342.                 Exit For
  343.             Else
  344.                 Set prevUserId = ocol
  345.             End IF
  346.          next
  347.     
  348.       If Not IsEmpty(prevUserId) Then
  349.           ' ~~~ Change the class of the previous and current users
  350.           currUserId.classname="unselectuser"
  351.           document.all("img" & Mid(currUserId.id,4)).style.visibility = "hidden"
  352.           prevUserId.classname="selectuser"
  353.           document.all("img" & Mid(prevUserId.id,4)).style.visibility = "visible"
  354.           
  355.           ' ~~~ Call the mouseover sub to display text
  356.           User_mouseover(prevUserId.id)
  357.           
  358.           ' ~~~ Scroll to the selected user
  359.           'document.all("td" & Mid(prevUserId.id,4)).ScrollIntoView(True)
  360.        End If
  361. End Sub
  362.  
  363. ' ***
  364. ' *** ------------------------------------------------------------------------------
  365. ' *** Name:            movedown()
  366. ' *** ------------------------------------------------------------------------------
  367. ' *** Purpose:        This function is executed on click of the user name
  368. ' *** ------------------------------------------------------------------------------
  369. ' ***
  370. Sub movedown
  371.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  372.     Dim bseluser, ocol, SelUserId, newSelUserId
  373.     bseluser = False
  374.         For each ocol in colUsers 
  375.             If bseluser = True Then
  376.                 Set newSelUserId = ocol
  377.                 exit for
  378.             End If
  379.             If ocol.classname = "selectuser" Then
  380.                 bseluser = True
  381.                 Set SelUserId = ocol
  382.             End If
  383.          next
  384.     
  385.      If Not IsEmpty(newSelUserId) Then
  386.          ' ~~~ Change the class of the previous and current users
  387.          SelUserId.classname = "unselectuser"
  388.          document.all("img" & Mid(SelUserId.id,4)).style.visibility = "hidden"
  389.          newSelUserId.classname = "selectuser"
  390.          document.all("img" & Mid(newSelUserId.id,4)).style.visibility = "visible"
  391.          ' ~~~ Call the mouseover sub to display text
  392.          User_mouseover(newSelUserId.id)
  393.          
  394.          ' ~~~ Scroll to the image next to the selected user
  395.          'document.all("td" & Mid(newSelUserId.id,4)).ScrollIntoView(False)
  396.      End If
  397. End Sub
  398.  
  399. ' ***
  400. ' *** ------------------------------------------------------------------------------
  401. ' *** Name:            userenter()
  402. ' *** ------------------------------------------------------------------------------
  403. ' *** Purpose:        This function is executed on click of the user name
  404. ' *** ------------------------------------------------------------------------------
  405. ' ***
  406. Sub userenter
  407.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  408.     Dim ocol
  409.     ' ~~~ If the collection is not null then proceed
  410.      If Not IsNull(colUsers) Then
  411.         For each ocol in colUsers
  412.             If ocol.classname = "selectuser" Then
  413.                 ' ~~~ Call the user_select sub to return the user name
  414.                 User_Select(ocol.id)
  415.                 Exit For
  416.             End If
  417.          Next
  418.      End If
  419. End Sub
  420.  
  421. ' ***
  422. ' *** ------------------------------------------------------------------------------
  423. ' *** Name:            HTAUnLoad()
  424. ' *** ------------------------------------------------------------------------------
  425. ' *** Purpose:        This method unloads all the objects 
  426. ' ***            created within the scope of the HTA
  427. ' *** ------------------------------------------------------------------------------
  428. ' ***
  429. Sub HTAUnLoad()
  430.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  431.     
  432.     Set oUserAccount = Nothing
  433.     
  434. End Sub