'==========================================================================
' Make changes only in the 2 marked sections below
' DO NOT CHANGE THIS SECTION
'
' NAME: Install Template n.n.nn.vbs
' TEMPLATE AUTHOR: Chuck Hoffman
' DATE: 7/28/2011
'
' REVISION HISTORY
' 1.0.6		8-12-2011	CH
'	Added option not to wait for command line program to finish.
' 1.0.7		8-12-2011	CH
'	Minor revision
' 1.0.8		8/31/2011	CH
'	Changed ProcessResults to ProcessError for code clarity
'	Removed call to CheckForScriptError from LogMessage; could cause looping
'	Added Configuration as run type
' 1.0.9		10/13/2011	CH
'	If command line executable is missing ".exe", add it when checking if file exists
' 1.0.10	11/11/2011	CH
'	Corrected Mid function call in ExecutableFound.
' 1.0.11	11/21/2011	CH
'	Corrected folder creation for DAPP\Logs
' 1.0.12	8/14/2012	CH
'	Added option for using the WSH Exec method to launch programs
' 1.0.13	10/23/2012	CH
'	Added RegisterUEVTemplate sub
' 1.0.14	10/25/2012	CH
'	Added CopyUEVTemplate sub
' 1.0.15	11/5/2012	CH
'	Changed %PROGRAMFILES% to %programw6432%, because %PROGRAMFILES% not deemed reliable.
' 1.0.16	12/13/2012	CH
'	If error, but ignoring the error, set ResultCode to 0 after saving it in the list of result codes
'	Modified the CloseOut sub to properly report success for special exit codes
' 1.0.17	1/25/2013	CH
'	Added CheckExitCode to consolidate code.
'	Moved CopyUEVTemplate before registration in RegisterUEVTemplate.
'	Added PrepTerminalServer and FinalizeTerminalServer subroutines.
'	Added CheckErrAndLogResults subroutine for custom processing.
' 1.0.18	1/29/2013	CH
'	Changed IsTerminalServer; streamlined other code.
' 1.0.19	2/11/2013	CH
'	Added the missed declaration for variables.
'	Updated the ResultCode value in "GetOSFamily" Function.
'	Corrected IsTerminalServer function by validating WMIClassExists or not.
' 1.0.20	2/14/2013	CH
' 	Added the functions "CreateLogFiles" & "GetProcessorArchitecture" to create DAPP\logs folder in both x86 & x64 systems.
'	Made changes to improve error handling.
' 1.0.21   	2/27/2013	VK, CH
' 	Added command line examples using the variable "LogPath" for log file location for either x86 & x64 systems.
' 1.0.22	5/3/2013	CH
'	Fixed syntax error
'	Log if terminal server found
'	Modified FinalizeTerminalServer not to call CheckForScriptError, to prevent recursion.
' 1.0.23	2/26/2014 VKT
'	Changed DAPP log files folder from %WINDIR%\System32(Syswow64)\DAPP\logs to  %WINDIR%\DLX\DAPP\logs
'	Windows Server 2012 environment has been added to "GetOsFamily" subroutine
' 1.0.24	10/23/2014 VKT
'	Windows 8.1 environment has been added to "GetOsFamily" subroutine.
' 1.0.25	02/13/2015 GUR,VIG
'	Windows 2012 environment has been added to "IsTerminalServer" subroutine.
'	Modified 'LogMessage "Registering EUV Template" to LogMessage "Registering UEV Template"' in RegisterUEVTemplate subroutine.

Option Explicit
On Error Resume Next
Dim Product, RunType, bErrorFound, ResultCode, SaveResultCodes, IgnoreError, WaitForFinish, ScriptPath, LogPath, LogFile, strOS, strProcArch
Dim bTerminalServer, bTerminalServerInstallStateEnabled

' -------- CHANGE THIS SECTION (1) --------------------

' AUTHOR: Vigneshwaran
' DATE  : 29/10/2015

