Code:
If @ERROR $=LogOff(1) EndIf



The "If @ERROR" check to see if there was *any* error when the attempt was made to map the drive. It doesn't need to check if the drive mapping is in place.

If there was any error then the user is logged off.

As I mentioned, it would be better to check for the actual error that occurs when you try to map to a drive which has a limit set, but I don't know what that error number might be.

You can find the number yourself. Try to map to a drive which is already at its limit and you should get a specific error number that you can then use in the conditional to avoid false positives.

Code:
USE H: /delete /persistent
USE H: @HOMESHR
If @ERROR
$=MessageBox("Cannot map home share, reason: ["+@ERROR+"] "+@SERROR, "Logon error",0+16+4096,30)
$=LogOff(1)
EndIf



The code above displays the reason for logging off in a pop-up message box. Once you know the value of @ERROR you could change the conditional to "If @ERROR=x" where "x" is the value displayed between the "[]" characters in the message.

I've also changed the mapping so that it uses @HOMESHR rather than a hard-coded path. @HOMESHR is the value from user manager or AD, so it's much more portable and gets around your problem of having the home shares in many different places.