Network Share Management Functions - ?

Just starting out? Need help? Post your questions and find answers here.
registrymechanic22
Enthusiast
Enthusiast
Posts: 176
Joined: Sun Jun 28, 2009 7:07 pm
Location: RUS

Network Share Management Functions - ?

Post 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.
User avatar
JHPJHP
Addict
Addict
Posts: 2258
Joined: Sat Oct 09, 2010 3:47 am

Re: Network Share Management Functions - ?

Post 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

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
registrymechanic22
Enthusiast
Enthusiast
Posts: 176
Joined: Sun Jun 28, 2009 7:07 pm
Location: RUS

Re: Network Share Management Functions - ?

Post 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_(
Deluxe0321
User
User
Posts: 69
Joined: Tue Sep 16, 2008 6:11 am
Location: ger

Re: Network Share Management Functions - ?

Post by Deluxe0321 »

More here
User avatar
JHPJHP
Addict
Addict
Posts: 2258
Joined: Sat Oct 09, 2010 3:47 am

Re: Network Share Management Functions - ?

Post 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,
Last edited by JHPJHP on Tue Apr 26, 2016 2:03 am, edited 4 times in total.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
registrymechanic22
Enthusiast
Enthusiast
Posts: 176
Joined: Sun Jun 28, 2009 7:07 pm
Location: RUS

Re: Network Share Management Functions - ?

Post 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!
PeteM
User
User
Posts: 12
Joined: Thu Mar 05, 2015 8:44 pm

Re: Network Share Management Functions - ?

Post 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!
User avatar
JHPJHP
Addict
Addict
Posts: 2258
Joined: Sat Oct 09, 2010 3:47 am

Re: Network Share Management Functions - ?

Post by JHPJHP »

Hi PeteM,

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

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
PeteM
User
User
Posts: 12
Joined: Thu Mar 05, 2015 8:44 pm

Re: Network Share Management Functions - ?

Post by PeteM »

Beautiful, worked first time! Thanks.
Post Reply