home *** CD-ROM | disk | FTP | other *** search
- ' ***
- ' *** --------------------------------------------------------------------------
- ' *** Filename: ProfileMgr.vbs
- ' *** --------------------------------------------------------------------------
- ' *** Description: Code for the User Profiles HTA
- ' *** --------------------------------------------------------------------------
- ' *** Version: 1.0
- ' *** Notes:
- ' *** --------------------------------------------------------------------------
- ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
- ' *** --------------------------------------------------------------------------
- ' ***
-
- ' ~~~
- ' ~~~ Force variables to be declared and turn off script error messages unless in DEBUG mode
- ' ~~~
- Option Explicit
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- ' ~~~
- ' ~~~ Declare global variables
- ' ~~~
- Dim oProfileMgr, oLog
-
- ' ***
- ' *** --------------------------------------------------------------------------
- ' *** Name: Init
- ' *** --------------------------------------------------------------------------
- ' *** Purpose: This function is initiated by Main, which is called by
- ' *** OnLoad
- ' *** --------------------------------------------------------------------------
- ' ***
- Sub Init()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- ' ~~~ Turn on error handling
- On Error Resume Next
-
- Set oProfileMgr = New ProfileMgr
- Set oLog = New Logging
- oLog.Open(GetRootFolder & "\log\ProfileMgr.hta.log")
- oLog.write("ProfileMgr.hta : Started")
- oProfileMgr.Logging = oLog
-
- End Sub
-
- ' ***
- ' *** --------------------------------------------------------------------------
- ' *** Name: Load
- ' *** --------------------------------------------------------------------------
- ' *** Purpose: This function is initiated by Main to Load the UI.
- ' *** --------------------------------------------------------------------------
- ' ***
- Sub Load()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- ' ~~~ Call the Sub to create the drive lists
- Call CreateDrivelist()
-
- ' ~~~ To add the drives
- Call PopulateDrives()
-
- ' ~~~ Call the sub to enable body
- Call BodyDisable(False)
-
- ' ~~~ disabling the controls
- ddDrives.disabled = true
- UserPass.disabled = true
- txtAccount.readonly = True
- btnSelectAccounts.setactive()
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Validate()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: This function is executed before a wizard page is exited
- ' *** If this function returns True The page is ready to close.
- ' *** ------------------------------------------------------------------------------
- ' ***
- Function Validate()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- Validate = True
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: Action()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: This function is executed when enter key/close button is pressed
- ' *** There is no action for close button
- ' *** ------------------------------------------------------------------------------
- ' ***
- Function Action()
-
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: UserAccounts_Click()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: This subroutine is executed on the click of CreateUserAccounts button
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub UserAccounts_Click()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- oLog.write("UserAccounts: Started")
- oProfileMgr.CreateUserAccounts()
- ' ~~~ If an account is deleted remove the account if it is currently selected.
- If oProfileMgr.GetUserSID(document.all("txtAccount").value) = "" Then
- document.all("txtAccount").value = ""
- RefreshAccount ""
- End If
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: CreateProfiles_Click()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Creates the profile for the selected user
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub CreateProfiles_Click()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Dim sUser
-
- bProcessing = True
-
- oLog.write("ProfileMgr.hta - CreateProfile: Started")
-
- If txtAccount.value <> "" Then
- sUser = Mid(oProfileMgr.UserSelected,4)
- If IsValidAccount(sUser) = False then
- MsgBox sUser & " " & NoUserAcc.innerHTML, vbOKOnly+vbCritical, sTitle
- oLog.write("ProfileMgr.hta - CreateProfile: Account does not exist")
- Exit Sub
- End If
- Call ToggleClose(True)
- oLog.write("ProfileMgr.hta - CreateProfile for user: " & sUser)
- if oProfileMgr.CreateProfiles (sUser, Trim(UserPass.value),".", ddDrives.Value) = "0" Then
-
- MsgBox CreateSuccess.innerHTML, vbOKOnly+vbInformation, sTitle
- oLog.write("ProfileMgr.hta - CreateProfile: Success")
-
- Call ToggleClose(False)
-
- ' ~~~ Clear the password field
- UserPass.Value=""
- RefreshAccount Mid(oProfileMgr.UserSelected,4)
- Else
- MsgBox CreateFailed.innerHTML, vbOKOnly+vbCritical, sTitle
- oLog.write("ProfileMgr.hta - CreateProfile: Error - Wrong Password or username")
- oLog.write("ProfileMgr.hta - CreateProfile: Failed")
- Call ToggleClose(False)
-
- ' ~~~ Clear the password field
- UserPass.Value = ""
- End If
-
- Else
- MsgBox UserAcc.innerHTML, vbOKOnly+vbCritical, sTitle
- End If
-
- oLog.write("ProfileMgr.hta - CreateProfile: Completed")
-
- bProcessing = False
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: DeleteProf_Click()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Deletes the selected user's profile
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub DeleteProf_Click()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Dim sUser
-
- bProcessing = True
-
- oLog.write("ProfileMgr.hta - DeleteProfile: Started")
-
- ' ~~~ Call the DeleteProfiles function in the class
- If txtAccount.value <> "" Then
- sUser = Mid(oProfileMgr.UserSelected,4)
- If Msgbox ( DeleteWarningText.innerHTML , VbYesNo+vbQuestion , DeleteWarningTitle.innerHTML & " " & txtAccount.value) = VbYes Then
- If IsValidAccount(sUser) = False then
- MsgBox sUser & " " & NoUserAcc.innerHTML, vbOKOnly+vbCritical, sTitle
- bProcessing = False
- oLog.write("ProfileMgr.hta - DeleteProfile: Account does not exist")
- Exit Sub
- End If
- oLog.write("ProfileMgr.hta - DeleteProfile for user: " & sUser)
- Call ToggleClose(True)
- if oProfileMgr.DeleteProfiles (sUser, "") = "0" Then
- MsgBox DeleteSuccess.innerHTML, vbOKOnly+vbInformation, sTitle
- oLog.write("ProfileMgr.hta - DeleteProfile: Success")
- Call ToggleClose(False)
-
- ' ~~~ Clear the password field
- UserPass.Value=""
- RefreshAccount Mid(oProfileMgr.UserSelected,4)
- Else
- MsgBox DeleteFailed.innerHTML, vbOKOnly+vbCritical, sTitle
- oLog.write("ProfileMgr.hta - DeleteProfile: Failed")
- Call ToggleClose(False)
-
- ' ~~~ Clear the password field
- UserPass.Value = ""
- End If
- End If
- Else
- MsgBox UserAcc.innerHTML, vbOKOnly+vbCritical, sTitle
- End If
- oLog.write("ProfileMgr.hta - DeleteProfile: Completed")
- bProcessing = False
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: CreateDrivelist()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: This subroutine is executed to create an empty drive list
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub CreateDrivelist()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Dim sId, sStyle, sDefault
-
- ' ~~~ populate drive drop-down list
- sId = "id=""ddDrives"" "
- sStyle = "style="" width=100%;"""
- tdDrives.innerHTML = "<select " & sId & sStyle & ">" & "</select>"
-
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: add_option(sValue)
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: This subroutine is executed to add the drive ID
- ' *** to the drop down lists
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub add_option(sValue)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Dim oOption
-
- Set oOption = document.CreateElement("OPTION")
-
- oOption.text = sValue
- oOption.Value = sValue
- ddDrives.add(oOption)
-
- Set oOption = Nothing
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: RefreshAccount(strUserName)
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: This subroutine is executed when a user's profile is deleted/created
- ' *** and also while changing the user
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub RefreshAccount(strUserName)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Dim ProfilePath, sUser
-
- if strUserName <> "" Then
- sUser = strUserName
- ProfilePath = oProfileMgr.GetProfilePath(sUser)
- UserPass.Value = ""
-
- ddDrives.disabled = false
- UserPass.disabled = false
-
- If ProfilePath = "" Then
- ' ~~~ Set the default display in the drives ddlist
- ddDrives.Value = Defaultdrive.innerHTML
- btnCreateProfiles.Style.Visibility = "Visible"
- btnDeleteProfiles.Style.Visibility = "hidden"
- ' ~~~ disable
- btnDeleteProfiles.disabled = true
- btnCreateProfiles.disabled = false
- Else
- ' ~~~ Extract the drive of the Profile
- ProfilePath = UCase(Left(ProfilePath,2))
-
- ' ~~~ Display the drive of the profile in drives dd list
- ddDrives.Value = ProfilePath
- btnCreateProfiles.Style.Visibility = "hidden"
- btnDeleteProfiles.Style.Visibility = "Visible"
- ' ~~~ disable
- btnDeleteProfiles.disabled = false
- btnCreateProfiles.disabled = true
- ddDrives.disabled = true
- UserPass.disabled = true
-
- End If
- Else
- ddDrives.Value = Defaultdrive.innerHTML
- UserPass.Value = ""
-
- btnCreateProfiles.Style.Visibility = "Visible"
- btnDeleteProfiles.Style.Visibility = "Visible"
-
- ' ~~~ disable the buttons
- ddDrives.disabled = true
- UserPass.disabled = true
- btnCreateProfiles.disabled = false
- btnDeleteProfiles.disabled = false
- End If
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: SelectAccount()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: To select the user account from the user account list
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub SelectAccount()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Dim strUser, arrReturnValue
-
- bProcessing = True
-
- ' ~~~ get the username from the modal dialog
- arrReturnValue = Window.ShowModalDialog("UserAccounts.hta", "ProfileMgr", "dialogWidth:15;dialogHeight:10;Center:Yes;help:No;Resizable:No;")
-
- If NOT IsEmpty(arrReturnValue) Then
-
- ' ~~~ display the user name
- txtAccount.value = arrReturnValue(1)
-
- ' ~~~ Extract the account name from
- strUser = arrReturnValue(0)
-
- ' ~~~ Set the UserSelected property
- oProfileMgr.UserSelected = strUser
-
- ' ~~~ Set the userdisabled property
- If Left(strUser,3) = "dis" Then
- oProfileMgr.IsUserDisabled = True
- Else
- oProfileMgr.IsUserDisabled = False
- End If
-
- oLog.write("ProfileMgr.hta - Name of the account selected: " & Mid(strUser,4))
- ' ~~~ call the onchange user function
- RefreshAccount Mid(strUser,4)
- End If
- bProcessing = False
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: ToggleClose(bToggle)
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: This subroutine is executed to toggle the close button.
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub ToggleClose(bToggle)
-
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- If bToggle = True Then
- btnFinish.disabled = True
- btnFinish.style.cursor = "auto"
- ' ~~~ To change the cursor to wait icon
- BodyDisable(True)
-
- Else
- btnFinish.disabled = False
- btnFinish.style.cursor = "hand"
- ' ~~~ To change the cursor to default
- BodyDisable(False)
- End If
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: CloseTxtClick()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: This subroutine is executed on the click of Close Text
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub CloseTxtClick()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- If Not(btnFinish.IsDisabled) Then
- Self.Close
- End If
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: HTAKeyDown()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: This is the handler function for tool specific key controls
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub HTAKeyDown()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- End Sub
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: PopulateDrives()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Returns a collection of drives in the system
- ' *** ------------------------------------------------------------------------------
- ' ***
- Function PopulateDrives()
-
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
-
- Dim colDiskDrives, oDisks
-
- const HARD_DISK = 3 ' ~~~ To check whether the drive is a hard disk
-
- Set colDiskDrives = oWMIService.ExecQuery _
- ("Select * from Win32_LogicalDisk where DriveType =" & HARD_DISK & "" )
-
- For Each oDisks in colDiskDrives
- ' ~~~ Do not display the drive if it is not formatted
- If oDisks.FileSystem <> "" Then
- ' ~~~ Call the sub routine to add the driveID
- add_option oDisks.DeviceID
- End If
- Next
-
- Set colDiskDrives = Nothing
-
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: IsValidAccount(userName)
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: Returns true if the user account exists or returns false
- ' *** ------------------------------------------------------------------------------
- ' ***
- Function IsValidAccount(userName)
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- Dim oAccounts, oUser
-
- IsValidAccount = False
- ' ~~~ get a list of user accounts on the local machine
- Set oAccounts = GetObject("WinNT://" & sComputer)
- oAccounts.Filter = Array("user")
- For Each oUser in oAccounts
- If oUser.Name = userName Then
- IsValidAccount = True
- Exit Function
- End If
- Next
- End Function
-
- ' ***
- ' *** ------------------------------------------------------------------------------
- ' *** Name: HTAUnLoad()
- ' *** ------------------------------------------------------------------------------
- ' *** Purpose: This method unloads all the objects
- ' *** created within the scope of the HTA
- ' *** ------------------------------------------------------------------------------
- ' ***
- Sub HTAUnLoad()
- If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
- Set oProfileMgr = Nothing
- Set oLog = Nothing
- End Sub