Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
API GetVolumeInformation
Message
De
19/07/2002 12:31:11
Elyse Pomerantz
Dynamic Data Concepts, Inc.
Brooklyn, New York, États-Unis
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00497258
Message ID:
00680508
Vues:
24
I'm also looking for some way of getting a serial number on a Novell network. Was this ever resolved? Does this code work on Novell?


>>Hi,
>>I'm trying to get a disk serial number using API GetVOlumeInformation.
>>It works fine when I get local drive's number (like c:\ or d:\ )
>>but it fails when I try to reach network drives (like \\server\c\ ).
>>I read in Microsoft FAQ that it is a bug of W95 and W98. They give a workaround example in c++ , but it was imposible for me to translate it to VFP because of the HANDLERS and the structured type it uses.
>>
>>Anyone ever had this problem or has anyone any idea ?
>>
>>thanks
>
>Fabian,
>
>I haven't been able to get the solution proposed by the KB article to work on a Novell network. It does return the file attributes properly, so it may be an issue with Novell. As a result, here's the code to access the API call in question
#DEFINE GENERIC_READ           0x80000000
>DECLARE INTEGER GetFileInformationByHandle IN Win32API;
>  INTEGER hFile, STRING @lpFileInformation
>
>LOCAL lcfile, oFileIO, lnhandle
>lcfile = GETFILE("*")
>IF NOT EMPTY(lcfile)
>  SET PROCEDURE TO FILEIO ADDITIVE
>  oFileIO = CREATEOBJECT('FileOpenClose')
>  IF oFileIO.OpenFile(lcfile, GENERIC_READ)
>    lnhandle = oFileIO.nFileHandle
>    lcFileInfo = REPLICATE(CHR(0), 52)
>    IF GetFileInformationByHandle(lnhandle, @lcFileInfo) > 0
>      SET PROCEDURE TO Con_Int ADDITIVE
>      oCovert = CREATEOBJECT('ConvertInt')
>      ? oCovert.StringToInteger(SUBSTR(lcFileInfo, 29, 4))
>    ENDIF
>    oFileIO = NULL
>  ENDIF
>ENDIF
>
>* FileIO.prg
>
>DEFINE CLASS FileOpenClose AS CUSTOM
>  #DEFINE GENERIC_READ           0x80000000
>  #DEFINE FILE_SHARE_READ        0x00000001
>  #DEFINE FILE_SHARE_WRITE       0x00000002
>  #DEFINE FILE_FLAG_NO_BUFFERING 0x20000000
>  #DEFINE OPEN_EXISTING          0x00000003
>
>  * API Open and close existing file routines
>
>  * The file handle
>  nFileHandle = 0
>
>  PROCEDURE Init
>
>    DECLARE SHORT CloseHandle IN Win32API;
>      INTEGER hObject
>    DECLARE INTEGER CreateFile IN Win32API;
>      STRING @lpFileName, INTEGER dwDesiredAccess,;
>      INTEGER dwShareMode, STRING @lpSecurityAttributes,;
>      INTEGER dwCreationDistribution,;
>      INTEGER dwFlagsAndAttributes,;
>      INTEGER hTemplateFile
>    RETURN
>  ENDPROC
>
>  FUNCTION OpenFile
>
>    LPARAMETERS pcFileName, pnMode
>    * pnMode is either GENERIC_READ or
>    * GENERIC_WRITE
>
>    LOCAL llresult, lcfilename, lnaccess
>    lcfilename = pcFileName
>    IF This.nFileHandle # 0
>      This.FileClose
>    ENDIF
>    IF pnMode = GENERIC_READ
>      lnaccess = FILE_SHARE_READ
>    ELSE
>      lnaccess = FILE_SHARE_WRITE
>    ENDIF
>    This.nFileHandle = CreateFile(@lcfilename, pnMode,;
>      lnaccess, 0, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, 0)
>    llresult = (This.nFileHandle > -1)
>    IF NOT llresult
>      This.nFileHandle = 0
>    ENDIF
>    RETURN llresult
>  ENDFUNC
>
>  PROCEDURE CloseFile
>
>    IF This.nFileHandle # 0
>      = CloseHandle(This.nFileHandle)
>      This.nFileHandle = 0
>    ENDIF
>    RETURN
>  ENDPROC
>
>  PROCEDURE Destroy
>
>    This.CloseFile
>    RETURN
>  ENDPROC
>ENDDEFINE
>
>* Con_Int.prg
>
>DEFINE CLASS ConvertInt AS CUSTOM
>
>  FUNCTION IntegerToString
>
>    LPARAMETER pnInteger, pnbytes
>
>    LOCAL lcresult, lnbytes, lnmask,;
>      lninteger, lni, lnchar
>    lcresult = ""
>    IF PCOUNT() = 2
>      lnbytes = pnbytes
>    ELSE
>      * Default to DWORD
>      lnbytes = 4
>    ENDIF
>    lninteger = pnInteger
>    lnmask = 255
>    FOR lni = 1 TO lnbytes
>      lnchar = BITAND(lninteger, lnmask)
>      lcresult = lcresult + CHR(lnchar)
>      lninteger = BITRSHIFT(lninteger, 8)
>    NEXT
>    RETURN lcresult
>  ENDFUNC
>
>  FUNCTION StringToInteger
>
>    LPARAMETER pcstring, plsigned
>
>    LOCAL lnresult, lnlast, lni, llsigned,;
>      lnmsb, lnmax
>    lnresult = 0
>    lnlast = LEN(pcstring)
>    * Return Signed Integer?
>    IF PCOUNT() = 2
>      llsigned = plsigned
>    ELSE
>      llsigned = .F.
>    ENDIF
>    FOR lni = 1 TO lnlast
>      lnresult = lnresult + ASC(SUBSTR(pcstring, lni, 1)) * (256 ^ (lni - 1))
>    NEXT
>    IF llsigned
>      lnmsb = (lnlast * 8) - 1
>      IF BITTEST(lnresult, lnmsb)
>        lnmax = (2 ^ (lnmsb + 1))
>        lnresult = lnresult - lnmax
>      ENDIF
>    ENDIF
>    RETURN lnresult
>  ENDFUNC
>ENDDEFINE
Let me know if this works and, if so, on what type of network.
Elyse Pomerantz
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform