Using Win32 functions in Visual FoxPro Image Gallery
Security
..msdn
ConvertSidToStringSid
GetAce
GetAclInformation
GetFileSecurity
GetLengthSid
GetNamedSecurityInfo
GetSecurityDescriptorDacl
GetSecurityDescriptorOwner
ImpersonateLoggedOnUser
IsValidSid
IsWellKnownSid
LogonUser
LookupAccountName
LookupAccountSid
LsaClose
LsaFreeMemory
LsaLookupSids
LsaOpenPolicy
RevertToSelf
Code examples:
Creating a folder
GetFileOwner - Get the owner of an NTFS file
Reading security permissions for NTFS files and folders
Creating a folder

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Versions:
click to open
 
DO declare
 
*!*    DO cd1 WITH "c:\temp1"
*!*    DO cd2 WITH "c:\temp2"
DO cd3 WITH "c:\temp3", GETENV("SystemRoot")
 
* end of main
 
PROCEDURE cd1(cNewFolder)
* creates new directory using default security descriptor
    IF CreateDirectory(cNewFolder, NULL) = 0
        *   3 = ERROR_PATH_NOT_FOUND
        *   5 = ERROR_ACCESS_DENIED
        * 183 = ERROR_ALREADY_EXISTS
        ? "CreateDirectory failed:", GetLastError()
    ENDIF
 
PROCEDURE cd2(cNewFolder)
* Shell version of this function
    nResult = SHCreateDirectory(0,;
        STRCONV(m.cNewFolder+CHR(0),5))
 
    IF nResult <> 0
        ? "SHCreateDirectory failed:", nResult
    ENDIF
 
PROCEDURE cd3(cNewFolder, cTemplateFolder)  && NTFS only
* creates new directory using security descriptor 
* of a template directory
#DEFINE DACL_SECURITY_INFORMATION 0x0004
#DEFINE SECURITY_ATTRIBUTES_SIZE 12
 
*!*    typedef struct _SECURITY_ATTRIBUTES {
*!*        DWORD nLength;
*!*        LPVOID lpSecurityDescriptor;
*!*        BOOL bInheritHandle;
*!*    } SECURITY_ATTRIBUTES,
*!*    *PSECURITY_ATTRIBUTES;
 
    LOCAL oSD, hSD, nSDSize, nBufsize, cSecurityAttributes
    oSD = CREATEOBJECT("LocalMem", 512)
    nBufsize=0
    hSD=oSD.GetHandle()
    nSDSize=oSD.GetSize()
 
    * obtain Security Descriptor for a template directory
    IF GetFileSecurity(m.cTemplateFolder, DACL_SECURITY_INFORMATION,;
        m.hSD, m.nSDSize, @nBufsize) = 0
        ? "GetFileSecurity call failed:", GetLastError()
        RETURN .F.
    ENDIF
 
    * assemble SECURITY_ATTRIBUTES structure
    cSecurityAttributes = num2dword(SECURITY_ATTRIBUTES_SIZE) +;
        num2dword(m.hSD) + num2dword(0)
 
    IF CreateDirectory(cNewFolder, @cSecurityAttributes) = 0
        ? "CreateDirectory failed:", GetLastError()
    ENDIF
 
PROCEDURE declare
    DECLARE INTEGER GetLastError IN kernel32
    DECLARE INTEGER LocalFree IN kernel32 INTEGER hMem
 
    DECLARE INTEGER LocalAlloc IN kernel32;
        INTEGER uFlags, INTEGER uBytes
 
    DECLARE INTEGER SHCreateDirectory IN shell32;
        INTEGER hwnd, STRING pszPath
 
    DECLARE INTEGER CreateDirectory IN kernel32;
        STRING lpPathName, STRING @lpSecurityAttr
 
    DECLARE INTEGER GetFileSecurity IN advapi32;
        STRING lpFileName, INTEGER RequestedInformation,;
        INTEGER pSecurityDescriptor, INTEGER nLength,;
        INTEGER @lpnLengthNeeded
 
DEFINE CLASS LocalMem As Session
* implements locally allocated memory block
#DEFINE LMEM_ZEROINIT 0x0040
PROTECTED hMem, bufsize
    hMem=0
    bufsize=0
 
PROCEDURE Init(nBufsize)
    THIS.bufsize = m.nBufsize
    THIS.hMem = LocalAlloc(LMEM_ZEROINIT, THIS.bufsize)
 
PROCEDURE Destroy
    IF THIS.hMem <> 0
        = LocalFree(THIS.hMem)
        THIS.hMem=0
    ENDIF
 
FUNCTION GetHandle
RETURN THIS.hMem
 
FUNCTION GetSize
RETURN THIS.bufsize
 
ENDDEFINE
 
FUNCTION num2dword(lnValue)
#DEFINE m0 0x0000100
#DEFINE m1 0x0010000
#DEFINE m2 0x1000000
    IF lnValue < 0
        lnValue = 0x100000000 + lnValue
    ENDIF
    LOCAL b0, b1, b2, b3
    b3 = Int(lnValue/m2)
    b2 = Int((lnValue - b3*m2)/m1)
    b1 = Int((lnValue - b3*m2 - b2*m1)/m0)
    b0 = Mod(lnValue, m0)
RETURN Chr(b0)+Chr(b1)+Chr(b2)+Chr(b3)
 
 
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
3014 bytes  
Created: 2001-07-12 12:00:00  
Modified: 2006-05-31 11:38:52  
Visits in 7 days: 38  
Listed functions:
CreateDirectory
GetFileSecurity
GetLastError
LocalAlloc
LocalFree
SHCreateDirectory
Printer friendly API declarations
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.


Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

Privacy policy
Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (54.234.67.55)
7 sec.Example: 'GetFocus returns a HWND value'
12.3 hrs.Function: 'CeRegDeleteValue'
Function group: 'Remote Application Programming (RAPI)'
 Example: 'Current directory of the application'
 Function: 'MAPISendDocuments'
12.64 hrs.Function: 'CreateEllipticRgn'
Function group: 'Region'
14.3 hrs.Function: 'AVIFileExit'
Function group: 'Windows Multimedia'
19.41 hrs.Example: 'Semi-transparent Form'
21.02 hrs.Example: 'The original LoadPicture() function in VFP returns valid handles to bitmaps, icons, cursors, and metafiles'
 
Function group: 'Keyboard Input'
1 day(s)Function: 'SetMonitorContrast'
Google
Advertise here!