Netware API

TKnight

Registered User.
Local time
Today, 14:35
Joined
Jan 28, 2003
Messages
181
Hi,

I really need to get the Novell Netware File Owner property because the way our network is set-up is that the windows file owner always says "Admin" or "Everyone" (which isn't very helpful!).

I've searched everywhere online and although there are a few mentions of the Netware APIs for VBA I can't find exactly what i'm looking for. Has anyone managed to do this? If so, a function would be amazing, and if not, anything that would get me connected to the right API would be great and I should be able to take it from there.

Thanks,

Tom
 
try a new module;


Option Compare Database

Option Explicit
'declare NetWare APIs
Private Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" _
(ByVal lpszNetPath As String, _
ByVal lpszPassword As String, _
ByVal lpszLocalName As String) As Long
Private Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" _
(ByVal lpszName As String, _
ByVal bForce As Long) As Long

'declare NT APIs
Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" _
(lpNetResource As NETRESOURCE, _
ByVal lpPassword As String, _
ByVal lpUserName As String, _
ByVal dwFlags As Long) As Long

Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" _
(ByVal lpName As String, _
ByVal dwFlags As Long, _
ByVal fForce As Long) As Long

'NetWare Vars
Const NW_Success = &H0
Const NW_Not_Supported = &H1
Const NW_Net_Error = &H2
Const NW_Bad_Pointer = &H4
Const NW_Bad_NetName = &H32
Const NW_Bad_Password = &H6
Const NW_Bad_Localname = &H33
Const NW_Access_Denied = &H7
Const NW_Out_Of_Memory = &HB
Const NW_Already_Connected = &H34
Private Const ERROR_NO_CONNECTION = 8
Private Const ERROR_NO_DISCONNECT = 9
Private Type NETRESOURCE
dwScope As Long
dwType As Long
dwDisplayType As Long
dwUsage As Long
lpLocalName As String
lpRemoteName As String
lpComment As String
lpProvider As String
End Type

'NT Vars
Const NO_ERROR = 0
Const CONNECT_UPDATE_PROFILE = &H1
Const RESOURCETYPE_DISK = &H1
Const RESOURCETYPE_PRINT = &H2
Const RESOURCETYPE_ANY = &H0
Const RESOURCE_CONNECTED = &H1
Const RESOURCE_REMEMBERED = &H3
Const RESOURCE_GLOBALNET = &H2
Const RESOURCEDISPLAYTYPE_DOMAIN = &H1
Const RESOURCEDISPLAYTYPE_GENERIC = &H0
Const RESOURCEDISPLAYTYPE_SERVER = &H2
Const RESOURCEDISPLAYTYPE_SHARE = &H3
Const RESOURCEUSAGE_CONNECTABLE = &H1
Const RESOURCEUSAGE_CONTAINER = &H2

Dim RC As Long
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''
'' Sub to Disconnect mapped drive
''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''
'' Error Codes:
'' 2250 - not disconnected for (some reason)
''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function Disconnect(Drive As String) As Long
'attempt to disconnect NT type connection
Disconnect = WNetCancelConnection2(Drive, CONNECT_UPDATE_PROFILE, False)

'if not worked, attempt to disconnect NetWare type connection
If Disconnect <> 0 Then _
Disconnect = WNetCancelConnection(Drive + Chr(0), 0)
End Function

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Sub to Map network drive
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
' Error Codes:
' 0 - Connected
' 67 - bad UNC
' 85 - not connected due to existing connection on specified drive letter
' 1202 - attempt to connect NT on existing NW mapping OR
' - attempt to connect NW on existing NT mapping
' 1219 - server valid, path invalid
' 1326 - invalid username/password OR attempt to connect NT with NW code
' 2202 - ?
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function Connect(Drive As String, UNC As String) As Long
Dim Disconnected As Long
Dim Answer

Dim NetR As NETRESOURCE 'for mapping
NetR.dwScope = RESOURCE_GLOBALNET
NetR.dwType = RESOURCETYPE_DISK
NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE
NetR.lpLocalName = Drive
NetR.lpRemoteName = UNC
ConnectNW:
'attempt Netware type connection
Connect = WNetAddConnection(UNC & Chr(0), "" & Chr(0), Drive & Chr(0))
If Connect = 0 Then
Exit Function
ElseIf Connect = 85 Then
Disconnected = Disconnect(Drive)
If Disconnected = 0 Then GoTo ConnectNW
Answer = MsgBox("Could not map a drive to " & UNC & " due to the " & _
"drive letter already being in use." & vbLf & _
"Please disconnect the I: drive and try again", _
vbRetryCancel + vbCritical, "Error Attempting " & _
"to Connect to " & UNC)
If Answer = vbRetry Then GoTo ConnectNW

ElseIf Connect = 1202 Then
Disconnected = Disconnect(Drive)
If Disconnected = 0 Then GoTo ConnectNW
End If

ConnectNT:
'attempt NT type connection if Netware connection fails
Connect = WNetAddConnection2(NetR, "password", "user name", CONNECT_UPDATE_PROFILE)

If Connect = 0 Then
Exit Function
ElseIf Connect = 67 Then
MsgBox UNC & " is either invalid or unavailable!" & vbLf & vbLf & _
"Program execution may be affected by this situation", vbCritical, "" & _
"Error connecting to " & UNC
Exit Function

ElseIf Connect = 85 Then
Disconnected = Disconnect(Drive)
If Disconnected = 0 Then GoTo ConnectNT
Answer = MsgBox("Could not map a drive to " & UNC & " due to the " & _
"drive letter already being in use." & vbLf & _
"Please disconnect the I: drive and try again", _
vbRetryCancel + vbCritical, "Error Attempting " & _
"to Connect to " & UNC)
If Answer = vbRetry Then GoTo ConnectNT

ElseIf Connect = 1202 Then
Disconnected = Disconnect(Drive)
If Disconnected = 0 Then GoTo ConnectNT

ElseIf Connect = 1326 Then
Disconnected = Disconnect(Drive)
If Disconnected = 0 Then GoTo ConnectNT
Answer = MsgBox("Class NETUSE is hard coded to login as Administrator. " & _
"The error code returned indicates that the Username/" & _
"Password" & vbLf & "is incorrect. Most probable cause " & _
"is that the Administrator password has been changed", _
vbRetryCancel + vbCritical, "Error Attempting to " & _
"Connect to " & UNC)
If Answer = vbRetry Then GoTo ConnectNT

Else
Disconnected = Disconnect(Drive)
If Disconnected = 0 Then GoTo ConnectNT
MsgBox "A critical and Unknown error has occured while trying to attach " & _
"to " & UNC & vbLf & vbLf & "The Error Code was: " & _
Connect & vbLf & vbLf & "Program execution my be affected by " & _
"this situation", vbCritical
Exit Function

End If

End Function
 
Thanks for your help JPaulo but that code looks like it is more concerned with Network Connections rather than file properties. Let me elaborate a little...

Take a word doc on our network as an example. The Windows properties show the file owner as "S-1-1-0" (The same as every other file in the folder), and the file author as "Corporate ICT". I can access these properties by using shell and I have a function to do that, but the names are too generic to be of any use. If I right-click on the file and go to [Properties], under the [Netware Info] tab I can see that the owner is "tknight.bla.bla.bla". This is the property that I want to access because it actually gives the Novell username of the file owner which would be really useful in this case.

Can I access this property with the module you gave me? If so, would you be able to help me access it - I have no idea how to get started from there.

Thanks,

Tom
 
Unfortunately in Novell have tests to do.

Novell is more than out of date the Windows Server system is so good, that makes no sense to seek alternatives Novell or Lotus

may be that someone has to run Novell environment, which can help it.

Sorry
 
No Probs... thanks for your help.

Anyone else done this before?

Cheers,

Tom
 

Users who are viewing this thread

Back
Top Bottom