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!

API-calls

Status
Not open for further replies.

tsiv

Programmer
Jun 8, 2000
7
DK
Hi<br><br>I wish to use API-calls to create a new directory on my NTFS-volume with permissions set to something I myself choose.<br><br>I have the following code in a module - the declaration of the API-function-call takes a path (as string) to where the new folders is to be created as first parameter and second parameter is the SECURITY-settings. How do I specify this? As seen below I have found the typedeclarations with the API-viewer but I don't know how it fits together...Here's the module code:<br><br><br>Public Declare Function CreateDirectory Lib &quot;kernel32&quot; Alias &quot;CreateDirectoryA&quot; (ByVal lpPathName As String, lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long<br><br>Public Type SECURITY_ATTRIBUTES<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nLength As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lpSecurityDescriptor As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bInheritHandle As Long<br>End Type<br><br>Public Type ACL<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AclRevision As Byte<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sbz1 As Byte<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AclSize As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AceCount As Integer<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sbz2 As Integer<br>End Type<br><br>Public Type SECURITY_DESCRIPTOR<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Revision As Byte<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sbz1 As Byte<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Control As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Owner As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Group As Long<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sacl As ACL<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dacl As ACL<br>End Type<br><br><br>Next I have this in my button on a form:<br><br>' Create the new directory C:\Dummy\NewDir and<br>' give it default security attributes.<br>Dim secattr As SECURITY_ATTRIBUTES&nbsp;&nbsp;' security attributes structure<br>Dim retval As Long&nbsp;&nbsp;' return value<br><br>' Set the desired security attributes<br>secattr.nLength = Len(secattr)&nbsp;&nbsp;' size of the structure<br>secattr.lpSecurityDescriptor = 0&nbsp;&nbsp;' default (normal) level of security<br>secattr.bInheritHandle = 1&nbsp;&nbsp;' this is the default setting<br><br>' Create the directory.<br>retval = CreateDirectory(&quot;C:\nyt&quot;, secattr)<br><br><br>Does anyone have any ideas as to how this would be done?<br><br>Kind regards<br><br>Siv
 
you create a new variable of those &quot;types&quot;<br>its no different then using<br>Dim myvar as new SECURITY_ATTRIBUTE(depending on the type, you may or may not have to use the new operator)<br>but since you are using it, I would try to put a new operator in front, since you may have to allocate the type(actually create it in memory)<br><br>then you can fill that variable up with whatever<br>just a tip, if you ever need to stick multiple things into a single type, say its a parameter type for a API call, normally you can do this by assinging<br>&quot;some string&quot; & vbNullChar & &quot;Some String&quot;& VbNullChar, if i am not mistaken thats the format of a Variant array.<br><br>Also here is the definition I found for your command<br>as taken from the MSDN Library<br><br><FONT FACE=monospace><br>CreateDirectory<br>This function creates a new directory. If the underlying file system supports security on files and directories, the function applies a specified security descriptor to the new directory. <br><br>A remote application interface (RAPI) version of this function exists, and it is named CeCreateDirectory. <br><br>At a Glance<br><br>Header file: Winbase.h <br>Windows CE versions: 1.0 and later <br><br><br>Syntax<br><br>BOOL CreateDirectory(LPCTSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes); <br><br>Parameters<br><br>lpPathName<br><br>[in] Long pointer to a null-terminated string that specifies the path of the directory to be created. <br><br>There is a default string size limit for paths of MAX_PATH characters. This limit is related to how the CreateDirectory function parses paths. <br><br>lpSecurityAttributes<br><br>[in] Ignored; set to NULL. <br><br>Return Values<br><br>Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError. <br><br>Remarks<br><br>Some file systems, such as NTFS, support compression or encryption for individual files and directories. On volumes formatted for such a file system, a new directory inherits the compression and encryption attributes of its parent directory. <br><br>See Also<br><br>CreateFile, RemoveDirectory <br></font><br><br>hopefully this information helps(its C++ oriented the API command, but the idea is pretty straight forward, a string(or a reference to a string) and that special type)<br> <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
I am just curious , Are you not able to use the FileSystemObject in NT?<br><br>if you dont know much about it heres a quick example of how to make a folder(no API declarations needed, the reference is built into VB6, unsure about 5)<br><br><FONT FACE=monospace><br>Dim fs As New FileSystemObject<br><br>fs.CreateFolder(Path as String)<br></font><br><br>that command also returns a Folder Type, so you can actually assign the return of that into a variable and work with it. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
Thanks for replying<br><br>I have one puzzle though. My problem is I don't know what to pass as lpSecurityAttributes.<br><br>Correct me if I'm wrong:<br><br>I need to create an object/declaration with type SECURITY_ATTRIBUTES. The type-declaration of SECURITY_ATTRIBUTES points to the SECURITY_DESCRIPTER-type where the type of the DACL is declared (which is as I understand it the holder of who has what permissions to an object). So how do I go about generating the objects/declaration from the bottom up??<br><br>If you can assist me in anyway I would greatly appreciate it.<br><br>Kind regards<br><br>Siv<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 
Try passing NULL , and see if it will sucessfully create it, also try my fileSystemOBject sugestion, might be much easier. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML,Visual InterDev 6, ASP(WebProgramming), QBasic(least i didnt start with COBOL)
 
It is not the creation of the directory that is my problem - I can easily create this also with the FileSystemObject.<br><br>My problem is that I want to be able to add NT-users or NTgroups to the permissionlist on that newly created directory.<br><br>Kind regards<br><br>Siv
 
Hi again<br><br>Actually I think I'm supposed to use this API-function. Ace stands for Access Control Entry - and is the entry: Everyone - Read (just an example!). This is what I want to add to my newly created directory.<br><br>The function to add an ACE:<br><br>Public Declare Function AddAccessAllowedAce Lib &quot;advapi32.dll&quot; (pAcl As ACL, ByVal dwAceRevision As Long, ByVal AccessMask As Long, pSid As Any) As Long<br><br>Can you give any help on this? or do you know how to find documentation on this function?<br><br>Kind regards<br><br>Siv
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top