Page 1 of 2 12>
Topic Options
#148867 - 2005-09-30 01:45 AM Creating Share on Remote Computer
StarwarsKid Offline
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
#148868 - 2005-09-30 07:02 PM Re: Creating Share on Remote Computer
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
It appears this may be a harder question to answer than I first realized. I did a little searching for alternative methods of creating remote shares and I found a post by Shawn about an rmtshare.exe tool. It looks like this tools is from the NT reskit. I downloaded the W2K3 reskit, but didn't find a comparible tool.

Does anyone have recommendations on alternative methods for creating shares on remote computers?
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#148869 - 2005-09-30 07:16 PM Re: Creating Share on Remote Computer
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Do you mean other than rmtshare?
Have you tried cleaning up the UDF to be NoVarsInStrings compliant?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#148870 - 2005-09-30 07:40 PM Re: Creating Share on Remote Computer
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
I mean other than the NT reskit version of rmtshare, as in, an updated version of the program I haven't found yet. My concern here is whether the NT version of rmtshare is compatible with WinXP.

I tried adding the NoVarsInStrings to my KiX script, but the CreateShare UDF blows up at line 21. I'm not familiar with how to make a UDF NoVarsInStrings compliant (yet, anyway). Are there guidelines for doing this?
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#148871 - 2005-09-30 07:56 PM Re: Creating Share on Remote Computer
Radimus Moderator Offline
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)
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#148872 - 2005-09-30 08:06 PM Re: Creating Share on Remote Computer
StarwarsKid Offline
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
#148873 - 2005-09-30 08:18 PM Re: Creating Share on Remote Computer
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
I just ran the script with the new modifications. I get this error:
Code:
 E:\kixtest>kix32.exe createlocalshare.kix

ERROR : expected ')'!
Script: E:\kixtest\UDF\CreateShare.udf
Line : 15

E:\kixtest>

_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#148874 - 2005-09-30 08:21 PM Re: Creating Share on Remote Computer
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Making it NoVarsInStrings compliant is as easy as not putting vars in strings, hence the option "NoVarsInStrings". A string is in its siplest form, anything in quotes. So, for example:

if not exist("$uncpath")
should be:
if not exist($uncpath)

$path=makepath("$uncpath")
should be:
$path=makepath($uncpath)

$FService = GetObject ("WinNT://$Domain/$Server/LanmanServer,FileService")
should be:
$FService = GetObject ("WinNT://"+$Domain+"/"+$Server+"/LanmanServer,FileService")

While you're at it, the same holds true for macros:

$domain ="@domain"
should be:
$domain = @domain
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#148875 - 2005-10-01 01:27 AM Re: Creating Share on Remote Computer
StarwarsKid Offline
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 Offline
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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#148877 - 2005-10-01 03:47 AM Re: Creating Share on Remote Computer
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: CA
Okay

Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')


Top
#148878 - 2005-10-01 04:33 PM Re: Creating Share on Remote Computer
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Not to nitpick, but the new standard is:
Code:

Dim $iSO
$iSO=SetOption('Explicit','On')
$iSO=SetOption('NoVarsInStrings','On')
$iSO=SetOption('NoMacrosInStrings','On')


including compliance with KiXforms-based Hungarian Notation
_________________________
There are two types of vessels, submarines and targets.

Top
#148879 - 2005-10-02 02:35 AM Re: Creating Share on Remote Computer
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: CA
Perhaps this
$SO=SetOption('NoMacrosInStrings','On')

AS for the Hungarian, I've yet to see any sort of standards compliance with that. Some use it, some don't few if any use it with all scripts.

Top
#148880 - 2005-10-03 06:59 PM Re: Creating Share on Remote Computer
StarwarsKid Offline
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
#148881 - 2005-10-03 07:20 PM Re: Creating Share on Remote Computer
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Quote:


When you enable the Explicit option, you must explicitly declare all variables using the Dim, Global, or ReDim





Don't see DIM $unc in your code.
According to what the manual says you should DIM all vars.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#148882 - 2005-10-03 07:22 PM Re: Creating Share on Remote Computer
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
Thanks! I'll do that...... (I wish I understood this stuff better so I wouldn't miss these details.....)
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#148883 - 2005-10-03 07:23 PM Re: Creating Share on Remote Computer
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
No worries, sh#t happens.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#148884 - 2005-10-03 07:33 PM Re: Creating Share on Remote Computer
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
After DIMming the variables the script will run, but the folder isn't created. Any suggestions? I don't receive any error messages.
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#148885 - 2005-10-03 10:43 PM Re: Creating Share on Remote Computer
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Been trying for some time now but can get it to work also.
The makepath work great in my slightly alterd version of your code but the share is not created.
Maybe the creator of the original createshare function CreateShare() - creates remote shares by Radimus can shine his light on this.

Sorry to not help but it looks like I'm stuck in trying and failing must be some kind of knot in my brain but can’t get it out


Edited by Mart (2005-10-03 10:44 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#148886 - 2005-10-03 10:47 PM Re: Creating Share on Remote Computer
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
did I do this one?

And they still come back to haunt me... :-)
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 659 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.079 seconds in which 0.028 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org