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

  1. ' ***
  2. ' *** ------------------------------------------------------------------------------
  3. ' *** Filename:        clsWelcome.vbs
  4. ' *** ------------------------------------------------------------------------------
  5. ' *** Description:        Welcome Class
  6. ' *** ------------------------------------------------------------------------------
  7. ' *** Version:        1.0
  8. ' *** Notes:        
  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. Class Welcome
  21.  
  22. ' ~~~ ------------------------------------------------------------------------------
  23. ' ~~~ declare variables and constants
  24. ' ~~~ ------------------------------------------------------------------------------
  25. Private sUID, bLocal, bDisabled, strRegPath, bLogging
  26.  
  27. ' ~~~ ------------------------------------------------------------------------------
  28. ' ~~~ public properties
  29. ' ~~~ -----------------------------------------------------------------------------
  30.  
  31. ' ***
  32. ' *** ------------------------------------------------------------------------------
  33. ' *** Property:    Logging
  34. ' *** ------------------------------------------------------------------------------
  35. ' *** Purpose:    Turns on logging, property must be set to a logging object
  36. ' *** ------------------------------------------------------------------------------
  37. ' ***
  38. Public Property Get Logging
  39.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0    
  40.     Logging = bLogging
  41. End Property 
  42.  
  43. Public Property Let Logging(oObject)
  44.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  45.     If VarType(oObject) = vbObject Then
  46.         bLogging = True
  47.         Set oLog = oObject
  48.     End If
  49. End Property
  50.  
  51. ' ***
  52. ' *** ------------------------------------------------------------------------------
  53. ' *** Property:    User
  54. ' *** ------------------------------------------------------------------------------
  55. ' *** Purpose:    Username of account modify
  56. ' *** ------------------------------------------------------------------------------
  57. ' ***
  58. Public Property Get User
  59.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  60.     User = sUID
  61. End Property    
  62.  
  63. Public Property Let User(strUser)
  64.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  65.     sUID = strUser
  66.     bLocal = IsLocalUser(strUser)
  67.     bDisabled = CheckDisabled(strUser)
  68. End Property
  69.  
  70. ' ***
  71. ' *** ------------------------------------------------------------------------------
  72. ' *** Property:    IsDisabled
  73. ' *** ------------------------------------------------------------------------------
  74. ' *** Purpose:    Is the User already disabled from Windows Welcome
  75. ' *** ------------------------------------------------------------------------------
  76. ' ***
  77. Public Property Get IsDisabled
  78.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  79.     IsDisabled = bDisabled
  80. End Property
  81.  
  82. ' ***
  83. ' *** ------------------------------------------------------------------------------
  84. ' *** Property:    IsLocal
  85. ' *** ------------------------------------------------------------------------------
  86. ' *** Purpose:    Is the account a local account?
  87. ' *** ------------------------------------------------------------------------------
  88. ' ***
  89. Public Property Get IsLocal
  90.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  91.     IsLocal = bLocal
  92. End Property
  93.  
  94. ' ~~~ ------------------------------------------------------------------------------
  95. ' ~~~ public methods
  96. ' ~~~ ------------------------------------------------------------------------------
  97.  
  98. ' ***
  99. ' *** ------------------------------------------------------------------------------
  100. ' *** Name:        Enable
  101. ' *** ------------------------------------------------------------------------------
  102. ' *** Purpose:    Enables the user account, by removing the account from the
  103. ' ***        UserList Key of the SpecialAccounts in the reigstry.
  104. ' *** ------------------------------------------------------------------------------
  105. ' ***
  106. Public Function Enable
  107.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  108.     If bLocal Then
  109.         If bDisabled = False Then 
  110.             ' ~~~ Account already disabled
  111.             Enable = 2
  112.         Else
  113.             ' ~~~ Add account to Special Accounts list
  114.             Call RegDelete(strRegPath & sUID)
  115.             Enable = 0
  116.         End If
  117.     Else
  118.         ' ~~~ Not a local account
  119.         Enable = 1
  120.     End If
  121.  
  122. End Function
  123.  
  124. ' ***
  125. ' *** ------------------------------------------------------------------------------
  126. ' *** Name:        Disable
  127. ' *** ------------------------------------------------------------------------------
  128. ' *** Purpose:    Disables the user account, by adding the account in the
  129. ' ***        UserList Key of the SpecialAccounts in the  reigstry.
  130. ' *** ------------------------------------------------------------------------------
  131. ' ***
  132. Public Function Disable
  133.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  134.     If bLocal Then
  135.         If bDisabled = True Then
  136.             ' ~~~ Account already disabled
  137.             Disable = 2
  138.         Else
  139.             ' ~~~ Disable the account by adding it to the Special Accounts list
  140.             Call RegWrite(strRegPath & sUID, 0, "REG_DWORD")
  141.             Disable = 0
  142.         End If
  143.     Else
  144.         ' ~~~ Not a local account
  145.         Disable = 1
  146.     End If
  147.  
  148. End Function
  149.  
  150. ' ~~~ -------------------------------------------------------------------------
  151. ' ~~~ private methods
  152. ' ~~~ -------------------------------------------------------------------------
  153.  
  154. ' ***
  155. ' *** ------------------------------------------------------------------------------
  156. ' *** Name:        Class_Initialize
  157. ' *** ------------------------------------------------------------------------------
  158. ' *** Purpose:    Used internally by the class when it is created.
  159. ' ***            Declared as private because it must not be called directly.
  160. ' *** ------------------------------------------------------------------------------
  161. ' ***
  162. Private Sub Class_Initialize
  163.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  164.     ' ~~~ set default values for properties
  165.     bLogging = False
  166.  
  167.     strRegPath = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\winlogon\SpecialAccounts\UserList\"
  168.     
  169. End Sub
  170.  
  171. ' ***
  172. ' *** ------------------------------------------------------------------------------
  173. ' *** Name:        Class_Terminate
  174. ' *** ------------------------------------------------------------------------------
  175. ' *** Purpose:    Used internally by the class when it is destroyed.
  176. ' ***            Declared as private because it must not be called directly.
  177. ' *** ------------------------------------------------------------------------------
  178. ' ***
  179. Private Sub Class_Terminate
  180.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  181. End Sub
  182.  
  183. ' ***
  184. ' *** ------------------------------------------------------------------------------
  185. ' *** Name:            IsLocalUser(strUser)
  186. ' *** ------------------------------------------------------------------------------
  187. ' *** Purpose:        Returns true if the specified account is a local user
  188. ' *** ------------------------------------------------------------------------------
  189. ' ***
  190. Private Function IsLocalUser(strUser)
  191.     On Error Resume Next
  192.  
  193.     Dim oUser
  194.     Set oUser = GetObject("WinNT://" & sComputer & "/" & strUser & ",user")
  195.  
  196.     If Err.Number <> 0 Then
  197.         ' ~~~ Couldn't find the user, doesn't exist
  198.         IsLocalUser = False
  199.     Else
  200.         ' ~~~ User exists!
  201.         IsLocalUser = True
  202.     End If
  203.  
  204. End Function
  205.  
  206. ' ***
  207. ' *** ------------------------------------------------------------------------------
  208. ' *** Name:            CheckDisabled(strUser)
  209. ' *** ------------------------------------------------------------------------------
  210. ' *** Purpose:        Checks whether the user is already enabled/disabled        
  211. ' *** ------------------------------------------------------------------------------
  212. ' ***
  213. Private Function CheckDisabled(strUser)
  214.     On Error Resume Next
  215.  
  216.     Dim strDisabled
  217.  
  218.     strdisabled = RegRead(strRegPath & strUser)
  219.  
  220.     If IsNull(strdisabled) Then
  221.         CheckDisabled = False
  222.     Else
  223.         CheckDisabled = True
  224.     End If    
  225.  
  226. End Function
  227.  
  228.  
  229. End Class