y"
    if([string]::IsNullorEmpty($key))
    {
        WriteFunctionExceptionReport $functionName $localizationString.throw_invalidKey
        return
    }
    if([string]::IsNullorEmpty($keyValue))
    {
        WriteFunctionExceptionReport $functionName $localizationString.throw_invalidKeyValue
        return
    }
    [string]$data = (Get-ItemProperty -Path $key -Name $keyValue).$keyValue

    $mskey = "HKLM:\Software\Microsoft\Shared Tools\MSConfig\startupreg"
    CreateRegistryKey $mskey
    [string]$newKeyPath = "$msKey\$keyValue"
    if(-not (Test-Path($newKeyPath)))
    {
        $newKey = New-Item -Path $msKey -Name $keyValue
        $date = [System.DateTime]::Now
        New-ItemProperty -Path $newKeyPath -Name "command" -PropertyType String -Value "$data" > $null
        New-ItemProperty -Path $newKeyPath -Name "hkey" -PropertyType String -Value $key.SubString(0, 4) > $null
        New-ItemProperty -Path $newKeyPath -Name "inimapping" -PropertyType String -Value "0" > $null
        New-ItemProperty -Path $newKeyPath -Name "item" -PropertyType String -Value "$keyValue" > $null
        New-ItemProperty -Path $newKeyPath -Name "key" -PropertyType String -Value $key.SubString(6) > $null
        New-ItemProperty -Path $newKeyPath -Name "DAY" -PropertyType DWORD -Value $date.Day > $null
        New-ItemProperty -Path $newKeyPath -Name "HOUR" -PropertyType DWORD -Value $date.Hour > $null
        New-ItemProperty -Path $newKeyPath -Name "MINUTE" -PropertyType DWORD -Value $date.Minute > $null
        New-ItemProperty -Path $newKeyPath -Name "SECOND" -PropertyType DWORD -Value $date.Second > $null
        New-ItemProperty -Path $newKeyPath -Name "MONTH" -PropertyType DWORD -Value $date.Month > $null
        New-ItemProperty -Path $newKeyPath -Name "YEAR" -PropertyType DWORD -Value $date.Year > $null
    }
}

#
# Backup the startup link file to "HKLM:\Software\Microsoft\Shared Tools\MSConfig\startupreg"
#
function BackupStartupLinkFile([System.IO.FileInfo]$file)
{
    [string]$functionName = "BackupStartupLinkFile"
    if($file -eq $null)
    {
        WriteFunctionExceptionReport $functionName $localizationString.throw_invalidFile
        return
    }
    [string]$backupPath = "$env:windir\pss"
    [string]$programData = "$env:SystemDrive\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup"
    [string]$commonStartup = ".CommonStartup"
    [string]$startup = ".Startup"
    [string]$backupExtension = ""
    if(-not(Test-Path($backupPath)))
    {
        New-Item -Path $backupPath -ItemType "directory" > $null
    }
    if( $file.DirectoryName -eq $programData)
    {
        $backupExtension = $commonStartup
    }
    else
    {
        $backupExtension = $startup
    }
    #
    # backup file
    #
    [string]$desFileName = $file.Name + $backupExtension
    Copy-Item -LiteralPath $file.FullName -Destination "$backupPath\$desFileName"
    #
    # backup registry key
    #
    $mskey = "HKLM:\Software\Microsoft\Shared Tools\MSConfig\startupfo# Copyright  2008, Microsoft Corporation. All rights reserved.


#
# Log other users off of the system
#

Import-LocalizedData -BindingVariable localizationString -FileName CL_LocalizationData
. .\CL_Utility.ps1

Write-DiagProgress -activity $localizationString.progress_rs_multipleUsers

$userInfoArray = GetLogonUsersInfo

if($userInfoArray -eq $null -or $userInfoArray.Count -lt 2)
{
    return
}

[string]$SESSOIN_ID = "sessionID"
[string]$USER_NAME = "userName"

$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
if ($currentUser -eq $null) {
    return
}

#
# Ask the user which users need be logged off
#
$choices = New-Object System.Collections.ArrayList

for([int]$i = 0; $i -lt $userInfoArray.Count; $i++)
{
    $ht = $userInfoArray[$i]
    if($ht -eq $null) {
        Continue
    }

    $userName = $ht["$USER_NAME"]
    if($userName -eq $currentUser)
    {
        Continue
    }
    $value = $ht["$SESSOIN_ID"]
    $choices += @{"Name" = "$userName"; "Description" = "$userName"; "Value" = "$value"}
}

if ($choices.Length -ge 1) {
    $sessionIDArray = Get-DiagInput -id "IT_MultipleUsers" -choice $choices
}
#
# Logs off a specified Terminal Services session.
#

if($sessionIDArray -ne $null)
{
$logoffDefinition = @"
    [DllImport("wtsapi32.dll", SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool WTSLogoffSession(IntPtr hServer, int SessionId, [MarshalAs(UnmanagedType.Bool)] bool bWait);
"@
    $logoffType = Add-Type -MemberDefinition $logoffDefinition -Name "logoffType" -UsingNamespace "System.Reflection","System.Diagnostics" -PassThru

    [string]$fileName = "RS_MultipleUsers"

    foreach($sessionID in $sessionIDArray)
    {
        [bool]$result = $logoffType::WTSLogoffSession([IntPtr]::Zero, $sessionID, $true)
        [int]$errorCode = [System.Runtime.InteropServices.Marshal]::GetLastWin32Error()
        if(-not $result)
        {
            WriteFileAPIExceptionReport $fileName "WTSLogoffSession" $errorCode
            return
        }
    }

    #
    # update report
    #
    $userArray = New-Object System.Collections.ArrayList
    for([int]$i = 0; $i -lt $userInfoArray.Count; $i++)
    {
        foreach($sessionID in $sessionIDArray)
        {
            if($userInfoArray[$i][$SESSOIN_ID] -eq $sessionID)
            {
                $userArray += $userInfoArray[$i][$USER_NAME]
            }
        }
    }
    $userArray | select-object -Property @{Name=$localizationString.multipleUsers_userName; Expression={$_}} | convertto-xml | Update-DiagReport -id LogoffUser -name $localizationString.logoffUser_name -verbosity Informational
}
