Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatically share a folder. 1

Status
Not open for further replies.

foxwizard

Programmer
Aug 23, 2001
81
PH
Hi guys,

How can I programmatically share a folder?

Thanks.

Bren Soriano
SA-Philippines
 

Hi Mike,

Thank you for the link.

Bren Soriano
SA-Philippines

 
Hi rotelmak,

Codes from any versions of visual foxpro would be appreciated.

Thanks.

Bren Soriano
SA-Philippines
 
It's not hard to translate to VFP:
Code:
LOCAL comp As IADsComputer, ;
      serv As IADsService, ;
      fserv As IADsContainer, ;
      share As IADsFileShare, ;
     shareNew As IADsFileShare, ;
     v 

   *' Replace DOMAIN, SERVER & SHARE with the appropriate
   *' domain, server  and share names
   share = GetObject("WinNT://DOMAIN/SERVER/lanmanserver/SHARE")
   v = share.Path &&' Gets directory path on server
   RELEASE share 

   *' Replace DOMAIN & SERVER with the appropriate domain and server names
   fserv = GetObject("WinNT://DOMAIN/SERVER/lanmanserver")

   *' Enumerate existing shares
   For Each share In fserv
     ?share.Class,share.ADsPath,share.HostComputer,share.Path
   ENDFOR

   *' Create share in fileservice container
   shareNew = fserv.Create("fileshare", "newshare")
   shareNew.Path = "C:\"
   shareNew.SetInfo  &&' Commit new share

   *' Delete share
   fserv.Delete( "fileshare", "newshare" )

   *' Fails since share is gone
   shareNew.GetInfo

I tested some of these on my computer in vfp and they work.

Please note the comment:
*' Replace DOMAIN, SERVER & SHARE with the appropriate
*' domain, server and share names


Plus, you need to be administrator on the specified computer for the add/delete share commands to work.
How to be administrator if you aren't already logged in as one? I don't know.


- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
Just one more way:

Code:
DECLARE INTEGER WNetAddConnection IN "mpr.dll" ;
	STRING cRemoteName, ;
	STRING cPassword, ;
	STRING cLocalName

cResource = "\\MyServer\MyShare"
cPassword = "MyPassword"
cDriveLetter = "myDriverLetter:"

lnRetval = WNetAddConnection(cResource, cPassword, cDriveLetter)

note lnRetVal = 0 if successful and the password is not needed if the user is already logged in and has rights to the server directory. This does a map root of the cResource.

return (lnRetval)

Steve Bowman
Independent Technology, Inc.
CA, USA
 
Steve,

That's a useful complementary function... however "cResource" must already be "shared" for it to work... it doesn't actually create a share.

- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
Sorry I was not reading carefully the code is to MAP a drive


Steve Bowman
Independent Technology, Inc.
CA, USA
 
Hi Bill & Steve,

That was very nice Bill. Thank you so much. I give you a star for this.

Thanks also to Steve for your post. It might be useful in some other way.


Bren Soriano
SA-Philippines
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top