Pages

Thursday, November 11, 2010

VMware View 4.5 - Building the Windows 7 Thin Client (Part 2)

Note: that this works with all View Client versions View 4.5, 4.6 and 5.0.

Update 4-4-2011- Added the scripts and the fix windows size Powershell shell.

This post is part of a Series of Posts
The this guide will walk you through building a Thin Client will have the following details.
  • Running Windows 7
  • Using the PCoIP Protocol
  • User authentication based on AD
  • The Thin Client will have a replaced shell to limit the users to VMware View Client only.
  • The Client can be configured to use a particular Pool or offer the user any they have access
Thin Client OS Install
The Thin Client only needs to be protected and run VMware View. The OS is about the only software we need installed and I'll be reploying clones of this machine so I only plan to build it once by hand. Starting with a formated machine that's same as the hardware it'll be running on in the lab. I run a fresh Windows 7 install from DVD. After the Install with normal options for your enviroment. I make the following changes.
  • Updates service configured to auto update and download other microsoft updates
  • Install all possible Microsoft updates
  • Update any drivers
  • Disable UAC
  • Set for best performance
  • turn off system restore points
  • Enable remote desktop.
  • Stop and disable the Themes Service
  • Check that the newest version of  Powershell is installed
  • Change Power settings
    • Don't password protect awaking from sleep
    • Let Sleep monitor and/or machine
Creating a ViewUser and Changing its Shell

We need a Local User that we will use to run VMware View Client from. We could have users log in as themselves but I didn't for a the following reason. If we make users login to Windows. They would login to the machines, profile would be created, then View Client Launched, Authentication is passed, then finally the user is prompted for what VM they would like to access. After they select it they have to wait for it to login and create another profile. Very time consuming. We can skip all of the first profile copy issues by createing a already logged in local user. So Instead lets create the local user.
  • Create Local User: ViewUser
    • Set password and write it down.
    • Uncheck much change password at next logon
    • Check password never expires
    • Check user can not change password
    • No need to add user to any groups, just normal user access is fine.
Now, we want to change the User shell on only the ViewUser account. We are doing this so that when this account is logged it we control what the user gets. We want it so that when this users account logs in they don't get a start menu or anything but rather they only see a VMware View login prompt.  To do that for one account rather for all accounts on the machine we change the following.

  • Launch Regedit while logged into an administrator account.
  • Navigate to "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\IniFileMapping\system.ini\boot\"
  • Change the Entry "Shell" from this:
    • SYS:Software\Microsoft\Windows NT\CurrentVersion\Winlogon
  • To the following 
    • USR:Software\Microsoft\Windows NT\CurrentVersion\Winlogon
This means that when a account is logged in Windows will look for a Shell in that user's registry instead of just using the system default. If none is specified there, the system will then just use the systems default Shell (normally explorer).

Later we'll change the ViewUser'sShell however this change means that windows will listen to the setting when we do.

Shell Replacement Script to Launch VMware View Client

In order to control what the user gets as a shell I've created a PowerShell script to replace the Explorer.exe as the shell. The script is looks more complicated than it really is. All it really does is the following.
  • Replace Windows Shell with PowerShell script.
  • PowerShell script is Launched
  • Script Opens VMware View
    • Connect to the correct View Server
    • Clear the last users username
    • Make sure the window is centered
    • Hide the Tool Bar while Remote window is open
  • If the VMware View is exited, relaunch it.
  • Optional
    • Maximize View Client window if someone minimized it. (This is done by loading a user32.dll  and is a little messy.)
Download Links for Powershell Files

###########################
#
#  Purpose: Replacess The Windows Shell for VMware View Thin Client
#  Created By: Chris Towles
#  When: 04/04/2011
#  Version: 1.0
#  Change List
#
###########################

#Set-ExecutionPolicy -scope Currentuser -executionPolicy Unrestricted -WarningAction SilentlyContinue

$ViewServer = "view.nku.edu"

