Load all AppV 4.6 packages into the AppV Cache

image_pdfimage_print

After the migration from SCCM 2007 to SCCM 2012 some users had an issue with accessing their AppV 4.6 packages. They received the following error:

Error message that AppV 46 cannot be found in ccmcache.

Error message that AppV 46 cannot be found in ccmcache.


What happens. During the client migration the ccmcache is cleared. So if an AppV 4.6 package has not been started before the migration, the content could not be found after starting the package after the migration.
That has been solved by creating a vbscript that is run before the SCCM 2007 client is migrated to SCCM 2012. In short: for each AppV 4.6 application the virtual package is loaded into the AppV Cache.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
' ================================================================================================
' Load all the AppV 4.6 Packages again
' Created by Willem-Jan Vroom
' (c) Canon Europe B.V.
' Version history:
'
' v0.0.1:
'   Initial version
'
' v0.0.2:
'   Add functionality:
'     - Unlocks the AppV 4.6 package if it is in use
'     - For each entry a log file is created. 
' ================================================================================================
 
' ------------------------------------------------------------------------------------------------
' Declare the most variables. 
' ------------------------------------------------------------------------------------------------
 
  Option Explicit
 
  Dim objShell               : set objShell         = WScript.CreateObject("WScript.Shell")
  Dim objNetWork             : set objNetWork       = Wscript.CreateObject("WScript.Network")
  Dim objLogFileFSO          : Set objLogFileFSO    = CreateObject("Scripting.FileSystemObject")
  Dim objFSO                 : Set objFSO           = CreateObject("Scripting.FileSystemObject")
  Dim objProcessEnv          : Set objProcessEnv    = objShell.Environment("PROCESS")
  Dim objWMIService          : Set objWMIService    = GetObject("winmgmts:\\.\root\cimv2")
  Dim objReg                 : Set objReg           = GetObject("winmgmts:\\.\root\default:StdRegProv")
  Dim objLogFile
  Dim colListOfServices
  Dim objService                
  Dim strCurrentDir          : strCurrentDir        = Left(Wscript.ScriptFullname, InstrRev(Wscript.ScriptFullname, "\"))
                               strCurrentDir        = Left(strCurrentDir,len(strCurrentDir)-1)
  Dim strCommand             : strCommand           = ""
  Dim strLogLocation         : strLogLocation       = "C:\WINDOWS\system32\Logfiles"
  Dim strcomputerName        : strcomputerName      = objProcessEnv("COMPUTERNAME")
  Dim strOutputFile          : strOutputFile        = strLogLocation & "\" & strcomputerName & "_ReinstallAllAppV46Packages_" & Replace(FormatDateTime(Now(), 2),"/","-") & ".log"
  Dim strOS                  : strOS                = ""
  Dim strKeyPath             : strKeyPath           = ""
  Dim strArchitecture        : strArchitecture      = "x86"
  Dim strWindir              : strWinDir            = objShell.ExpandEnvironmentStrings("%WinDir%")
 
  Dim valOSBuildNumber, valResult
  Dim objItem, colItems
  Dim arrSubKeys, objSubKey
  Dim strProcess
 
  Const ForWriting           = 2
  Const ForReading           = 1
  Const ForAppending         = 8
  Const OverWriteFiles       = True
  const HKEY_CURRENT_USER    = &H80000001
  const HKEY_LOCAL_MACHINE   = &H80000002
  Const HKEY_USERS           = &H80000003 
 
' ------------------------------------------------------------------------------------------------
' Detect the current OS architecture.  
' ------------------------------------------------------------------------------------------------
 
  if objFSO.FolderExists(strWindir & "\syswow64") Then
     strArchitecture = "x64"
  end if
 
' ------------------------------------------------------------------------------------------------
' Create the log location (if not exists)
' Open the logfile.  
' ------------------------------------------------------------------------------------------------
 
  CreateFolderStructure(strLogLocation)
  OpenLogFile()
  WriteToLog "- ACTION: script started."
 
' ------------------------------------------------------------------------------------------------
' Detect the current OS.  
' ------------------------------------------------------------------------------------------------
 
  Set colItems = objWMIService.ExecQuery("Select Caption,BuildNumber from Win32_OperatingSystem")
  For Each objItem in colItems
      strOS            = objItem.Caption
      valOSBuildNumber = objItem.BuildNumber
  Next
 
  WriteToLog("########## Details regarding operating system and logged on user        ##########")
  WriteToLog("Found Operating System:    " & strOS)
  WriteToLog("Found OS architecture:     " & strArchitecture)
  WriteToLog("Wscript engine:            " & wscript.FullName)
  WriteToLog("########## End details regarding operating system and logged on user    ##########")
  WriteToLog(" ")
 
' ------------------------------------------------------------------------------------------------
' Kill all the processes that belongs to the virtual applications
' The location of the packages are:
' on x86:
'  HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SoftGrid\4.5\Client\Applications
' 
' on x64:
'  HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\SoftGrid\4.5\Client\Applications
' ------------------------------------------------------------------------------------------------
 
  if strArchitecture = "x64" then
     strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\SoftGrid\4.5\Client\Applications"
      else
     strKeyPath = "SOFTWARE\Microsoft\SoftGrid\4.5\Client\Applications"
  end if
 
  WriteToLog ("---------------------------------------------------------------------------------")
  WriteToLog ("Closing all applications that belongs to an AppV 4.6 package.")
 
  objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
  if IsArray(arrSubKeys) Then
     For Each objSubKey in arrSubKeys
         KillProcessFromAllvirtualPackages(strKeyPath & "\" & objSubKey)
     Next
     else 
    WriteToLog("No AppV 4.6 packages have been found.")
  end if
  WriteToLog ("---------------------------------------------------------------------------------")
  WriteToLog (" ")
 
 
' ------------------------------------------------------------------------------------------------
' Load the App-V 4.6 packages. 
' The location of the packages are:
' on x86:
'  HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SoftGrid\4.5\Client\Packages
' 
' on x64:
'  HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\SoftGrid\4.5\Client\Packages
' ------------------------------------------------------------------------------------------------
 
  if strArchitecture = "x64" then
     strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\SoftGrid\4.5\Client\Packages"
      else
     strKeyPath = "SOFTWARE\Microsoft\SoftGrid\4.5\Client\Packages"
  end if
 
  objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
  if IsArray(arrSubKeys) Then
     For Each objSubKey in arrSubKeys
         LoadAppV46Package(strKeyPath & "\" & objSubKey)
     Next
     else 
    WriteToLog("No AppV 4.6 packages have been found. Thus quitting.")
  end if
 
  CloseLogFile()
 
 
Sub OpenLogFile() 
 
' ------------------------------------------------------------------------------------------------
' Subroutine: OpenLogFile() 
' The name of the logfile is mentinoed in the variabele strOutputFile.
' ------------------------------------------------------------------------------------------------
 
  If objLogFileFSO.FileExists(strOutputFile) Then
     Set objLogFile = objLogFileFSO.OpenTextFile(strOutputFile, ForWriting)
         Else
     Set objLogFile = objLogFileFSO.CreateTextFile(strOutputFile)
  End If
 
End Sub
 
 
Function WriteToLog(sLogMessage)
 
' ------------------------------------------------------------------------------------------------
' Function: WriteToLog(sLogMessage)
' Writes an entry 'sLogMessage' in the logfile.
' ------------------------------------------------------------------------------------------------
 
  if instr(sLogMessage, "- ACTION: ") = 0 then sLogMessage = "          " & sLogMessage
  objLogFile.WriteLine("Time: " & now & "  " & sLogMessage)
 
End Function
 
Sub CloseLogFile()
 
' ------------------------------------------------------------------------------------------------
' Subroutine: CloseLogFile()
' Close the log file.
' ------------------------------------------------------------------------------------------------
  WriteToLog("########## End repairing all the AppV Packages.                         ##########")
  WriteToLog("- ACTION: script ended.")           
  objLogFile.Close
  Set objLogfileFSO = Nothing
 
End Sub
 
 
Sub CreateFolderStructure(strFolderNameToBeCreated)
 
' ------------------------------------------------------------------------------------------------
' Subroutine: CreateFolderStructure(strFolderNameToBeCreated)
' Creates the map as mentioned in strFolderNameToBeCreated.
' ------------------------------------------------------------------------------------------------
 
  Dim arrFoldersTMP : arrFoldersTMP = split (strFolderNameToBeCreated,"\")
  Dim strFolder     : strFolder     = ""
  Dim objFolderTMP
 
  For Each objFolderTMP in arrFoldersTMP
      strFolder = strFolder & objFolderTMP
      If NOT objFSO.FolderExists(strFolder) Then
             objFSO.CreateFolder(strFolder)
      end If
      strFolder = strFolder & "\"
  Next
 
End Sub
 
Sub KillProcessFromAllvirtualPackages(key)
 
' ------------------------------------------------------------------------------------------------
' Subroutine: LoadAppV46Package(key)
' ------------------------------------------------------------------------------------------------
 
  Dim strProcessNameToKill : objReg.GetStringValue HKEY_LOCAL_MACHINE, key, "AppPath", strProcessNameToKill
 
  if not IsNull(strProcessNameToKill) Then
 
     Dim numFirstChar : numFirstChar = len(left(strProcessNameToKill, InstrRev(strProcessNameToKill, "\")))
     Dim numLastChar  : numLastChar  = len(strProcessNameToKill)
 
     call fnKillProcess(mid(strProcessNameToKill,numFirstChar+1,numLastChar))
  end if
 
End Sub
 
 
 
Sub LoadAppV46Package(key)
 
' ------------------------------------------------------------------------------------------------
' Subroutine: LoadAppV46Package(key)
' ------------------------------------------------------------------------------------------------
 
  Dim strSoftGridPackageName  : objReg.GetStringValue HKEY_LOCAL_MACHINE, key, "Name",        strSoftGridPackageName
  Dim strSoftGridSFTName      : objReg.GetStringValue HKEY_LOCAL_MACHINE, key, "OverrideURL", strSoftGridSFTName
  Dim strCommand
 
 
  WriteToLog ("---------------------------------------------------------------------------------")
  WriteToLog ("Processing SCCM AppV Package: " & strSoftGridPackageName & ".")
 
 
 
  strCommand = "sftmime unlock package:" & strSoftGridPackageName & " /LOG c:\windows\system32\logfiles\Unlock_AppV46Package_" & strSoftGridPackageName & ".log"
  WriteToLog ("Running command: " & ucase(strCommand))
 
  On Error Resume Next
  objShell.Run strCommand,6,True
  If Err.Number <> 0 Then
     WriteToLog("The following error occurred: " & Err.Description)
  end if
  On Error Goto 0
 
  On Error Resume Next
  strCommand = "sftmime unload package:" & strSoftGridPackageName & " /LOG c:\windows\system32\logfiles\Unload_AppV46Package_" & strSoftGridPackageName & ".log"
  WriteToLog ("Running command: " & ucase(strCommand))
  objShell.Run strCommand,6,True
  If Err.Number <> 0 Then
     WriteToLog("The following error occurred: " & Err.Description)
  end if
  On Error Goto 0
 
  On Error Resume Next
  strCommand = "sftmime load package:" & strSoftGridPackageName & " /sftpath "
  strCommand = strCommand & chr(34) & strSoftGridSFTName & chr(34) & " /LOG c:\windows\system32\logfiles\Load_AppV46Package_" & strSoftGridPackageName & ".log"
  WriteToLog ("Running command: " & ucase(strCommand))
  objShell.Run strCommand,6,True
  If Err.Number <> 0 Then
     WriteToLog("The following error occurred: " & Err.Description)
  end if
  On Error Goto 0
 
 
  On Error Goto 0
 
  WriteToLog ("End processing SCCM AppV Package: " & strSoftGridPackageName & ".")
  WriteToLog ("---------------------------------------------------------------------------------")
  WriteToLog (" ")
 
 
End Sub
 
Function fnKillProcess(strProcessName)
 
' ------------------------------------------------------------------------------------------------
' Function: fnKillProcess(strProcessName)
' Terminates the given processname.
' ------------------------------------------------------------------------------------------------
 
  Dim colProcess
  Dim objProcess
 
  Set colProcess = objWMIService.ExecQuery ("Select * From Win32_Process")
  For Each objProcess In colProcess
    If Instr(LCase(objProcess.Name),LCase(strProcessName)) > 0 Then
       objShell.Run "TASKKILL /F /T /IM " & objProcess.Name, 0, False
       objProcess.Terminate()
       WriteToLog("Terminating application: " & objProcess.Name)
    End If
  Next
 
End Function
 
Sub CheckProcess(strProcess)
' ------------------------------------------------------------------------------------------------
' Subroutine: CheckProcess(strProces)
' checks if a process is running. The subroutine is left when the process is not running
' anymore.
' ------------------------------------------------------------------------------------------------
 
  Dim blnProcessFound    : blnProcessFound = True
  Dim intLoopNotFound    : intLoopNotFound = 0
  Dim MINLoopCount       : MINLoopCount    = 3
  Dim objSWbemServices
  Dim colSWbemObjectSet
  Dim objSWbemObject
  Dim strCmdLine
 
  strProcess = ucase(strProcess)
 
  Do While (blnProcessFound And intLoopNotFound < 3)
    blnProcessFound = False
    WScript.Sleep 3000
    Set objSWbemServices = GetObject("winmgmts:\\.\root\cimv2")
    Set colSWbemObjectSet = objSWbemServices.InstancesOf("Win32_Process")
    For Each objSWbemObject In colSWbemObjectSet
        If (ucase(objSWbemObject.Name) = strProcess) And  (strCmdLine = "" Or strCmdLine = objSWbemObject.CommandLine) then
            blnProcessFound = true
                    intLoopNotFound = 0
        End If
    Next
    If Not blnProcessFound Then intLoopNotFound = intLoopNotFound + 1
    Set colSWbemObjectSet = Nothing
    Set objSWbemServices  = Nothing
  Loop
 
End Sub

Now the user can start the application without issues:

 Successfull start.

Successfull start.

Permanent link to this article: https://www.vroom.cc/wordpress/load-all-appv-4-6-packages-into-the-appv-cache/