#148867 - 2005-09-30 01:45 AM
Creating Share on Remote Computer
|
StarwarsKid
Seasoned Scripter
   
Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
|
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.
|
|
Top
|
|
|
|
#148871 - 2005-09-30 07:56 PM
Re: Creating Share on Remote Computer
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
$unc =join(split($folder,":"),"$")
should be
$unc =join(split($sharepath,":"),"$")
Additionally, I'd just make an additional optional parameter for $Hidden and then do something like: if $hidden $sharename = $sharename + '$' endif $FileShare = $FService.Create ("FileShare", $ShareName)
|
|
Top
|
|
|
|
#148872 - 2005-09-30 08:06 PM
Re: Creating Share on Remote Computer
|
StarwarsKid
Seasoned Scripter
   
Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
|
Using those suggestions I have modified the UDF. Please check and verify if I made the changes correctly.
Code:
;Example: ; ;$Server ="server1" ;$SharePath ="c:\test\share" ;$ShareName ="Test Share" ;CreateShare($server,$shareName,$SharePath,,)
Function CreateShare($Server, $ShareName, $SharePath, optional $Domain, optional $hidden)
if not $domain $domain ="@domain" endif if not $server $server ="@wksta" endif if $hidden $sharename = $sharename + '$' endif
$unc =join(split($sharepath,":"),"$") $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
If I am understanding this correctly, would the syntax for using the modified UDF be as follows?
Code:
$Server ="server1" $SharePath ="c:\test\share" $ShareName ="Test Share"
CreateShare($server,$shareName,$SharePath,, 1 )
_________________________
let the wise listen and add to their learning, and let the discerning get guidance- Proverbs 1:5
|
|
Top
|
|
|
|
#148875 - 2005-10-01 01:27 AM
Re: Creating Share on Remote Computer
|
StarwarsKid
Seasoned Scripter
   
Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
|
I implemented the NoVarsInStrings compliance changes to the CreateShare UDF and have added the UDF changes recommended by Radimus.
Here is the new code (would this need to be updated on the UDF page?) Code:
;Example: ; ;$Server ="server1" ;$SharePath ="c:\test\share" ;$ShareName ="Test Share" ;CreateShare($server,$shareName,$SharePath,,)
Function CreateShare($Server, $ShareName, $SharePath, optional $Domain, optional $hidden)
if not $domain $domain =@domain endif if not $server $server =@wksta endif if $hidden $sharename = $sharename + '$' endif
$unc =join(split($sharepath,":"),"$") $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
The hidden share feature still isn't working. Any suggestions on what I should do? Thanks.
(*Thanks Les for TEACHING me, your examples were key)
_________________________
let the wise listen and add to their learning, and let the discerning get guidance- Proverbs 1:5
|
|
Top
|
|
|
|
#148876 - 2005-10-01 02:51 AM
Re: Creating Share on Remote Computer
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
try doubling up the the "$" to be "$$"
Eventually, Doc or Lonk will mention DIMming the vars and that the nul statements at the end aren't necessary
|
|
Top
|
|
|
|
#148877 - 2005-10-01 03:47 AM
Re: Creating Share on Remote Computer
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11634
Loc: CA
|
Okay
Dim $SO $SO=SetOption('Explicit','On') $SO=SetOption('NoVarsInStrings','On')
|
|
Top
|
|
|
|
#148880 - 2005-10-03 06:59 PM
Re: Creating Share on Remote Computer
|
StarwarsKid
Seasoned Scripter
   
Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
|
*EDIT* Just noticed something. I've been testing on my local PC. When I ran a test on a remote PC I was able to create a "hidden" share by making the share name with a '$' symbol after it. No modifications to the UDF. (for what it's worth .... ?) So, perhaps It's not a big deal, unless you want to create a hidden share with this script on a local computer....???
I've tried all recommended alterations to the Function, but am still unable to create a hidden share. Any corrections/suggestions?
After adding the suggested DIMming I receive the following error: Code:
E:\kixtest>kix32.exe createlocalshare.kix
ERROR : undefined variable [unc]! Script: E:\kixtest\UDF\CreateShare2.udf Line : 21
E:\kixtest>
*New* CreateShare UDF: Code:
;Example: ; ;$Server="server1" ;$SharePath="c:\test\share" ;$ShareName="Test Share" ;$Domain= ;$hidden= ;CreateShare($server,$shareName,$SharePath,$domain,$hidden)
Function CreateShare($Server, $ShareName, $SharePath, optional $Domain, optional $hidden)
Dim $iSO $iSO=SetOption('Explicit','On') $iSO=SetOption('NoVarsInStrings','On') $iSO=SetOption('NoMacrosInStrings','On')
if not $domain $domain=@domain endif if not $server $server=@wksta endif if $hidden $sharename=$sharename + '$' endif
$unc=join(split($sharepath,":"),"$") $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 Initiating KiX Script: Code:
call "@ScriptDir\UDF\MakePath.udf" call "@ScriptDir\UDF\CreateShare2.udf" $server="smith1" $shareName="local" $SharePath="c:\tempdrive" ;$Hidden =
CreateShare($Server, $ShareName, $SharePath,$domain,$hidden)
Edited by StarwarsKid (2005-10-03 07:20 PM)
_________________________
let the wise listen and add to their learning, and let the discerning get guidance- Proverbs 1:5
|
|
Top
|
|
|
|
#148886 - 2005-10-03 10:47 PM
Re: Creating Share on Remote Computer
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
did I do this one?
And they still come back to haunt me... :-)
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 584 anonymous users online.
|
|
|