function VMwareView-ClearLastUsername {

 $key = "hkcu:\\Software\VMware, Inc.\VMware VDM\Client"
 
 #Clear the last user to login to View
 $name = "MRUsername" 
 $RegKey = Get-ItemProperty $key $name -ErrorAction SilentlyContinue
 if($RegKey -ne $null){
  set-itemproperty -path $key -name $name -value $null 
 }
 
 #Delete the key so that it returns to center
 $name = "DialogPos" 
 $RegKey = Get-ItemProperty $key $name -ErrorAction SilentlyContinue
 if($RegKey -ne $null){
  set-itemproperty -path $key -name $name -value $null 
 }
 
 #Minize the ToolBar on the remote
 $name = "InitialPinState" 
 $RegKey = Get-ItemProperty $key $name -ErrorAction SilentlyContinue
 if($RegKey -ne $null){
  set-itemproperty -path $key -name $name -value "TRUE"
 }
 else{
  Set-ItemProperty -Path $key -Name $name -Value "TRUE" -ErrorAction SilentlyContinue
 }
 
 
}
function VMwareView-StartProcessToFixWindowSize {

 $FixWindowPSFile = "c:\Program Files\VMware\VMware View\PowerShellScripts\ThinClient\VmwareViewFixWindowSize.ps1"
 if( Test-Path $FixWindowPSFile ){
  Start-Job -FilePath $FixWindowPSFile -Name VMwareViewFixWindowSizeLoop
 }
 else {
  Write-Output "The Powershell file $FixWindowPSFile wasn't found. Its needed to fix the resize issues."
 }
}

Get-Job | Stop-Job | Remove-Job
#| Stop-Job | Remove-Job
#$var = Stop-Job $JobList         # stop any extra jobs still running
#$var = Remove-Job $JobList       # Remove the jobs from the list

VMwareView-StartProcessToFixWindowSize 

$FileToRun = "C:\Program Files\VMware\VMware View\Client\bin\wswc.exe" 
$Arguments = @()
$Arguments += "-serverURL $ViewServer"
$Arguments += "-desktopProtocol PCoIP"
$Arguments += "-loginAsCurrentUser no"
$Arguments += "-desktopLayout fullscreeen"
#$Arguments += "-desktopName `"SL100`""

while($true)
{
 VMwareView-ClearLastUsername
 Start-Process $FileToRun -ArgumentList $Arguments -Wait
}


###########################
#
#  Purpose: Background process to make sure windows has a process maximized or any other setting.
#  Created By: Chris Towles
#  When: 11/12/2010
#  Version: 1.0
#  Change List
#
###########################

function VMwareView-FixWindowSize
{
 $procList = $null
 $RemoteList = $null    
 
 $procList = Get-Process "wswc" -ErrorAction SilentlyContinue
 
 if($procList -ne $null)
 {
  Foreach($proc in $procList){
   $RemoteList = Get-Process "vmware-remotemks" -ErrorAction SilentlyContinue
   if($RemoteList -ne $null){  
    $app::ShowWindow($proc.MainWindowHandle, 3)
   }
   else {
    $app::ShowWindow($proc.MainWindowHandle, 9)
   }
   #shows the sizes 9- restores window , 3 is maximize
   #http://msdn.microsoft.com/en-us/library/ms633548(VS.85).aspx   
  }
 } 
}


$signature = @"  
        [DllImport("user32.dll")]  
        public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
"@

$app = Add-Type -MemberDefinition $signature  -Name Win32Window -ReferencedAssemblies System.Windows.Forms -Using System.Windows.Forms -Namespace test -PassThru 

while($true) {
 VMwareView-FixWindowSize
 sleep 30 
}

Note: This is just the simplified method of what did with PowerShell scripts and I will link the to that post here when I finish it.
Download the script and save it to the Thin Client and then edit the file. Edit the $ViewServer parameter with your own Vmware View server.  I created a folder "C:\Program Files\VMware\VMware View\PowerShellScripts" in placed the script there.

This document is continued at VMware View 4.5 - Configuring the Local Account on the Thin Client (Part 3)

5 comments:

  1. Hi Chris, is there a way to set a background image while in the login vmware screen?

    thank you...
    bless your post.. :D

    ReplyDelete
  2. Busy this week with Vmware issues, will try and post the background image fix some time next week before winter break.

    ReplyDelete
  3. Chris -

    Did you ever post a way to put up a custom background image when using the View Client as a replacement shell in Windows 7?

    Thanks!

    === Tim

    ReplyDelete
  4. What do I save the files as... .ps or .bat?

    ReplyDelete
  5. Those are PowerShell so the file extension will be ".ps1". I also just fixed the download link above as well.

    ReplyDelete

Please leave a comment; someone, anyone!