FYI - I reread your post and then mine and I see some ambiguity to my original statement. That may have caused you to misinterpret the proper action.

In item C) - your code was spilling the return code - 0 in that case - directly onto the screen and I suggested prefixing the command with "$Rc = " to catch the return code. There should not be a zero in front of that. The proper syntax is:
 Code:
$Rc = Function(args)
The $Rc contains the Return Code (if any). You can examine it if you want to, or simply ignore it and possibly check the @ERROR macro for a non-zero value. The benefit of this is that the return codes don't litter the screen with "random" numbers.

$Rc is one of those variables that helps keep output clean, has a short "lifespan", and might be used whether required or not. When you use $Rc to capture the result of a function, it means you either don't care about the value - you just don't want to be a litterbug, or you just want to check the status, such as Pass/Fail. When a function returns DATA that you will use later, then directly define an appropriate variable to use the result.
 Code:
$Value = ReadValue('hklm\path', 'Value')
_________________________
Actually I am a Rocket Scientist! \:D