Hello All,

I've been testing the CreateShare UDF and have run into a few problems and questions that I hope you can help with.

1. I am trying to create a hidden share but I receive the following error when running the script, which appearantly only happens when I try to create a hidden share (a share name with a trailing "$").

DOS-PROMPT ERROR:
Code:
 
E:\kixtest>kix32.exe createlocalshare.kix
c:\tempdrive-1



SCRIPT:
Code:
 
call "@ScriptDir\UDF\MakePath.udf"
call "@ScriptDir\UDF\CreateShare.udf"

$server ="smith1"
$SharePath ="c:\tempdrive"
$shareName ="local$"
CreateShare($Server, $ShareName, $SharePath)



UDF:
Code:

;Example:
;
;$server ="server1"
;$folder ="c:\test\share"
;$share ="Test Share"
;CreateShare($server, $share, $folder)


Function CreateShare($Server, $ShareName, $SharePath, optional $Domain)

if not $domain $domain ="@domain" endif
if not $server $server ="@wksta" endif

$unc =join(split($folder,":"),"$")
$uncpath="\\$server\$unc"
if not exist("$uncpath")
$path=makepath("$uncpath")
endif

$FService = GetObject ("WinNT://$Domain/$Server/LanmanServer,FileService")
$FileShare = $FService.Create ("FileShare", $ShareName)
$FileShare.Path = $SharePath
$FileShare.MaxUserCount = -1 ; -1 allows unlimited connections. Any other positive number
$FileShare.SetInfo
$FService = 0
$FileShare = 0
EndFunction




DEPENDENT UDF:
Code:
 
;Shawn
;
;MakePath()
;Action:
;
;Create deep directory paths on local and remote systems
;
;Syntax:
;
;MakePath("Path")
;
;Parameters:
;
;Path (Required): A string representing the the directory path
;to create. Can be UNC or local path. Creates all directories along
;along the path if they do not already exist.
;
;Returns:
;
;@ERROR set to 0 (zero) on success -1 on invalid path or relevent error code on failure
;
;Remarks:
;
;Dependencies:
;
;KiXtart 4.0 (Final)
;
;Example(s):
;
;MakePath("c:\folder1\folder2")
;
;MakePath("\\server\share\folder1\folder2")


Function MakePath($Path)
dim $dirs,$maxdirs,$index,$count,$rpath
$dirs = split($Path, "\")
$maxdirs = ubound($dirs)
if instr($Path, "\\") = 1
if $maxdirs < 4
exit -1
else
$rpath = "\\"+$dirs[2]+"\"+$dirs[3]
$index = 4
endif
else
$rpath = $dirs[0]
$index = 1
endif
select
case $maxdirs < $index
exit -1
case $maxdirs = $index and $dirs[$maxdirs] = ""
exit -1
case 1
for $count = $index to $maxdirs
$rpath = $rpath + "\" + $dirs[$count]
if not exist($rpath)
md "$rpath"
if @ERROR
exit(@ERROR)
endif
endif
next
endselect
EndFunction



Would this have something to do with how the "$" is recognized within the Function? I've tried doubling up the $'s and using + '$', but those don't create the hidden share name. local$$ produces the error and local + '$' creates a share name of the exact text.

I will have more questions for this post, but I would like to work through this problem I'm having before adding further questions.

(BY the way LONKERO, I replaced the "REPLACE" UDF text with your recommended join(split($folder,":"),"$") code in the CreateShare UDF)

Thanks all for your help.