MarkMelanson
(Fresh Scripter)
2008-03-08 02:23 PM
Migrate Offline Files to a New Server

Recently I have been working on migrating Windows servers from Win2K to Win2K3. During our adventure we have across the usual issues that you would expect during a migration. So far these have been quickly addressed and fixes documented. Unfortunately the difficulties of migrating Offline Files in a seamless manner has not been as easy to to overcome.

After much hair pulling and googling I found enough information to put together a solution that is working for us. Since I have had the benefit of the knowledge of so many others on the Internets I thought I'd post my findings for your perusal.

Before I begin let me start by saying if this does not work for you or it breaks something you are on your own. I know the code is ugly. KIXTART is not my forte. Suggestions are welcomed to improve it.

You may not know that Microsoft actually provides a tool for this purpose. It is in the Win2K3 Resource Kit and is called CSCCMD.EXE. If you have it, good for you! It's crap. But there is a new and improved version that is mentioned in a 2 year old article (KB884739). From a scripting standpoint it isn't much better but it will have to do. If you checked out the KB article you will also notice that you have to call them to get it. Apparently two years isn't long enough to test it sufficiently. If you search the Internet via Google you will find it (or call them). You will need it for this to work. If you are running Vista then you don't need to do any of this since you can now manipulate it with WMI. You can find a VBScript to do that at http://blogs.technet.com/filecab/pages/cscrenameitem-vbs.aspx

Links to the stuff you need can be found at http://www.markmelanson.com/migratingyouruserstoanewserver

The script expects CSCCMD.EXE to be in the path.

Below is the code. Good Luck!

 Code:

;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


Glenn BarnasAdministrator
(KiX Supporter)
2008-03-08 05:09 PM
Re: Migrate Offline Files to a New Server

Mark,

Welcome to KORG, and thanks for your post!

You might want to edit your post and place your script inside of [ code ] [ /code ] tags to preserve the formatting. (real tags are entered without spaces).

Glenn


MarkMelanson
(Fresh Scripter)
2008-03-08 06:29 PM
Re: Migrate Offline Files to a New Server

Thanks for the welcome (and the advice).

NTDOCAdministrator
(KiX Master)
2008-03-08 11:53 PM
Re: Migrate Offline Files to a New Server

Welcome Mark and thanks for sharing. Nice first post.

Witto
(MM club member)
2008-03-09 01:31 PM
Re: Migrate Offline Files to a New Server

Is that a UDF? Maybe move it to the UDF forum?

MarkMelanson
(Fresh Scripter)
2008-03-09 04:54 PM
Re: Migrate Offline Files to a New Server

I think it could use more error checking code. I will work on it.

MarkMelanson
(Fresh Scripter)
2008-03-09 06:35 PM
Re: Migrate Offline Files to a New Server

I have made some updates but I probably won't get to test it until tomorrow.

Below is what t expect:

 Code:
;Function		MigOfflineFiles()
;  
;Author			Mark Melanson
;  
;Contributors  
;  
;Action			Repoints the Offline Files cache to another server
;  
;Syntax			MigOfflineFiles("ServerOld", "ServerNew")  
;  
;Version		1.1 BETA
;  
;Date			03-07-2008
;  
;Date Revised		03-09-2008
;  
;Revision Reason  
;  
;Remarks		Tested on 2000/XP  
;  
;Returns		0 on Offline Files disabled
;			1 on migration success
;			2 on one or more migration failures, check the log for what failed at:
;								$Temp\@UserID_OfflineFail.log
;			
;Dependencies		KiXtart v4.x, Microsoft CSCCMD.EXE v1.1  
;			Written and tested with KiXtart v4.53  



Glenn BarnasAdministrator
(KiX Supporter)
2008-03-09 06:59 PM
Re: Migrate Offline Files to a New Server

Mark,

Couple of quick comments to enhance this a bit...

1. for posting, break your long lines to prevent left/right scrolling. This line is too big even for my 19" widescreen monitor! You can change this one:
 Code:
