API Programming in ASP

Results 1 to 2 of 2

Thread: API Programming in ASP

  1. #1
    Join Date
    Dec 1969

    Default API Programming in ASP

    I am trying to use an API called "NetFileEnum" in "netapi32.dll" in order to develope an application to let the use select a file from within our LAN and then when he clicks on a button this API will response.write the the Names of the Users who currently open the specified file. So if you have any other new way to do this or do you know any asp objects that I can get to help me reading opened files and network resources Information, this will be great. Anyhow here is the code in a VB standard project for the specified API:<BR><BR>Private Const PERM_FILE_READ As Integer = 1<BR> Private Const PERM_FILE_WRITE As Integer = 2<BR> Private Const PERM_FILE_CREATE As Integer = 4<BR> <BR> Private Const NERR_Success As Long = 0<BR> <BR> Private Const ERROR_MORE_DATA As Long = 234<BR> <BR> Private Type FILE_INFO_3<BR> fi3_id As Long<BR> fi3_permissions As Long<BR> fi3_num_locks As Long<BR> fi3_pathname As Long<BR> fi3_username As Long<BR> End Type<BR> <BR> Private Declare Function NetFileEnumNT Lib "netapi32.dll" Alias "NetFileEnum" _<BR> (ByRef lServer As Long, ByRef lBasePath As Long, ByRef lUserName As Long, _<BR> ByVal lLevel As Long, ByRef btBuffer As Any, ByVal lPrefBufferSize As Long, _<BR> ByRef lEntriesRead As Long, ByRef lTotalEntries As Long, ByRef hResume As Long) As Long<BR> <BR> Private Declare Function NetAPIBufferFree Lib "netapi32" Alias "NetApiBufferFree" _<BR> (ByVal lpBuffer As Long) As Long<BR> <BR> Private Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" (hpvDest As Any, _<BR> hpvSource As Any, ByVal cbCopy As Long)<BR> <BR> Private Declare Function lstrcpyW Lib "kernel32.dll" (ByRef strDest As String, ByRef strSource As Long) As Long<BR> <BR> Private Declare Function NetFileClose Lib "netapi32.dll" (ByRef lServer As Long, ByVal lID As Long) As Long<BR><BR> Private Function PermToDesc(ByVal lIn As Long) As String<BR> If (lIn And PERM_FILE_READ) = PERM_FILE_READ Then PermToDesc = PermToDesc & "reading "<BR> If (lIn And PERM_FILE_WRITE) = PERM_FILE_WRITE Then PermToDesc = PermToDesc & "writing "<BR> If (lIn And PERM_FILE_CREATE) = PERM_FILE_CREATE Then PermToDesc = PermToDesc & "creating "<BR> If Len(PermToDesc) = 0 Then PermToDesc = lIn<BR> End Function<BR> <BR> <BR> Function Ptr2StrW(ByRef lIn As Long) As String<BR> Dim lRet As Long, i As Long<BR> Dim strRet As String, strTemp As String<BR> <BR> strRet = String(256, Chr$(0))<BR> lRet = lstrcpyW(ByVal strRet, ByVal lIn)<BR> strTemp = StrConv(strRet, vbFromUnicode)<BR> i = InStr(1, strTemp, Chr$(0))<BR> If i &#062; 0 Then<BR> Ptr2StrW = Left$(strTemp, i - 1)<BR> Else<BR> Ptr2StrW = strTemp<BR> End If<BR> End Function<BR><BR>Private Sub ListOpenFilesNT(ByVal strServer As String, ByVal strBasePath As String)<BR> Dim lLevel As Long, fi3 As FILE_INFO_3, lRet As Long<BR> Dim lEntriesRead As Long, lTotalEntries As Long, lPrefBufferSize As Long<BR> Dim hResume As Long, lBuffer As Long, strUser As String, strPath As String<BR> <BR> lLevel = 3<BR> lTotalEntries = 2<BR> lPrefBufferSize = 1000<BR> Do<BR> lRet = NetFileEnumNT(ByVal 0&, ByVal 0&, ByVal 0&, lLevel, lBuffer, lPrefBufferSize, _<BR> lEntriesRead, lTotalEntries, hResume)<BR> If lRet &#060;&#062; NERR_Success And lRet &#060;&#062; ERROR_MORE_DATA Then<BR> NetAPIBufferFree lBuffer<BR> Debug.Print "Error " & lRet<BR> Exit Do<BR> Else<BR> Do While lEntriesRead &#062; 0<BR> CopyMemory fi3, ByVal lBuffer, Len(fi3)<BR> strPath = Ptr2StrW(fi3.fi3_pathname)<BR> strUser = Ptr2StrW(fi3.fi3_username)<BR> Debug.Print "File """ & strPath & """ opened by """ & strUser & """ for " & PermToDesc(fi3.fi3_permissions)<BR> lBuffer = lBuffer + Len(fi3)<BR> lEntriesRead = lEntriesRead - 1<BR> NetFileClose ByVal 0&, fi3.fi3_id<BR> Loop<BR> NetAPIBufferFree lBuffer<BR> End If<BR> Loop While lTotalEntries &#062; lEntriesRead<BR> End Sub<BR> <BR><BR>Private Sub Command1_Click()<BR>ListOpenFilesNT "\servername should go here", "File Path Name Shoud go here"<BR>End Sub<BR><BR>This code is not getting any errors but it does now get any result at all, if you could see anything wrong in this code, please tell me. I know this is some how advanced piece but this the way the developers&#039; life goes.<BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default Just a suggestion, however you might

    try to see if you can do this using WMI(Windows Management Instrumentation). The nice thing about WMI is you can use it via scripting without having to do all this separate coding in VB.<BR><BR>Again I&#039;m not sure if its possible, however its worth taking a look thru the WMI SDK:<BR><BR>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_start_page.asp<BR><BR>Also, here is a great article right here on 4Guys to get you started:<BR>http://www.4guysfromrolla.com/webtech/082802-1.shtml<BR><BR>Good luck<BR>Pete

Posting Permissions

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