Page 1 of 1

Network Share Management Functions - ?

Posted: Wed Dec 24, 2014 12:04 pm
by registrymechanic22
Help please.
Prompt please an example how to do it on PB:
  • NetShareAdd_(
    NetShareCheck_(
    NetShareDel_(
    NetShareDelEx_(
    NetShareEnum_(
    NetShareGetInfo_(
    NetShareSetInfo_(
    NetStatisticsGet_(
I do not understand :oops: how this translates into the PB and examples on forums never found :( .
Thanks.

Re: Network Share Management Functions - ?

Posted: Wed Dec 24, 2014 12:29 pm
by JHPJHP
Hi registrymechanic22,

This should get you started:

Code: Select all

Structure _SHARE_INFO_502 
  shi502_netname.l
  shi502_type.l
  shi502_remark.l
  shi502_permissions.l
  shi502_max_uses.l
  shi502_current_uses.l
  shi502_path.l
  shi502_passwd.l
  shi502_reserved.l
  *shi502_security_descriptor.SECURITY_DESCRIPTOR
EndStructure

If FileSize("C:\Temp") <> -2 : CreateDirectory("C:\Temp") : EndIf

If FileSize("C:\Temp") = -2
  #STYPE_DISKTREE = 0
  #STYPE_PRINTQ = 1
  #STYPE_DEVICE = 2
  #STYPE_IPC = 3
  #STYPE_SPECIAL = $80000000

  #ACCESS_READ = $1
  #ACCESS_WRITE = $2
  #ACCESS_CREATE = $4
  #ACCESS_EXEC = $8
  #ACCESS_DELETE = $10
  #ACCESS_ATRIB = $20
  #ACCESS_PERM = $40

  buf._SHARE_INFO_502
  buf\shi502_netname = @"TempShared"
  buf\shi502_type = #STYPE_DISKTREE
  buf\shi502_remark = @"Test Share"
  buf\shi502_permissions = #ACCESS_READ
  buf\shi502_max_uses -1
  buf\shi502_current_uses = 5
  buf\shi502_path = @"C:\Temp"
  buf\shi502_reserved = 0

  NetShareAdd_(#Null, 502, @buf, @parm_err)

  If parm_err : Debug "ERROR: Incorrect Parameter " + Str(parm_err) : EndIf

Else
  Debug "ERROR: Missing Folder C:\Temp"
EndIf
Compiler-Options
- Create unicode executable
- Request Administrator mode for Windows Vista and above
-- needed for Windows 8

SHARE_INFO_502 structure: http://msdn.microsoft.com/en-us/library ... s.85).aspx

Re: Network Share Management Functions - ?

Posted: Wed Dec 24, 2014 2:12 pm
by registrymechanic22
Hi JHPJHP!
JHPJHP wrote:

Code: Select all

;---------------------------------------------------------------------------
;----24.12.2014-------------------------------------------------------------
;-----by JHPJHP-------------------------------------------------------------
;---------------------------------------------------------------------------

Structure _SHARE_INFO_502 
  shi502_netname.l
  shi502_type.l
  shi502_remark.l
  shi502_permissions.l
  shi502_max_uses.l
  shi502_current_uses.l
  shi502_path.l
  shi502_passwd.l
  shi502_reserved.l
  *shi502_security_descriptor.SECURITY_DESCRIPTOR
EndStructure

  #STYPE_DISKTREE = 0
  #STYPE_PRINTQ = 1
  #STYPE_DEVICE = 2
  #STYPE_IPC = 3
  #STYPE_SPECIAL = $80000000

  #ACCESS_READ = $1
  #ACCESS_WRITE = $2
  #ACCESS_CREATE = $4
  #ACCESS_EXEC = $8
  #ACCESS_DELETE = $10
  #ACCESS_ATRIB = $20
  #ACCESS_PERM = $40
;---------------------------------------------------------------------------

If FileSize("C:\Test") <> -2 : CreateDirectory("C:\Test") : EndIf

;---------------------------------------------------------------------------
;-Add Share

If FileSize("C:\Test") = -2

  buf._SHARE_INFO_502
  buf\shi502_netname = @"TestShared"
  buf\shi502_type = #STYPE_DISKTREE
  buf\shi502_remark = @"Test Share"
  buf\shi502_permissions = #ACCESS_READ
  buf\shi502_max_uses -1
  buf\shi502_current_uses = 5
  buf\shi502_path = @"C:\Test"
  buf\shi502_reserved = 0
  NetShareAdd_(#Null, 502, @buf, @parm_err)

  If parm_err : Debug "ERROR: Parameter: " + Str(parm_err) + "." : EndIf

Else
  Debug "ERROR: Folder Test Missing."
EndIf

;---------------------------------------------------------------------------
;-Del Share

Delay (5000)
If FileSize("C:\Test") = -2

NetShareDel_(#Null, "TestShared", #Null)

Else
  Debug "ERROR: Folder Test Missing."
EndIf

;---------------------------------------------------------------------------
; 
.................................
..............
.......
Thank you very much for your help! :D
Best regards.



Can I ask for help to give examples of the remaining functions ?: :oops:
  • NetShareCheck_(
    NetShareDelEx_(
    NetShareEnum_(
    NetShareGetInfo_(
    NetShareSetInfo_(
    NetStatisticsGet_(

Re: Network Share Management Functions - ?

Posted: Wed Dec 24, 2014 2:20 pm
by Deluxe0321
More here

Re: Network Share Management Functions - ?

Posted: Wed Dec 24, 2014 6:53 pm
by JHPJHP
Hi registrymechanic22,

When time allows I'll be adding an updated version titled Network Share Management Functions to Tricks 'n' Tips.

Seasons Greetings,

Re: Network Share Management Functions - ?

Posted: Thu Dec 25, 2014 9:12 am
by registrymechanic22
JHPJHP wrote:Hi registrymechanic22,
Here is a link to the NetShare Functions you requested: https://www.dropbox.com/s/sv3ja4n0ubhs0 ... e.zip?dl=0
The example creates and deletes the folder C:\JHPJHP, adding and removing the share JHPShare.
- if the folder already exists it will not be deleted, but the share will be removed
NB*: When time allows I'll be adding an updated version titled "NetShare" to my Services, Stuff, and Shellhook post.
Seasons Greetings,
COOL!
Many thanks!
Wish you all the best!

Re: Network Share Management Functions - ?

Posted: Mon Apr 25, 2016 5:22 pm
by PeteM
The example above no longer seems to work. The directory gets created, but "ERROR: Parameter: 501." gets returned. Downloading the full Netshare package produces an almost identical result in NetShareAdd.pb - its returns "ERROR: Invalid Parameter [ 501 ]"

I am using 64-bit 5.42 LTS on Windows 10.

Any ideas gratefully received!

Re: Network Share Management Functions - ?

Posted: Tue Apr 26, 2016 1:26 am
by JHPJHP
Hi PeteM,

The Network Share Management Functions have been updated to support x64.

Re: Network Share Management Functions - ?

Posted: Tue Apr 26, 2016 10:14 am
by PeteM
Beautiful, worked first time! Thanks.