Product = "Microsoft User Experience Virtualization 2.1 SP1"	' Product name and version
RunType = "Uninstall"		' Install/Uninstall/Configuration

InitializeRun			' Do not change this line

' RunCommandLine "<Command Line>"
' RunCommandLine "msiexec /i ""<MSI Name>"" /qn /L*V """ & LogPath & "<Log File Name> "" "
' Example: RunCommandLine "msiexec /i test.msi /qn /L*V """ & LogPath & "test_Inst.log"""

Uninst


' If strProcArch = "x86" Then RunCommandLine "<Command Line for 32-bit>"
' If strProcArch = "x64" Then RunCommandLine "<Command Line for 64-bit>"

' RegisterUEVTemplate "<Absolute Path>"

' -------- END OF CHANGES (1) --------------------------

CloseOut


Sub InitializeRun
	Dim TemplateVersion
	Dim oFSO, oShell

	TemplateVersion = "1.0.25"

	strProcArch = GetProcessorArchitecture()
	
	Set oFSO = CreateObject("Scripting.FileSystemObject")
	LogPath = "C:\windows\DLX"
	if Not oFSO.FolderExists (LogPath) Then oFSO.CreateFolder LogPath
	LogPath = LogPath & "\DAPP"
	if Not oFSO.FolderExists (LogPath) Then oFSO.CreateFolder LogPath
	LogPath = LogPath & "\Logs\"
	if Not oFSO.FolderExists (LogPath) Then oFSO.CreateFolder LogPath
	LogFile = LogPath & Product & " Overview.log"
	
	LogMessage "===================================================="
	LogMessage "Template Version: " & TemplateVersion
	LogMessage "Run Type: " & RunType
	Set oShell = WScript.CreateObject("WScript.Shell") 
	ScriptPath = Left(WScript.ScriptFullName, InstrRev(WScript.ScriptFullName, "\"))
	CheckForScriptError "Looking up script location"
	oShell.CurrentDirectory = ScriptPath
	CheckForScriptError "Setting current directory"
	LogMessage "Script path: " & ScriptPath
	LogMessage "Processor family: " & strProcArch

	bErrorFound = False
	ResultCode = 0
	SaveResultCodes = ""
	IgnoreError = False
	WaitForFinish = True
	
	Set oShell = Nothing

	strOS = GetOSFamily() 
	PrepTerminalServer strOS
End Sub


Sub RunCommandLine (CommandLine)
	Dim bStepSuccess
	Dim oShell
	
	LogMessage "Looking for executable from command line: " & CommandLine
	If ExecutableFound (CommandLine) = False Then 
		bErrorFound = True
		ResultCode = 9000
		ProcessError ResultCode
	End If
	
	LogMessage "Launching command line (Wait for finish = " & WaitForFinish & ")"
	LogMessage "Command Line: " & CommandLine
	Set oShell = CreateObject("Wscript.Shell")
	ResultCode = oShell.Run (CommandLine,,WaitForFinish)

	bStepSuccess = False

	CheckExitCode ResultCode, bStepSuccess
	CheckStepResult bStepSuccess
	
	Set oShell = Nothing
	IgnoreError = False
	WaitForFinish = True
End Sub


Sub ExecCommandLine (CommandLine)					' 8/14/2012
	Dim bStepSuccess
	Dim oShell, oExec
	
	LogMessage "Looking for executable from command line: " & CommandLine
	If ExecutableFound (CommandLine) = False Then 
		bErrorFound = True
		ResultCode = 9010
		ProcessError ResultCode
	End If
	
	LogMessage "Launching command line (Wait for finish = " & WaitForFinish & ")"
	LogMessage "Command Line: " & CommandLine
	Set oShell = CreateObject("Wscript.Shell")
	Set oExec = oShell.Exec (CommandLine)
	
	bStepSuccess = False
	
	If WaitForFinish then
		Do While oExec.Status = 0
		     WScript.Sleep 1000
		Loop
	End If

	CheckExitCode ResultCode, bStepSuccess
	CheckStepResult bStepSuccess
	
	Set oShell = Nothing
	Set oExec = Nothing
	IgnoreError = False
	WaitForFinish = True
End Sub


Sub CheckExitCode (ResultCode, bStepSuccess)
	if WaitForFinish then
		Select Case ResultCode
			case 0
				bStepSuccess = True
				LogMessage "Step was successful"
			Case 1605
				If lcase(RunType) = "uninstall" Then
					bStepSuccess = True
					LogMessage "Step failed because product is not installed; ignoring error"
				Else
					bStepSuccess = False
					bErrorFound = True
				End If
			Case 1641
				bStepSuccess = True
				LogMessage "Step was successful, and triggered a reboot"
			Case 3010
				bStepSuccess = True
				LogMessage "Step was successful, and requires a reboot"
			Case Else
				bStepSuccess = False
				bErrorFound = True
		End Select
	Else		
		Select Case ResultCode
			case 0
				bStepSuccess = True
				LogMessage "Step was successfully started"
			Case Else
				bStepSuccess = False
				bErrorFound = True
		End Select
	End If
End Sub


Sub LogMessage (Message)
	Dim oFSO, oLogFile
	Const forAppending = 8

	Set oFSO = CreateObject ("Scripting.FileSystemObject")
	Set oLogFile = oFSO.OpenTextFile (LogFile,forAppending,True)
	oLogFile.WriteLine Date & " " & Time & " " & message
	oLogFile.Close
	
	Set oFSO = Nothing
	Set oLogFile = Nothing
End Sub


Function ExecutableFound (CommandLine)
	Dim strExecutable, strExecutableAndExe
	Dim iPos
	Dim bContainsPath
	Dim oFSO
	
	strExecutable = trim(CommandLine)
	
	If Left (strExecutable,1) = """" Then
		strExecutable = Mid(strExecutable,2,InStr(2,strExecutable,"""")-2)	' 11/11/11
	Else
		iPos = InStr(2,strExecutable," ")
		if iPos > 0 Then strExecutable = left(strExecutable,iPos-1)
	End If
	
	If InStr(strExecutable,"\") > 0 Then 
		bContainsPath = True
	Else
		bContainsPath = False
	End If
	
	If Instr(strExecutable,".") = 0 then strExecutableAndExe = strExecutable & ".exe"

	Set oFSO = CreateObject ("Scripting.FileSystemObject")
	ExecutableFound = False
	
	If oFSO.FileExists (strExecutable) Then
		ExecutableFound = True
	ElseIf bContainsPath = False Then
		If oFSO.FileExists ("C:\windows\system32\" & strExecutable) Then 
			ExecutableFound = True
		ElseIf oFSO.FileExists ("C:\windows\system32\" & strExecutableAndExe) Then 
			ExecutableFound = True
		End If
	End If
	
	If ExecutableFound = False Then LogMessage "ERROR: Executable not found: " & strExecutable
	
	Set oFSO = Nothing
End Function


sub CheckStepResult (bStepSuccess)
	' Used only for running command lines or custom processing, because it can ignore errors

	If bStepSuccess = False Then
		SaveResultCodes = SaveResultCodes & ResultCode & " "
		ProcessError ResultCode
	End If
end sub


Sub ProcessError (ResultCode)
	' Used only for running command lines or custom processing, because it can ignore errors

	LogMessage "ERROR: Step failed due to error " & ResultCode
	If IgnoreError Then
		ResultCode = 0 
		LogMessage "Error ignored by request; continuing with next steps"
	Else
		LogMessage "Processing cancelled due to error"
		CloseOut 
	End If
End Sub


Sub CheckErrAndLogResults (strMessage, ResultCodeIfFailed)
	' Used only for custom processing

	Dim bStepSuccess
	
	If Err then
		bStepSuccess = False
		bErrorFound = True
		LogMessage "ERROR: " & err.number & ": " & err.description
		Err.Clear
		LogMessage strMessage
		ResultCode = ResultCodeIfFailed 
	Else
		bStepSuccess = True
		LogMessage "Step was successful"
	End If
	
	CheckStepResult bStepSuccess
End Sub


Sub CheckForProcessingError (ResultCode)
	If ResultCode <> 0 Then CloseOut
End Sub


Sub CheckForScriptError (Step)
	' Check for script failure
	
	If Err.Number <> 0 Then
		LogMessage "ERROR: An error occurred during processing of step: " & Step & " - (" & CStr(Err.Number) & ") " & Err.Description
		bErrorFound = True
		ResultCode = 9990
		Err.Clear
		CloseOut
	End If
End Sub


Sub CloseOut ()
	FinalizeTerminalServer
	
	If bErrorFound and ResultCode <> 0 and IgnoreError = False Then
		LogMessage Product & ": " & RunType & " failed (error " & ResultCode & ")"
	ElseIf bErrorFound and IgnoreError Then
		LogMessage Product & ": " & RunType & " was successful (ignored errors: " & trim(SaveResultCodes) & ")"
	ElseIf ResultCode <> 0 Then
		Select Case ResultCode
			Case 1605
				LogMessage Product & ": " & RunType & " was successful"
				ResultCode = 0
			Case 1641
				LogMessage Product & ": " & RunType & " was successful"
				ResultCode = 0
			Case 3010
				LogMessage Product & ": " & RunType & " was successful"
			Case Else
				LogMessage Product & ": " & RunType & " failed (error " & ResultCode & ")"	
		End Select
	Else 
		LogMessage Product & ": " & RunType & " was successful"
	End If
	
	LogMessage "Final result code: " & ResultCode
	WScript.Quit ResultCode
End Sub


Sub RegisterUEVTemplate(strAbsolutePathAndName)	
	Dim objWMIProvider, objProcess, objInParam, objOutParams, objWMIObject
	Dim strWMIPath, strWMIClass, strTemplateName 
	Dim iPos
	Dim bStepSuccess

	If strOS = "WXP" Or strOS = "W2K" Then Exit Sub

	ResultCode = 9030						' Default error code for script failure in this sub
	bStepSuccess = True
	LogMessage "Registering UEV Template"
	strWMIPath = "\\.\root\microsoft\uev"
	strWMIClass = "SettingsLocationTemplate"
	strTemplateName = mid(strAbsolutePathAndName,InstrRev(strAbsolutePathAndName,"\") + 1)
	CopyUEVTemplate strTemplateName
	
	If WMIClassExists(strWMIPath, strWMIClass) Then
		Set objWMIProvider = GetObject("winmgmts:{impersonationLevel=impersonate}!" & strWMIPath)
		Set objProcess = objWMIProvider.Get(strWMIClass)		
		Set objInParam = objProcess.Methods_("Register").inParameters.SpawnInstance_()
		objInParam.Properties_.item("AbsolutePathToTemplate") = strAbsolutePathAndName
		ResultCode = 9032						' invalid or missing XML file
		Set objOutParams = objProcess.ExecMethod_("Register", objInParam)
		If Err Then
			Err.Clear
			LogMessage "NOTE: SettingsLocationTemplate not found in WMI; UEV template not registered"
			bErrorFound = True
			ResultCode = 9034
			bStepSuccess = False
		Else
			LogMessage "UEV template has been registered: " & strAbsolutePathAndName
			ResultCode = 0
		End If
	Else
		ResultCode = 0
		If strOS = "WXP" Or strOS = "W2K" Then
			LogMessage "NOTE: root\microsoft\uev not found in WMI; UEV template not registered"   ' OK if WinXP
		Else
			LogMessage "ERROR: root\microsoft\uev not found in WMI; UEV template not registered"
			bErrorFound = True
			ResultCode = 9036
			bStepSuccess = False
		End If
	End If
	
	Set objWMIProvider = Nothing
	Set objProcess = Nothing
	Set objInParam = Nothing
	Set objOutParams = Nothing
	
	CheckForScriptError "Registering UEV template"
	CheckForProcessingError ResultCode
End Sub


Function WMIClassExists(strWMIPath, WMIClassName) 
	Dim objWMIProvider, colClasses, objClass 

	WMIClassExists = False 
	Set objWMIProvider = GetObject("winmgmts:" & strWMIPath) 
	If Err = False Then
		Set colClasses = objWMIProvider.SubclassesOf() 
		For Each objClass In colClasses 
			if instr(objClass.Path_.Path,":" & WMIClassName) Then 
				WMIClassExists = True 
			End If 
		Next
	End If
	
	Set objWMIProvider = Nothing 
	Set colClasses = Nothing 
	Set objClass = Nothing
	CheckForScriptError "Checking if WMI class exists"
End Function


Sub CopyUEVTemplate(strTemplateName)
	Dim oFSO, oShell, strDir, strVar, bStepSuccess

	LogMessage "Copying UEV template"
	Set oFSO = CreateObject("Scripting.FileSystemObject")
	Set oShell = CreateObject("WScript.Shell")
	strVar = "%programw6432%"
	strDir = oShell.ExpandEnvironmentStrings(strVar)

	If strDir = strVar Then
		LogMessage "ERROR: Unable to copy " & strTemplateName & " to " & strDir & "; environment variable not defined"
		bErrorFound = True
		bStepSuccess = False
		ResultCode = 9050
	Else
		strDir = strDir & "\Microsoft User Experience Virtualization\Templates\"
		If oFSO.FolderExists(strDir) Then
			oFSO.CopyFile strTemplateName, strDir, True
			CheckForScriptError "Copying of UEV template"
			ResultCode = 0
			bStepSuccess = True
			LogMessage strTemplateName & ": Copied successfully to " & strDir
		Else
			LogMessage "ERROR: " & strTemplateName & ": Failed to copy to " & strDir & "; folder doesn't exist"
			bErrorFound = True
			bStepSuccess = False
			ResultCode = 9052
		End If
	End If

	Set oFSO = Nothing
	Set oShell = Nothing

	CheckForScriptError "Copying UEV template"
	CheckForProcessingError ResultCode
End Sub


Sub PrepTerminalServer (strOS)
	Dim oShell, Return, ReturnValue
	
	Set oShell = WScript.CreateObject("WScript.Shell")
	
	If IsTerminalServer(strOS) Then  
		LogMessage "Preparing terminal server for install"  
		bTerminalServer = True
		Set Return = oShell.Exec("c:\Windows\system32\Change.exe User /Query")
		Do While Return.StdOut.AtEndOfStream <> True
			ReturnValue = Return.StdOut.ReadLine
			LogMessage "Current Installation Mode: " &  ReturnValue
		Loop
	
		oShell.run "c:\Windows\system32\Change.exe User /Install", 6, True
		
		Set Return = oShell.Exec("c:\Windows\system32\Change.exe User /Query")
		Do While Return.StdOut.AtEndOfStream <> True
			LogMessage "Terminal server status: " & Return.StdOut.ReadLine
		Loop
			
		bTerminalServerInstallStateEnabled = True
	Else  
		bTerminalServer = False
		bTerminalServerInstallStateEnabled = False
	End If
	
	Set oShell = Nothing
	Set Return = Nothing
	
	CheckForScriptError "Preparing terminal server"
End Sub


Sub FinalizeTerminalServer()
	Dim oShell, Return, ReturnValue
	
	Set oShell = WScript.CreateObject("WScript.Shell")
	
	If bTerminalServerInstallStateEnabled = True Then
		LogMessage "Finalizing terminal server install"
		oShell.run "c:\Windows\system32\Change.exe User /Execute", 6, True
		Set Return = oShell.Exec("c:\Windows\system32\Change.exe User /Query")
		Do While Return.StdOut.AtEndOfStream <> True
			LogMessage "Terminal server status: " & Return.StdOut.ReadLine
		Loop
		
		''bTerminalServerInstallStateEnabled = False	' prevent recursion in case of error (CloseOut > FinalizeTerminalServer > CheckForScriptError > CloseOut)
		'CheckForScriptError "Finalizing terminal server" 
		If Err.Number <> 0 Then
			LogMessage "ERROR: An error occurred during processing of step: Finalizing terminal server - (" & CStr(Err.Number) & ") " & Err.Description
			bErrorFound = True
			ResultCode = 9992
			Err.Clear
		End If

	End If
	
	Set oShell = Nothing
	Set Return = Nothing
End Sub


Function GetOSFamily()   
	Dim strWMIPath, strCaption, strOSFamily 
	Dim objWMIProvider, colOSInfo, oOSProperty 

	LogMessage "Checking OS"
 	strWMIPath = "\\.\root\cimv2"

	If WMIClassExists(strWMIPath, "Win32_OperatingSystem") Then
		Set objWMIProvider = GetObject("winmgmts:{impersonationLevel=impersonate}!" & strWMIPath)
		Set colOSInfo = objWMIProvider.ExecQuery("Select * from Win32_OperatingSystem")		
 		For Each oOSProperty in colOSInfo     
			strCaption = oOSProperty.Caption   
			If InStr(1,strCaption, "2000", vbTextCompare) Then 
				strOSFamily = "W2K"
				ResultCode = 0
				ElseIf InStr(1,strCaption, "Windows XP", vbTextCompare) Then 
				strOSFamily = "WXP"
				ResultCode = 0
			ElseIf InStr(1,strCaption, "2003", vbTextCompare) Then 
				strOSFamily = "W2K3"
				ResultCode = 0
			ElseIf InStr(1,strCaption, "Windows 7", vbTextCompare) Then 
				strOSFamily = "WIN7"
				ResultCode = 0
			ElseIf InStr(1,strCaption, "Embedded", vbTextCompare) Then 
				strOSFamily = "WIN7E"
				ResultCode = 0
			ElseIf InStr(1,strCaption, "2008", vbTextCompare) Then 
				strOSFamily = "W2K8"  
				ResultCode = 0
			ElseIf InStr(1,strCaption, "2012", vbTextCompare) Then 
				strOSFamily = "W2K12"  
				ResultCode = 0
			ElseIf InStr(1,strCaption, "Windows 8.1", vbTextCompare) Then 
				strOSFamily = "WIN8.1"  
				ResultCode = 0
			Else
				LogMessage "ERROR: Unknown OS type"
				ResultCode = 9060
			End If
		Next

		LogMessage "OS family: " & strOSFamily
		GetOSFamily = strOSFamily   
		Set objWMIProvider = Nothing
		Set colOSInfo = Nothing
 		Set oOSProperty = Nothing
	End If
	
	CheckForScriptError "Getting OS family"
	CheckForProcessingError ResultCode
End Function


Function IsTerminalServer(strOS)   
	Dim strNameSpace
	Dim objWMIService, colItems, objItem
	
	LogMessage "Checking for terminal server"

	If strOS = "W2K8" or strOS = "W2K12" Then
		strNameSpace = "\root\cimv2\TerminalServices" 
	ElseIf strOS = "W2K3" Then
		strNameSpace = "\root\cimv2" 
	Else
		IsTerminalServer = False
		Exit Function
	End If
	
	If WMIClassExists(strNameSpace, "Win32_TerminalServiceSetting") Then
			Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\." & strNameSpace)     
			Set colItems = objWMIService.ExecQuery("Select * from Win32_TerminalServiceSetting")     
			For Each objItem In colItems       
				Select Case objItem.LicensingType         
					Case "1" 	' Remote Administration         
					  IsTerminalServer = False      
					Case "2" 	' Per Device         
					  IsTerminalServer = True      
					Case "4" 	' Per User         
					  IsTerminalServer = True      
					Case "5" 	' Not configured yet         
					  IsTerminalServer = True      
					Case Else        
					  IsTerminalServer = False      
				End Select  
			Next
	End If

	If IsTerminalServer then LogMessage "Terminal server found"

	Set objWMIService = Nothing    
	Set colItems = Nothing 
	Set objItem = Nothing
	
	CheckForScriptError "Checking for terminal server"
	CheckForProcessingError ResultCode
End Function

	
Function GetProcessorArchitecture()
	Dim strProcessorFamily, strWMIPath
	Dim objWMIProvider, colOSInfo, oProcessorProperty, strCaption
	
	ResultCode = 9070
 	strWMIPath = "\\.\root\cimv2"
	If WMIClassExists(strWMIPath, "Win32_Processor") Then
		Set objWMIProvider = GetObject("winmgmts:{impersonationLevel=impersonate}!" & strWMIPath)
		Set colOSInfo = objWMIProvider.ExecQuery("Select * from Win32_Processor")		
		For Each oProcessorProperty in colOSInfo     
			strCaption = oProcessorProperty.AddressWidth   
			If InStr(1,strCaption, "64", vbTextCompare) Then 
				strProcessorFamily = "x64"
				ResultCode = 0
			ElseIf InStr(1,strCaption, "32", vbTextCompare) Then 
				strProcessorFamily = "x86"			
				ResultCode = 0
			Else
				LogMessage "ERROR: Processor family not 32 or 64"
				ResultCode = 9072
			End If
		Next
		
		GetProcessorArchitecture = strProcessorFamily  
		ResultCode = 0
		Set objWMIProvider = Nothing  
		Set colOSInfo = Nothing
		Set oProcessorProperty = Nothing
	End If

' 	Can't do these checks; log file not created yet:
' 		CheckForScriptError "Checking processor family"		
' 		CheckForProcessingError ResultCode
End Function


' -------- CHANGE THIS SECTION (2) --------------------
' Add custom functions and subroutines here

Sub UninstallPackage

       ScriptPath = Left(WScript.ScriptFullName, InstrRev(WScript.ScriptFullName, "\"))
       
	If (strProcArch = "x64") Then
               RunCommandLine "msiexec /x  {8CE81DCD-C208-4922-A6F0-45725E1601BB} /qn /L*V """ & LogPath & "Microsoft User Experience Virtualization 2.1 SP1_Uninst.log"""

	Else

	If (strProcArch = "x86") Then
	RunCommandLine "msiexec /x  {D54945DB-8BB6-4261-A75A-43833EB0C073} /qn /L*V """ & LogPath & "Microsoft User Experience Virtualization 2.1 SP1_Uninst.log"""
       End If
End If
 
     CheckForScriptError "Installing the application"		

End Sub

Sub Uninst
	Dim strWMIPath, procCount, colProcs, objWMIProvider
	strWMIPath = "\\.\root\cimv2"
	Set objWMIProvider = GetObject("winmgmts:{impersonationLevel=impersonate}!" & strWMIPath)		
	Set colProcs = objWMIProvider.execquery("select * from win32_process where name='Microsoft.Uev.SyncController.exe'")	
	 procCount = colProcs.count
	 If procCount=0 Then 
	 UninstallPackage
	 
	 Else 
	 LogMessage "The application is in use. Please close the applications for uninstallation of the application"
	 ResultCode = 9994
	 End If 
	 Set strWMIPath = Nothing
	 Set procCount = Nothing
	 Set colProcs = Nothing
	 Set objWMIProvider = Nothing
	 CheckForScriptError "Checking for Uninstallation of the application"
End Sub