;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 1.4
;
;Date 03-07-2008
;
;Date Revised 03-10-2008
;
;Revision Reason Added error checking and return codes
; Added logging of FAILURES ONLY
; Updated and REMed Shutdown notification code (You may want to use it)
; Check for files from a previous run and delete
; Removed dependency on Temp files by using the WSHPipe UDF
;
;Remarks Tested on 2000/XP
;
;Returns 0 - ALL Targeted Offline Files were repointed successfully
; 1 - SOME Targeted Offline Files were repointed successfully
; Check the log for what failed at: $Temp\@UserID_OfflineFail.log
; 2 - NONE of the Targeted Offline Files were repointed successfully
; Check the log for what failed at: $Temp\@UserID_OfflineFail.log
; 3 - NOTHING TO DO (Targeted Server not found to be configured on the client)
; 4 - Offline Files are DISABLED
; 5 - NONE of the Targeted Offline Files were repointed successfully
; Log Creation FAILED
; 6 - SOME Targeted Offline Files were repointed successfully
; Log Creation FAILED
;
;
;Dependencies KiXtart v4.x
; WSHPipe KIXTART UDF
; Microsoft CSCCMD.EXE v1.1 - http://support.microsoft.com/kb/884739
; Tested with KiXtart v4.53
;
;License: Creative Commons Attribution 3.0 United States
; http://creativecommons.org/licenses/by/3.0/us/
;
;Source
Function MigOfflineFiles($OldSrv, $NewSrv)
Dim $Temp, $Index, $KeyName, $DrvSrvShr, $DrvSrv, $DrvShr, $NUL, $RetCode, $MigFail, $MigSuccess, $MigStat, $LogStat
$MigOfflineFiles = ""
$Temp = EXPANDENVIRONMENTVARS ("%TEMP%")
; Is Offline Files enabled?
$RetCode = WSHPipe("csccmd /IsEnabled",1)
If UCase($RetCode[0]) = "DISABLED"
; Return 4 to indicate Offline Files is not enabled
$MigOfflineFiles = 4
; Exit Function
Exit 4
EndIf
$MigStat = ""
$Index = 0
:OLoop
; enumerate the CSC Shares
$KeyName = ENUMKEY("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\NetCache\Shares\", $Index)
If @ERROR = 0
If $Index = 0
; CLS
EndIf
; parse the server and share
$DrvSrvShr = Split(UCase($KeyName),"/",-1)
$DrvSrv = $DrvSrvShr[2]
$DrvShr = $DrvSrvShr[3]
; Are we pointing at the old server?
If $DrvSrv = UCASE($OldSrv)
$RetCode = ""
$MigStat = 1
$MigFail = "FALSE"
$MigSuccess = "FALSE"
? "Pointing Offline Files to New Server..."
; Run CSCCMD and log failures
$RetCode = WSHPipe("csccmd /MOVESHARE:\\" + $DrvSrv + "\" + $DrvShr + " \\" + $NewSrv + "\" + $DrvShr,1)
If $RetCode[0] = "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)
Else
$MigFail = 1
IF Open( 3 , $Temp + "\" + @UserID + "_OfflineFail.log , 5 ) = 0
$x = WriteLine( 3 , \\" + $DrvSrv + "\" + $DrvShr + " \\" + $NewSrv + "\" + $DrvShr + " " + $RetCode[0])
$LogStat = 1
ELSE
$LogStat = "FAIL"
ENDIF
EndIf
EndIf
$Index = $Index + 1
goto OLoop
EndIf
; If there was NOTHING TO DO
If Not $Migstat = 1
; We did not have anything to migrate
; Return 3 to indicate NOTHING TO DO
$MigOfflineFiles = 3
; Exit Function
Exit 3
Endif
; $Msg = @CRLF + "Your PC MUST be rebooted to ensure that your Offline Files "
; $Msg = $Msg + @CRLF + "are configured properly." + @CRLF + @CRLF + "Click OK To Reboot"
SELECT
; If the migration had no failures
CASE $MigFail = "FALSE" AND $MigSuccess = 1
; CLS
; $NUL = MessageBox($Msg , "Logon Script", 4112);
; $NUL = Shutdown("", "System is being rebooted to enable new settings.", 5, 1, 1)
; Return 0 to indicate SUCCESS
$MigOfflineFiles = 0
; If the migration had success and failure and good logs
CASE $MigFail = 1 AND $MigSuccess = 1 AND $LogStat = 1
; CLS
; $NUL = MessageBox($Msg , "Logon Script", 4112);
; $NUL = Shutdown("", "System is being rebooted to enable new settings.", 5, 1, 1)
; Failure log is left at $Temp\@UserID_OfflineFail.log
; Return 1 to indicate SUCCESS and FAILURE
$MigOfflineFiles = 1
; If the migration completely failed but had good logs
CASE $MigFail = 1 AND $MigSuccess = "FALSE" AND $LogStat = 1
; We had one or more failures
; Failure log is left at $Temp\@UserID_OfflineFail.log
; Return 2 to indicate one or more FAILURES
$MigOfflineFiles = 2
; If the migration had success and failure and no logs
CASE $MigFail = 1 AND $MigSuccess = 1 AND $LogStat = "FAIL"
; CLS
; $NUL = MessageBox($Msg , "Logon Script", 4112);
; $NUL = Shutdown("", "System is being rebooted to enable new settings.", 5, 1, 1)
; FAILURE LOG WAS NOT CREATED
; Return 5 to indicate SUCCESS and FAILURE
$MigOfflineFiles = 5
; If the migration completely failed but had no logs
CASE $MigFail = 1 AND $MigSuccess = "FALSE" AND $LogStat = "FAIL"
; We had one or more failures
; FAILURE LOG WAS NOT CREATED
; Return 6 to indicate one or more FAILURES
$MigOfflineFiles = 6
ENDSELECT
EndFunction