I found the problem:

KiXtart 2001 Beta 2 does not support the USE x: /DELETE function!!

This is weird?!?!?

Ok, let me explain:

Here is the code I used:
BryceNetUse.K2K

code:

break on

$tab=chr(9)
$cr=chr(13)+chr(10)

Function MapDrive($a,$b)
$MapDrive = ""
use $a /d
$nul = execute('use $a "$b" exit(@@error)')
if @error = 0
$nul = execute('? "$tab$a mapped to $b"')
$mapdrive=0
exit(0)
ELSE
$nul = execute('? "$tab There was Error#@error mapping $drive to $b$cr$tab@Serror"')
$mapdrive=@error
exit(@error)
endif
endfunction

$Drive = readprofilestring("@curdir\"+"test.ini","test","drive")
$unc = readprofilestring("@curdir\"+"test.ini","test","UNC")

$drive ?
$unc ?


$nul = mapdrive($drive, $unc)
? @serror


It is essentially the same as yours with a few minor changes.

Now, if you run this with the /DEBUG switch on the command line, it will show these lines in the blue line: (this is KiXtart 2001 Beta 2)

debug:
break on
$tab=chr(9)
$cr=chr(13)+chr(10)
Function MapDrive($a,$b)
$Drive = readprofilestring("@curdir\"+"test.ini","test","drive")
$unc = readprofilestring("@curdir\"+"test.ini","test","UNC")
$drive ?
?
$unc ?
?
$nul = mapdrive($drive, $unc)

Now the function runs:
$MapDrive = ""
use $a /d
use k: "\\server\share" exit(@error)
exit(@error)

Then it quits to DOS with
Script error : error in USE statement !
if @error = 0

This implies that the line before "if @error = 0" is at fault, and this is normally the case, but... If you comment out the USE $a /d line and try again, it works OK (run NET USE k: /d before hand otherwise you'll get an error 85)

This shows two problems:
1. USE x: /DELETE is broken in KiXtart 2001 Beta 2.

2. The global DEBUG mode ignores EXECUTE().

More testing:
Put a DEBUG ON above USE $a /DELETE and a DEBUG OFF after it and you can see that it simply does not work.

Put the DEBUG ON/OFF "around" the EXECUTE('USE $a "$b" EXIT(@@error)') and it works fine.

cj