;Function MigOfflineFiles()
;
;Author Mark Melanson
;
;Contributors
;
;Action Repoints the Offline Files cache to another server
;
;Assumptions Old share and new share are the same name
;
;Syntax MigOfflineFiles("ServerOld", "ServerNew")
;
;Version 2.4
;
;Date 03-07-2008
;
;Date Revised 03-13-2008
;
;Revision Reason Added error checking and return codes
; Added logging of FAILURES ONLY
; Removed dependency on Temp files by using the WSHPipe UDF
; Fixed error checking in log creation
; Changed some variable names
; Restructured code to move If statement into SELECT CASE
; Restructured return codes (NOT backward compatible)
; Fixed condition where registry key was skipped
;
;Remarks Tested on 2000/XP
;
;Returns 0 - Offline Files are DISABLED
; 1 - NOTHING TO DO (Targeted Server not found to be configured on the client)
; 2 - ALL Targeted Offline Files were repointed successfully
; 3 - SOME Targeted Offline Files were repointed successfully
; Check the log for what failed at: $Temp\@UserID_OfflineFail.log
; 4 - NONE of the Targeted Offline Files were repointed successfully
; Check the log for what failed at: $Temp\@UserID_OfflineFail.log
; 5 - SOME Targeted Offline Files were repointed successfully
; Log Creation FAILED
; 6 - NONE of the Targeted Offline Files were repointed successfully
; Log Creation FAILED
; 7 - UNKNOWN ERROR
;
;Dependencies KiXtart v4.53
; WSHPipe KIXTART UDF
; Microsoft CSCCMD.EXE v1.1 - http://support.microsoft.com/kb/884739
;
;License: Creative Commons Attribution 3.0 United States
; http://creativecommons.org/licenses/by/3.0/us/
;
;Source
Function MigOfflineFiles($OldSrv, $NewSrv)
Dim $Temp, $Index, $CSCSrvShr, $CSCSrv, $CSCShr, $NUL, $RetCode
Dim $MigFail, $MigSuccess, $MigStat, $LogStat, $WinDir, $x, $Result
DIM $KeyName[2] ; Note : declaration of an array of 3 elements.
$MigOfflineFiles = ""
$Temp = EXPANDENVIRONMENTVARS ("%TEMP%")
; Is Offline Files enabled?
$RetCode = WSHPipe("csccmd /IsEnabled",1)
If UCase($RetCode[0]) = "DISABLED"
; Return 0 to indicate Offline Files is not enabled
$MigOfflineFiles = 0
; Exit Function
Exit 0
EndIf
$LogStat = 0
$MigStat = ""
$Index = 0
Do
; enumerate the CSC Shares
$KeyName = ENUMKEY("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\NetCache\Shares\", $Index)
If @ERROR = 0
; parse the server and share
$CSCSrvShr = Split(UCase($KeyName),"/",-1)
$CSCSrv = $CSCSrvShr[2]
$CSCShr = $CSCSrvShr[3]
; Are we pointing at the old server?
If $CSCSrv = UCASE($OldSrv)
$RetCode = ""
$MigStat = 1
$MigFail = "FALSE"
$MigSuccess = "FALSE"
; Run CSCCMD and log failures
$RetCode = WSHPipe("csccmd /MOVESHARE:\\" + $CSCSrv + "\" + $CSCShr + " \\" + $NewSrv + "\" + $CSCShr,1)
$Result = Ucase($RetCode[0])
If UCase($Result) = "THE COMMAND COMPLETED SUCCESSFULLY."
$MigSuccess = 1
; CSCCMD does not cleanup the registry entries (I don't like loose ends)
; Switched to DELTREE as DELKEY did not always work even with no subkeys
$NUL = DELTREE("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\NetCache\Shares\" + $KeyName)
; Since we deleted the registry key we have to decrement the counter
; to avoid multiple runs to get all the data
$Index = $Index - 1
Else
$MigFail = 1
IF Open( 3, $Temp + "\" + @UserID + "_OfflineFail.log", 5 ) = 0
$x = WriteLine( 3 ,@Date + " " + @Time + " " + "\\" + $CSCSrv + "\" + $CSCShr + " \\" + $NewSrv + "\" + $CSCShr + " " + $Result + @CRLF)
If $x <> 0
$LogStat = $LogStat + 1
ENDIF
$NUL = Close(3)
ENDIF
EndIf
EndIf
$Index = $Index + 1
EndIf
Until $KeyName = ""
; Check our return codes
SELECT
; If there was NOTHING TO DO
CASE $Migstat <> 1
; Return 1 to indicate NOTHING TO DO
$MigOfflineFiles = 1
; If the migration had no failures and good logs
CASE $MigFail = "FALSE" AND $MigSuccess = 1
; Return 2 to indicate SUCCESS
; You should reboot the computer for the changes to take effect
$MigOfflineFiles = 2
; If the migration had success and failure and good logs
CASE $MigFail = 1 AND $MigSuccess = 1 AND $LogStat = 0
; Failure log is left at $Temp\@UserID_OfflineFail.log
; Return 3 to indicate SUCCESS and FAILURE
; You should reboot the computer for the changes to take effect
$MigOfflineFiles = 3
; If the migration completely failed and had good logs
CASE $MigFail = 1 AND $MigSuccess = "FALSE" AND $LogStat = 0
; We had one or more failures
; Failure log is left at $Temp\@UserID_OfflineFail.log
; Return 4 to indicate one or more FAILURES
$MigOfflineFiles = 4
; If the migration had success and failure and questionable logs
CASE $MigFail = 1 AND $MigSuccess = 1 AND $LogStat <> 0
; We had one or more failures
; FAILURE LOG WAS NOT CREATED OR IS INCOMPLETE
; Return 5 to indicate SUCCESS and FAILURE
; You should reboot the computer for the changes to take effect
$MigOfflineFiles = 5
; If the migration completely failed and questionable logs
CASE $MigFail = 1 AND $MigSuccess = "FALSE" AND $LogStat <> 0
; We had one or more failures
; FAILURE LOG WAS NOT CREATED OR IS INCOMPLETE
; Return 6 to indicate one or more FAILURES
$MigOfflineFiles = 6
CASE 1
; You should not be here
; UNKNOWN ERROR
$MigOfflineFiles = 7
ENDSELECT
EndFunction