$RC = MessageBox(@CRLF + "Your PC MUST be rebooted to ensure that your Offline Files        " +
 @CRLF + "are configured properly." + @CRLF + @CRLF + "Click OK To Reboot", "Logon Script", 4112)

to
 Code:
$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"
$RC = MessageBox($Msg , "Logon Script", 4112)

You might be able to take advantage of Kixtart's forgiving nature and simply break the line after the "+" sign. I'm torn between convenience and good coding practice on that, though. \:\)

2. "RETURN" is used for Gosub. To exit a function, use "Exit", followed by the exit code. The exit code you return can be examined by the @ERROR macro. If your function succeeds, use "Exit 0", otherwise use "Exit 1" for generic errors, or a more appropriate code if possible.

3. You might want to revisit your return value choices. Since there are three possible return states, you might want to return 1 or 2 for the various success states (Migrate Successful or Disabled), and 0 to indicate error - check @ERROR status. Thus, you can do something like
 Code:
If MigOffLineFiles(old,new)
 'OK!'
Else
 @SERROR ?
EndIF

for simple migration tests.

4. Reference the source of the CSCCMD.EXE in the UDF header so someone that downloads the function can later recall where the dependent file is.

When it's done and tested, post it (code only) in the UDF forum. Put any commentary in a secondary post in the same topic, as the topmost posts are replicated to UDF mirror sites.

Looking forward to the finished UDF!

Glenn


MarkMelanson
(Fresh Scripter)
2008-03-09 09:54 PM
Re: Migrate Offline Files to a New Server

Before I move it to the UDF section please give it the once over. I couldn't resist working on it. I implemented your suggestions and code. It tests out OK.

I have updated the original post to save space.

Mark


MarkMelanson
(Fresh Scripter)
2008-03-09 10:13 PM
Re: Migrate Offline Files to a New Server

Wow! I just can't leave it alone. I'll stop now.

MarkMelanson
(Fresh Scripter)
2008-03-09 10:22 PM
Re: Migrate Offline Files to a New Server

Oops. I lied. I think I found a logic problem. Working on it now....

MarkMelanson
(Fresh Scripter)
2008-03-09 11:23 PM
Re: Migrate Offline Files to a New Server

Done. Tests OK.

I had to make sure that if there is ANY success that you are informed as the machine should then be rebooted.

Let me know what you think. I also cleaned up my variable & macro usage.


Glenn BarnasAdministrator
(KiX Supporter)
2008-03-09 11:23 PM
Re: Migrate Offline Files to a New Server

OK - Now I need two 19" widescreens! ;\)

Since you can't put it down, here's a few more ideas...

 Code:
	Shell "%Comspec% /c for /f %%A in ('csccmd /IsEnabled') DO @If /i '%%A'=='Enabled' (echo.>" + $Temp + "\Offline.flg)"

can probably be shortened to
 Code:
  Shell '%Comspec% /c csccmd /IsEnabled' | find.exe /i "Enabled"'
  If @ERROR ; text not found - not enabled - exit?

The last command from a Shell command will set the error macro. You can use this to check results. The Find command searches for "Enabled" in the output of csccmd, and returns 0 if found, 1 if not. No temp file to deal with.

You might also want to look at the WSHPipe UDF. I insert parts of that code into lots of my code to capture STDOUT instead of using temp files. Since all the output is returned to Kix, you can probably eliminate that "double-wide-screen" embedded batch file and use Kix to process the results and create the log, too.

Good idea making the UDF silent, too. Was thinking about that, earlier. Glad the telepathy worked!

BTW - no need to credit us unless we start co-writing the code. We will all throw ideas out pretty freely around here!

Glenn


MarkMelanson
(Fresh Scripter)
2008-03-09 11:40 PM
Re: Migrate Offline Files to a New Server

Doesn't SHELL return the exit code of the command executed? In this case CMD.EXE since FIND.EXE is a child of the former?

I'll test it.


MarkMelanson
(Fresh Scripter)
2008-03-09 11:51 PM
Re: Migrate Offline Files to a New Server

Silly question of course it works.....

MarkMelanson
(Fresh Scripter)
2008-03-10 01:13 PM
Re: Migrate Offline Files to a New Server

