Results 1 to 14 of 14

Thread: [RESOLVED] api to manipulate file/folder properties?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    Resolved [RESOLVED] api to manipulate file/folder properties?

    when you right-click on a file or folder, you see a properties option that you could click on. When you click on it, a window pops up which basically allows you to change certain properties of the file or folder. My question is, is there an api that allows you to change those properties? Excluding the option of sending window messages of mouse-buttons and keypress.

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: api to manipulate file/folder properties?

    I would imagine it would depend on the type of property. Change the program it opens with? The title/Author info? Permissions?

  3. #3
    Hyperactive Member
    Join Date
    Apr 2004
    Posts
    342

    Re: api to manipulate file/folder properties?

    VB Code:
    1. Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
    2. Public Const FILE_ATTRIBUTE_COMPRESSED = &H800
    3. Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
    4. Public Const FILE_ATTRIBUTE_HIDDEN = &H2
    5. Public Const FILE_ATTRIBUTE_NORMAL = &H80
    6. Public Const FILE_ATTRIBUTE_READONLY = &H1
    7. Public Const FILE_ATTRIBUTE_SYSTEM = &H4
    8. Public Const FILE_ATTRIBUTE_TEMPORARY = &H100
    9.  
    10. Public Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" (ByVal lpFileName as string, ByVal dwFileAttributes As Long

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    Re: api to manipulate file/folder properties?

    to be more specific, I want to change a folder's "sharing" property to yes.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    Re: api to manipulate file/folder properties?

    tward, could that api you showed do that?

  6. #6
    Hyperactive Member
    Join Date
    Apr 2004
    Posts
    342

    Re: api to manipulate file/folder properties?

    Not that I am aware of... It basically sets Hidden/Archive/System and ReadOnly attributes.

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: api to manipulate file/folder properties?

    Archive, Compressed, Directory,Hidden,Normal,Read-Only, System, Or Temporary are the attribute properties that can be changed. Those I knew about, but I did some Googling on "shared" and found nothing.

  8. #8
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: api to manipulate file/folder properties?

    The NetShareAdd API is what you want

    VB Code:
    1. 'Code by Roy Strickland, submitted by Jarret Peterson
    2. 'This code can share and unshare the directory 'c:\dos'
    3.  
    4. '===================================
    5. 'start a new project and add three command buttons
    6. 'set forms AutoRedraw property to true
    7. 'ADD TO A MODULE IN YOUR PROJECT:
    8. '====================================
    9. Option Explicit
    10. Public Platform As Long 'Platform ID of OS.  1 or 2
    11.  
    12. 'Structure for Getversion
    13. Public Type OSVERSIONINFO
    14.         dwOSVersionInfoSize As Long
    15.         dwMajorVersion As Long
    16.         dwMinorVersion As Long
    17.         dwBuildNumber As Long
    18.         dwPlatformId As Long
    19.         szCSDVersion As String * 128      '  Maintenance string for PSS usage
    20. End Type
    21.  
    22. Public Const STYPE_DISKTREE As Long = 0
    23. Public Const STYPE_PRINTQ As Long = 1
    24. Public Const STYPE_DEVICE As Long = 2
    25. Public Const STYPE_IPC As Long = 3
    26.  
    27. 'Access types
    28. Public Const ACCESS_READ As Long = &H1
    29. Public Const ACCESS_WRITE  As Long = &H2
    30. Public Const ACCESS_CREATE  As Long = &H4
    31. Public Const ACCESS_EXEC  As Long = &H8
    32. Public Const ACCESS_DELETE As Long = &H10
    33. Public Const ACCESS_ATRIB  As Long = &H20
    34. Public Const ACCESS_PERM  As Long = &H40
    35. Public Const ACCESS_ALL  As Long = &H7F
    36. Public Const WNTYPE_DRIVE  As Long = 1
    37. Public Const SHI_USES_UNLIMITED  As Long = -1
    38.  
    39. 'Info structures for NetShareAdd
    40. Type SHARE_INFO_2
    41.     shi2_netname As String * 14
    42.     shi2_type As Long
    43.     shi2_remark As String  'Far pointer to string
    44.     shi2_permissions As Long
    45.     shi2_max_uses As Long
    46.     shi2_current_uses As Long
    47.     shi2_path As String    'Far pointer to string
    48.     shi2_passwd As String * 10
    49. End Type
    50.  
    51. Type SHARE_INFO_50
    52.     shi50_netname As String
    53.     shi50_type As String
    54.     shi50_flags As Long
    55.     shi50_remark As String
    56.     shi50_path As String
    57.     shi50_rw_password As String
    58.     shi50_ro_password As String
    59. End Type
    60.  
    61. 'ACL for Security Descriptor
    62. Public Type ACL
    63.         AclRevision As Byte
    64.         Sbz1 As Byte
    65.         AclSize As Integer
    66.         AceCount As Integer
    67.         Sbz2 As Integer
    68. End Type
    69.  
    70. 'Security Descriptor for SHARE_INFO_502
    71. Public Type SECURITY_DESCRIPTOR
    72.         Revision As Byte
    73.         Sbz1 As Byte
    74.         Control As Long
    75.         Owner As Long
    76.         Group As Long
    77.         Sacl As ACL
    78.         Dacl As ACL
    79. End Type
    80.  
    81. Type SHARE_INFO_502
    82.     shi502_netname As String
    83.     shi502_type As Long
    84.     shi502_remark As String
    85.     shi502_permissions As Long
    86.     shi502_max_uses As Long
    87.     shi502_current_uses As Long
    88.     shi502_path As String
    89.     shi502_passwd As String
    90.     shi502_reserved As Long
    91.     shi502_security_descriptor As SECURITY_DESCRIPTOR
    92. End Type
    93.  
    94. Public Security As SECURITY_DESCRIPTOR
    95.  
    96. Public Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _
    97.                             (lpVersionInformation As OSVERSIONINFO) As Long
    98. Public Declare Function lstrcpy Lib "kernel32" _
    99.                     (ByVal lpString1 As Any, ByVal lpString2 As Any) As Long
    100. 'NT
    101. Public Declare Function NetShareDelNT Lib "netapi32.dll" Alias "NetShareDel" _
    102. (ByVal servername As Any, ByVal netname As String, ByVal reserved As Long) As Long
    103. Public Declare Function NetShareAddNT Lib "netapi32.dll" Alias "NetShareAdd" _
    104.                                 (ByVal servername As Any, ByVal slevel As Long, _
    105.                                 buf As SHARE_INFO_502, ByVal cbbuf As Long) As Long
    106. '9x
    107. Public Declare Function NetShareDel9x Lib "svrapi.dll" Alias "NetShareDel" _
    108. (ByVal servername As Any, ByVal netname As String, ByVal reserved As Long) As Long
    109. Public Declare Function NetShareAdd9x Lib "svrapi.dll" Alias "NetShareAdd" _
    110. (ByVal servername As Any, ByVal slevel As Long, buf As SHARE_INFO_50, ByVal cbbuf As Long) As Long
    111.  
    112. '====================
    113. 'ADD CODE TO FORM:
    114. '====================
    115. Option Explicit
    116. Dim SI2 As SHARE_INFO_2
    117. Dim SI502 As SHARE_INFO_502
    118. Dim SI50 As SHARE_INFO_50
    119. Dim OSVERInfo As OSVERSIONINFO
    120. Dim ShareRemark As String
    121. Dim SharePath As String
    122. Dim nerr As Long
    123. Dim nPath As String
    124. Dim pwd As String
    125. Dim ret As Long
    126. Dim OS As Long
    127. Private Sub Form_Load()
    128.     OSVERInfo.dwOSVersionInfoSize = Len(OSVERInfo)
    129.     OS = GetVersionEx(OSVERInfo)
    130.     Command1.Caption = "Create Share NT"
    131.     Command2.Caption = "Create Share Win9x"
    132.     Command3.Caption = "Delete Share"
    133. End Sub
    134. Private Sub Command1_Click()
    135. 'NT
    136. On Error Resume Next
    137.     SetStrings
    138.     nerr = NetShareAddNT(0&, 2, SI502, ret)
    139.     Print nerr
    140. End Sub
    141. Private Sub Command2_Click()
    142. '9x
    143. On Error Resume Next
    144.     SetStrings
    145.     nerr = NetShareAdd9x(0&, 50, SI50, ret)
    146.     Print nerr
    147. End Sub
    148. Private Sub Command3_Click()
    149. 'Delete
    150. On Error Resume Next
    151.     If OSVERInfo.dwPlatformId = 1 Then
    152.         nerr = NetShareDel9x(0&, nPath, 0&)
    153.     Else
    154.         nerr = NetShareDelNT(0&, nPath, 0&)
    155.         Print nerr
    156.     End If
    157. End Sub
    158. Public Sub SetStrings()
    159.     If OSVERInfo.dwPlatformId = 1 Then
    160. '9x OS
    161.         nPath = "NewShare"
    162.         ShareRemark = "Remark for new share"
    163.         SharePath = "C:\dos"
    164.         pwd = "Share"
    165.        
    166.         SI50.shi50_netname = nPath
    167.         SI50.shi50_path = SharePath
    168.  
    169.         SI50.shi50_remark = ShareRemark
    170.         SI50.shi50_type = STYPE_DISKTREE
    171.         SI50.shi50_ro_password = vbNullChar
    172.         SI50.shi50_rw_password = vbNullChar
    173.        
    174.     Else
    175. 'NT OS
    176.         nPath = StrConv("NewShare", vbUnicode)
    177.         ShareRemark = StrConv("Remark for new share", vbUnicode)
    178.         SharePath = StrConv("C:\dos", vbUnicode)
    179.         pwd = StrConv("Share", vbUnicode)
    180.    
    181.         SI502.shi502_current_uses = 0
    182.         SI502.shi502_max_uses = 10
    183.         SI502.shi502_netname = nPath
    184.         SI502.shi502_passwd = pwd
    185.         SI502.shi502_path = SharePath
    186.         SI502.shi502_permissions = ACCESS_ALL
    187.         SI502.shi502_remark = ShareRemark
    188.         SI502.shi502_reserved = 0
    189.         SI502.shi502_security_descriptor = Security
    190.         SI502.shi502_type = STYPE_DISKTREE
    191.        
    192.     End If
    193. End Sub


    Has someone helped you? Then you can Rate their helpful post.

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: api to manipulate file/folder properties?

    Clearly I was Googling on the wrong keyword. Nice find Manavo11!

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    Re: api to manipulate file/folder properties?

    Thanks for the responses. I'll try the code out Manavo11.

  11. #11
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: api to manipulate file/folder properties?

    I tried it on Win XP Pro and it worked. Didn't try to access it from another computer but the hand showed up on the folder's icon...


    Has someone helped you? Then you can Rate their helpful post.

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    Re: api to manipulate file/folder properties?

    thanks, it works. But i got some questions. One, how come when the NetShareAdd for NT has level 2 for parameter, it still works? Shouldn't it work only if it is level 502? And second, have you tried doing this in c++? For some reason, it gives me a "123" errorcode, error_invalid_path. I'm guessing it has something to do with the fact it needs pointer to unicode, but how do you do that in c++?

  13. #13
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171


    Has someone helped you? Then you can Rate their helpful post.

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,168

    Re: api to manipulate file/folder properties?

    thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width