Hello,
I am trying to open/read file located in network using lotusscript or java. Please suggest what user should have access right on the folder in which file is located.
Please suggest how to access it.
Thanks
Hello,
I am trying to open/read file located in network using lotusscript or java. Please suggest what user should have access right on the folder in which file is located.
Please suggest how to access it.
Thanks
Subject: Open Network file using lotusscript
hiUse the following code to open the network
‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’
Call ConnectToNetwork(drivNam)
PathName=drivNam &"\" &Today &"file.xml"
If Dir(PathName , 2)<>"" Then
Kill PathName
End If
‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’
Function ConnectToNetwork(drivNam As String) As Integer
Dim pathNam As String
Dim Filepath As String
Dim IsNotConnected As String
Dim BodyText As String
Dim Isok As Boolean
Isok=False
'Forbind til drevet
IsNotConnected= Win32ConnectDrive$(SYS_pathNam,drivNam)
If IsNotConnected="" Then
ConnectToNetwork=Isok
BodyText= "network not connected"
Exit Function
End If
Isok=True
ConnectToNetwork=Isok
End Function
Public Function Win32ConnectDrive$(Byval pathNam$,drivNam As String)
Win32ConnectDrive = ""
On Error Goto Errors
Const FUNC_NAME = "Win32ConnectDrive"
Dim netRes As WIN32_NETRESOURCE
Dim retCode&, ascLett&
’ drivNam$
Dim fst&, sec&, mach$, shar$, pth$, tmp$
drivNam = ""
If Instr(pathNam, "\\") = 0 Then Goto TheEnd
'----- Try to find a drive that isn’t being used
For ascLett = 90 To 68 Step -1
tmp = Chr$(ascLett) & ":"
If Not(IsDriveAvailable(tmp)) Then
drivNam = tmp
Exit For
End If
Next ascLett
If drivNam = "" Then Goto TheEnd
'----- Explode the pieces of the UNC name
pathNam = Mid$(pathNam, 3) 'remove first 2 slashes
fst = Instr(pathNam, "\") 'first slash "\"
mach = Left$(pathNam, fst-1) 'machine name
sec = Instr(fst+1, pathNam, "\") 'second slash "\"
If (sec <> 0) Then
shar = Mid$(pathNam, fst+1, Instr(fst+1, pathNam,"\")-(fst+1)) 'share name
Else
shar = Mid$(pathNam, fst+1)
End If
tmp = "\\" & mach & "\" & shar
pth = Mid$(pathNam, Len(tmp))
pathNam = tmp
'----- Fill out the relevant info in the resource structure
netRes.dwType = RESOURCETYPE_DISK
netRes.lpLocalName = drivNam
netRes.lpRemoteName = pathNam
'----- Make the necessary call to map the drive
retCode = WNetAddConnection2(netRes, SYS_PASSWORD, SYS_USERNAME, 0)
If (retCode <> NO_ERROR) Then
tmp = Win32GetErrorString(retCode)
Print FUNC_NAME & ": " & tmp & "(" & Trim$(Str(retCode)) & ")"
Exit Function
End If
'----- Return the new full path
Win32ConnectDrive = drivNam & "\" & pth
TheEnd:
Exit Function
Errors:
Win32ConnectDrive = ""
Print FUNC_NAME & ": " & Error$
Resume TheEnd
End Function
Function IsDriveAvailable(drivNam$) As Variant
On Error Goto Errors
IsDriveAvailable = False
If Dir$(drivNam, 8) <> "" Then
IsDriveAvailable = True
End If
TheEnd:
Exit Function
Errors:
Resume TheEnd
End Function
Function Win32GetErrorString$(retCode&)
Dim tmp$
Select Case(retCode)
Case NO_ERROR:
tmp = "No error"
Case ERROR_ACCESS_DENIED:
tmp = "Access to resource was denied"
Case ERROR_ALREADY_ASSIGNED:
tmp = "Resource already assigned"
Case ERROR_INVALID_PASSWORD:
tmp = "Specified password is invalid"
Case ERROR_BAD_DEV_TYPE:
tmp = "Type of local device and the type of network resourcedo not match"
Case ERROR_BAD_NET_NAME:tmp = "The resource name is invalid, or the named resourcecannot be located"
Case ERROR_BUSY:
tmp = "The router or provider is busy, possibly initializing"
Case ERROR_BAD_DEVICE:
tmp = "The local name is invalid"
Case ERROR_DEVICE_ALREADY_REMEMBERED:tmp = "An entry for the specified device is already in the user profile"
Case ERROR_NO_NET_OR_BAD_PATH:tmp = "A network component has not started, or the specified name could not be handled"
Case ERROR_BAD_PROVIDER:
tmp = "The provider value is invalid"
Case ERROR_CANNOT_OPEN_PROFILE: tmp = "Unable to open the user profile to process persistent connections"
Case ERROR_BAD_PROFILE:
tmp = "The user profile is in an incorrect format"
Case ERROR_EXTENDED_ERROR:
tmp = "A network specific error occurred"
Case ERROR_NO_NETWORK:
tmp = "No network is present"
Case ERROR_CANCELLED:
tmp = "The action was cancelled"
Case Else:
tmp = "Error"
End Select
Win32GetErrorString = tmp
End Function
Sub DisconnectDrive(drivNam As String)
Call Win32DisconnectDrive(drivNam)
End Sub
FILE: EKLIB.LSS - Function Library
This library provides functions for mapping NT network drives using
Win 32 API (only tested on NT 4.0, Service Pack 3). These functions
are particularly useful for background agents that run on an NT
server where the Domino server is set up as a NT service using the Local
System account. In this case, the NT machine is not logged into any
domain
and no drives are mapped. UNC names do not work in this situation
either.
To use these Functions, add the following line to the Declarations
section
of your script module:
%INCLUDE “FILEPATH\EKWIN32.LSS”
where FILEPATH refers to a fully qualified file path. The contents of
this
file will be inserted at compile time (when the script is saved), so if
you make changes to it, you’re going to have to re-compile the modules
that use this file for the changes to be reflected. Alternatively,
this
file can be imported into a Script Library (in Notes R4.5 or higher),
in
which case changes will be felt as soon as they are made…
%ENDREM
'----- File that contains SYS_USERNAME and SYS_PASSWORD constants for
'login
'%INCLUDE “C:\LOGIN.LSS”
'%INCLUDE “C:\EKWIN32.LSS”
'Const SYS_pathNam=“\127.17.76.50\folderbane”
Const SYS_USERNAME = “username”
Const SYS_PASSWORD = “password”
'----- DLL containing the needed Win32 functions
Public Const WIN32_DLL = “mpr.dll”
'----- Flags
Public Const RESOURCETYPE_ANY = &H00000000
Public Const RESOURCETYPE_DISK = &H00000001
Public Const RESOURCETYPE_PRINT = &H00000002
Public Const CONNECT_UPDATE_PROFILE = &H00000001
'----- Network resource structure
Public Type WIN32_NETRESOURCE
dwScope As Long
dwType As Long '<< Any/disk/print
dwDisplayType As Long
dwUsage As Long
lpLocalName As String '<< Local drive name to use
lpRemoteName As String '<< Remote path
lpComment As String
lpProvider As String
End Type
'----- Win 32 API function(s)
Declare Function WNetCancelConnection& Lib WIN32_DLL Alias"WNetCancelConnectionA" (Byval lpName As String, Byval fForce As Long) 'Force the disconnect
Declare Function WNetAddConnection2& Lib WIN32_DLL Alias"WNetAddConnection2A" (lpNetResource As WIN32_NETRESOURCE,Byval lpPassword As String,Byval lpUserName As String, Byval dwFlags As Long) 'Flags
'----- Error codes from error.h
Public Const NO_ERROR = 0
Public Const ERROR_ACCESS_DENIED = 5
Public Const ERROR_ALREADY_ASSIGNED = 85
Public Const ERROR_INVALID_PASSWORD = 86
'----- Error codes from winerror.h
Public Const ERROR_BAD_DEV_TYPE = 66
Public Const ERROR_BAD_NET_NAME = 67
Public Const ERROR_BUSY = 170
Public Const ERROR_BAD_DEVICE = 1200
Public Const ERROR_DEVICE_ALREADY_REMEMBERED = 1202
Public Const ERROR_NO_NET_OR_BAD_PATH = 1203
Public Const ERROR_BAD_PROVIDER = 1204
Public Const ERROR_CANNOT_OPEN_PROFILE = 1205
Public Const ERROR_BAD_PROFILE = 1206
Public Const ERROR_EXTENDED_ERROR = 1208
Public Const ERROR_NO_NETWORK = 1222
Public Const ERROR_CANCELLED = 1223
Public Const ERROR_NOT_CONNECTED = 2250
Public Const ERROR_DEVICE_IN_USE = 2404
Dim retCode&, ascLett&, drivNam$, tmp$
Const FUNC_NAME = “Win32DisconnectDrive”
Subject: RE: Open Network file using lotusscript
Thanks for you response.
Can you also suggest that how this can be done with java code.
Thanks again.