LOL. Now that I am at work I see your point about the line length. I didn't really notice on my 24" widescreen.

MarkMelanson
(Fresh Scripter)
2008-03-10 03:13 PM
Re: Migrate Offline Files to a New Server

Hi Glenn,

I think I have it completed. I have not tested the log failures.

Below is the updated code. Give it the once over (again) please.

 Code:
;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


NTDOCAdministrator
(KiX Master)
2008-03-10 10:29 PM
Re: Migrate Offline Files to a New Server

Hi Mark,

Just a few comments (I'll leave Glenn to help with the coding) \:D

KiXtart v4.x
Unless you've tested it with KiXtart 4.0, 4.02, 4.22, etc... then I'd enter the version you did test under dependencies.



;License: Creative Commons Attribution 3.0 United States
; http://creativecommons.org/licenses/by/3.0/us/
Though this is not a bad deal I don't think we can accept it as a posted UDF with this license
We've never actually used any type of license (probably should have) but have basically used the principal
that ALL publicly posted code on the site is free to use in any shape form or manner one wishes to.


:OLoop
The use of GOTO and LABELS is considered [old school, out of date] coding practice. Though quite valid to use, we would rather it be coded to prevent it's use especially for a posted UDF.


Though not required you may want to either code for it or make a point that the SERVER names should not contain a UNC path


If wanted the use of HKEY_CURRENT_USER can be shortened to: HKCU

As mentioned about making the UDF silent, I would remove some of the minor items still left in that were not silent such as
CLS
? "Pointing Offline Files to New Server..."
etc...

I'm not actually sure what's it's official name is but you may want to preload your arrays in case of an invalid read it would abend KiX

 Code:
$DrvSrvShr = Split(UCase($KeyName),"/",-1)
$DrvSrv = $DrvSrvShr[2]
$DrvShr = $DrvSrvShr[3]



You should also have a CASE1 in case none of your expected results are there in your Select statement.

Good luck and I'll let Glenn carry on from here

.


Glenn BarnasAdministrator
(KiX Supporter)
2008-03-10 10:48 PM
Re: Migrate Offline Files to a New Server

Mark,

Did anyone mention when you signed up that we're a tough crowd? ;\)

Glenn


NTDOCAdministrator
(KiX Master)
2008-03-10 11:10 PM
Re: Migrate Offline Files to a New Server

LOL - No harm meant but he did post this:
 Quote:
I know the code is ugly. KIXTART is not my forte. Suggestions are welcomed to improve it.

Just trying to help him to make it better and along the way learn some more about KiXtart


MarkMelanson
(Fresh Scripter)
2008-03-11 12:19 PM
Re: Migrate Offline Files to a New Server

.dabs eyes with tissue.

I'm over it now. ;-)


Glenn BarnasAdministrator
(KiX Supporter)
2008-03-11 02:07 PM
Re: Migrate Offline Files to a New Server

You're gonna fit right in around here! \:\)

GLenn


MarkMelanson
(Fresh Scripter)
2008-03-11 04:11 PM
Re: Migrate Offline Files to a New Server

 Originally Posted By: NTDOC
Hi Mark,

Just a few comments (I'll leave Glenn to help with the coding) \:D

KiXtart v4.x
Unless you've tested it with KiXtart 4.0, 4.02, 4.22, etc... then I'd enter the version you did test under dependencies.


Done

 Originally Posted By: NTDOC

;License: Creative Commons Attribution 3.0 United States
; http://creativecommons.org/licenses/by/3.0/us/
Though this is not a bad deal I don't think we can accept it as a posted UDF with this license
We've never actually used any type of license (probably should have) but have basically used the principal
that ALL publicly posted code on the site is free to use in any shape form or manner one wishes to.


This is a little more complex. As I'm sure you are aware this license leaves it open to use by anyone only attribution is required. Living in the Land of the Free and the Home of the Lawyers my concern is that some scumbag might take some of the code and patent/register/trademark (WHATEVER, I don't care for lawyers) it making it unusable without some onerous license.

I do not recall, although it was quite awhile ago, seeing anything about licensing of code posted when I joined. If it is there then it is all good as long as this board stays up as a refencence for prior art.

Yes, I am paranoid. I have enough experience with lawyers to expect the worst.

 Originally Posted By: NTDOC

:OLoop
The use of GOTO and LABELS is considered [old school, out of date] coding practice. Though quite valid to use, we would rather it be coded to prevent it's use especially for a posted UDF.


Done

 Originally Posted By: NTDOC

Though not required you may want to either code for it or make a point that the SERVER names should not contain a UNC path


This should never happen. The key is the format // + ServerName + / + ShareName. If it does happen the CSCCMD.EXE will throw an error that I capture.

 Originally Posted By: NTDOC

If wanted the use of HKEY_CURRENT_USER can be shortened to: HKCU


Done

 Originally Posted By: NTDOC

As mentioned about making the UDF silent, I would remove some of the minor items still left in that were not silent such as
CLS
? "Pointing Offline Files to New Server..."
etc...


Done

 Originally Posted By: NTDOC

I'm not actually sure what's it's official name is but you may want to preload your arrays in case of an invalid read it would abend KiX

 Code:
$DrvSrvShr = Split(UCase($KeyName),"/",-1)
$DrvSrv = $DrvSrvShr[2]
$DrvShr = $DrvSrvShr[3]



Done

 Originally Posted By: NTDOC

You should also have a CASE1 in case none of your expected results are there in your Select statement.


Done

 Originally Posted By: NTDOC

Good luck and I'll let Glenn carry on from here.


New code is re-posted to the first message (v2.0)

Thanks


NTDOCAdministrator
(KiX Master)
2008-03-11 09:28 PM
Re: Migrate Offline Files to a New Server

Wow - sounds great. I'll try to take a look at it later on today.

Not sure about the license issue. I'll take it up with the other moderators / admins and see what they think and get back to you on that.


MarkMelanson
(Fresh Scripter)
2008-03-12 12:02 PM
Re: Migrate Offline Files to a New Server

Thanks guys!

I'll be fine if you don't want to add it to the UDF library due to the licensing. I would suggest adding something to notice when you join the board/post code that by doing so your code is released as Public Domain. That way there is no question.


MarkMelanson
(Fresh Scripter)
2008-03-12 06:04 PM
Re: Migrate Offline Files to a New Server

Updated to v2.1

Fixed error checking in log creation


MarkMelanson
(Fresh Scripter)
2008-03-12 07:08 PM
Re: Migrate Offline Files to a New Server

Coming in v2.3 (after testing)

Changed some variable names
Restructured code to move If statement into SELECT CASE
Restructured return codes (not backward compatible)

 Code:
;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
;


JochenAdministrator
(KiX Supporter)
2008-03-12 11:40 PM
Re: Migrate Offline Files to a New Server

Oi Mark,

just a quick advice as I don't have time to read anything in deep these days: Just make sure you don't miss the next KiXgolf tournament and KiXtart will be sooner or later your 'forte'

As for the licensing thing: KiXtart is CareWare and all we (the posse) pulish here can be treated as FreeWare to be used with the CareWare, so I don't think a creative commons licensing would be suitable, sorry.

Oh, and welcome to the board!


MarkMelanson
(Fresh Scripter)
2008-03-13 06:58 PM
Re: Migrate Offline Files to a New Server

No problemo.

MarkMelanson
(Fresh Scripter)
2008-03-13 06:59 PM
Re: Migrate Offline Files to a New Server

Skipped to v2.4

Fixed condition where registry key was skipped


Arend_
(MM club member)
2008-03-14 10:02 AM
Re: Migrate Offline Files to a New Server

Just a few pointers:
 Code:
$KeyName = ENUMKEY("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\NetCache\Shares\", $Index)
You can use "HKCU" instead of the full "HKEY_CURRENT_USER" to shorten your code, also the trailing "\" isn't neccesary.

Not entirely sure about this one but
 Code:
    CASE $Migstat <> 1
I think makes
 Code:
    CASE 1
obsolete.

Also you can shorten your code further by eliminating spaces
 Code:
$RetCode = WSHPipe("csccmd /MOVESHARE:\\" + $CSCSrv + "\" + $CSCShr + " \\" + $NewSrv + "\" + $CSCShr,1)

would look like this
 Code:
$RetCode = WSHPipe("csccmd /MOVESHARE:\\"+$CSCSrv+"\"+$CSCShr+" \\"+$NewSrv+"\"+$CSCShr,1)


Glenn BarnasAdministrator
(KiX Supporter)
2008-03-14 08:24 PM
Re: Migrate Offline Files to a New Server

Personally, I think that the elimination of spaces makes it more difficult to read, and prevents you from quickly recogniznig where each component begins/ends. Of course, if you're 22 and (still) have 20/20 vision... ;\)

Glenn


NTDOCAdministrator
(KiX Master)
2008-03-14 08:56 PM
Re: Migrate Offline Files to a New Server

Yes the
 Code:
CASE $Migstat <> 1

would negate the CASE 1

Missed that


I'm also with Glenn on not removing all the spaces, and it should also have liberal comments for future reference unless it's personal code on your own machine, but most often its for a Company you work for and sooner or later someone else will need to work on your code. Without comments it can make it difficult for a new person to determine what all it does.


masken
(MM club member)
2008-03-21 10:44 PM
Re: Migrate Offline Files to a New Server

hmm... I remember that when I scripted this it was tricky. csccmd requires administrative privs and so on. If my memory serves me right, old share-references in hklm also needs to be deleted, and the csc re-initiated on the client side to really remove old refs. But this was all for dleting old offline servers, might be that this isn't valid for /MOVESHARE when the old server is still online... Well I'm too tired atm anyhow hehe...

sns
(Just in Town)
2009-01-30 08:44 PM
Re: Migrate Offline Files to a New Server

I am new to the forum (1st post) and a newbie to kixtart! This udf would fix a major issue I have at one of my cleints sites. The question I have is: how do I apply this udf in a script? I know that the "syntax" states to use MigOfflineFiles("ServerOld", "ServerNew") but when I replace the server old and server new with the names of the servers, I get this error:

ERROR : expected ')'!
Script: U:\offlinefiles.KIX
Line : 65

This is basically how it looks in the my offlinefiles.kix file:

MigOfflineFiles("myoldservername", "mynewservername")

----UDF below----
line 64 ; Is Offline Files enabled?
line 65 $RetCode = WSHPipe("csccmd /IsEnabled",1)
line 66 If UCase($RetCode[0]) = "DISABLED"

I went through and read the forum sticky on using udfs in script but I think maybe Im just to new to get this one going w/o any help. Any one have any idea what I am doing wrong?

*edit*
I needed to add the udf "wshpipe" into the script. Now it's returning values.

After implementing this udf into my kix logon script I found that the warning in the notification area was still complaining about being offline on the old server. it was also still throwing errors when trying to synchronize. After doing some digging I found that if this is run once and the computer restarted this will clear those warnings.

reg add "hklm\SOFTWARE\Microsoft\Windows\CurrentVersion\netcache" /v FormatDatabase /t reg_dword /d 00000001

I put this into my current login script after the original script is called "\\myserver\netlogon\kix32 \\myserver\netlogon\kixtart.kix" in my batch file.

Hope this helps \:D


kmkix
(Just in Town)
2009-11-19 06:36 AM
Re: Migrate Offline Files to a New Server

Hey guys -- need a little help. The script didn't seem to run properly but I was able to run CSCCMD manually to update the offline cache file locations/etc using the MOVESHARE command.

SERVER1 (old)
SERVER2 (new -- copy of data on SERVER1)
PC (offline cache of data from SERVER1 -- user has not resynced with SERVER1 since X days ago -- so PC has newer data than some of what may exist on SERVER1 and SERVER2)

During my tests -- after the MOVESHARES change the problem comes up that on a re-sync with SERVER2 where the OFFLINE FILES CACHE now points -- SERVER2 does not update with any changes from the PC's cache. And, subsequently -- if there is a new file on the PC that's not on SERVER2 -- it gets deleted from the offline cache as well during the sync.