I have a desktop Windows application that is installed in small office environments.
The application uses an .MDB database file as its database which is stored on a network drive.
Configuration files specify the path of the .MDB file on the server using a letter drive: eg. f:\data\db.mdb
The application needs to access this database file when it starts. How can I ensure the network drive is connected and accessible when the application starts?
Sometimes Windows doesn't reconnect network drives and the only way to connect them is to double-click on them in My Computer, even when "Reconnect at logon" is ticked when mapping the drive.
Would a solution be to use \\machine_name\share instead of drive letters?
You asked, "Would a solution be to use \machine_name\share instead of drive letters?"
I think, yes, it could be. A UNC path avoids 2 problems:
share not connected to a drive letter
share is connected, but mapped to a different drive letter than you expect
The unknown is whether anything in your application makes a UNC path for the MDB either a complication or a flat out deal-breaker.
You should use UNC paths, because not everyone will have your drive mapped to the same letter.
Determine UNC path
First, I would determine the UNC path of your file as it exists on your local computer at F:\data\db.mdb using one of the techniques found here:
Creating UNC paths from mapped drives
Basically, you look at the way Windows Explorer lists the network mapped drive, then use this to deduce the UNC path.
Check Availability using WMI
Assuming the drive is actually mapped on every local computer that plans to use the application, use the Win32_MappedLogicalDisk class to determine availability of the mapped network drive.
I have some sample code here that can be adapted to determine whether a given network drive is available (scroll down to the Mapped Drives Information section). You check .ProviderName to match the UNC path, so you know which is the correct drive, then check the value of .Availability to determine if the mapped network drive can be accessed.
You should definitely abandon the network drive mapping possibilities:
using this technique forces you to manipulate 'physically' each computer using your db, where you have to assign a letter to the network drive.
every computer user can easily change it
any disconnection from the network might force the user to 'manually' reconnect to the disk drive
Though you are on a domain, I would not advise you to use a name, as computers, for multiple reasons, might not always find it 'easily' on the network, specially when its IP is regularly changed.
You should definitely find a way to assign a fixed IP to your disk: it is the most stable and permanent solution you can think about. Ask your domain administrator to arrange it for you.
Testing the presence of your network disk can then be done very easily. There are multiple solutions, including trying to open directly the mdb file. You could also test the existence of the file (through the file object I think) or even use any external program or windows API that you could launch from your code. Please google 'VB test IP' or something similar to find a solution at your convenience.
EDIT: windows has even a proposal to simulate a ping with some VB code. Check it here
EDIT2: I found in one of my apps this VBA code, which allows to quick-check if a file exists (and can ba accessed) somewhere on your network. It was basically set to test if a new version of the user interface is available.
Function fileIsAvailable(x_nom As Variant) As Boolean
On Error GoTo ERREUR
Application.Screen.MousePointer = 11
Dim fso as object
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(x_nom) Then
fileIsAvailable = False
Else
fileIsAvailable = True
End If
Set fso = Nothing
Application.Screen.MousePointer = 0
On Error GoTo 0
Exit Function
ERREUR:
Application.Screen.MousePointer = 0
debug.print Err.Number, Err.description
End Function
You can easily call this function by supplying your file's network name, such as:
if fileIsAvailable("\\192.168.1.110\myFileName.mdb") then ...
You did not make it clear what your application was written in, however before you attempt to connect to the database for the first time, presumably in a splash screen or something of that nature, check that f:\data\db.mdb
exists.
Make sure this script is ran right before the application is started:
net use f: \\machine_name\share /user:[username] [password] /persistent:yes
This will map the share drive on the letter you specified !
Related
Is it possible to attach an FS filter driver on a mapped network drive?
I'm really new to this filter driver work and currently testing a demo version of an SDK. It works fine on my local drive and I was able monitor and even deny file creation. But it doesn't seem to work on a mapped network drive.
So my question is: Is it even possible to do that?
Of course.
You simply need to check in you instance attach if your filesystem type is a network filesystem.
Read more here, especially the VolumeDeviceType and VolumeFilesystemType parameters.
Good luck,
Gabriel
I have a windows service that I built in C#. The purpose of the Windows Service is to synchronize two folders (Folder-A & Folder-B) between different servers using File System Watcher. Everything worked fine up until I moved Folder-A & Folder-B from the C drive to the D Drive. Now I can't map the folders and on the event log I get the "The local device name has a remembered connection to another network resource" error.
Also, the folders are shared and the credentials I use have full control rights to both folders.
Hi I finally fixed my issue all I had to do on my C# code I had to force the mapping of my shared folder. Its weird because the first time I used the service for the first time I didn't for it to map. But after changing the Shared folder to a different drive that's when i had this issue.
Below is the C# code to force the mapping.
oNetDrive.Force = true;
oNetDrive.Persistent = true;
oNetDrive drive is the Shared folder. Force and Persistent are the properties.
I have to write a script on Lotus Server which is on Windows server to save a csv file on UNIX server. I and Unix server path requires authentication. So can somebody help me or suggest me how to do it?
Thanks in advance.
Siddhartha
Could setting up a FTP server on Domino and accessing this from your UNIX server be an option ?
Mindoo FTP server
I once resolved this in two steps:
1. Save the file to a temporary directory on the D omino server using LotusScript
2. Create a scheduled taks on the windowd serverr to copy the file to the second server
Advantages:
You can specify any user in the scheduled task and you don`t have to care about accessibility of the other server.
Disadvantages
Two separate processes.
Hope that helos.
Michael
In my scenario which was very similar to yours, I did the following:
On the Windows Server, I created a Mapped Drive to the folder on the Unix OS. This also managed the Authentication.
In the LotusScript Agent, I extracted to this Mapped Drive, which worked 100%.
You need to provide more details. Presuming you can access the Unix folder from Windows Explorer, map the drive and let Windows store the password. Then access it through the mapped drive letter.
LotusScript can't write to UNC locations, so you need the drive letter.
That file will be probably picked up by another program. CVS is the worst approach. You could offer to write to a Web Service or provide one.
Update
On Unix "access" more often than not doesn't mean a CIFS (a.k.a Windows share) access, but SSH (or FTP). For SSH you would want to:
configure SSH Keys, so you actually don't need username/password any more
use a Java library as asked on Stackoverflow before (or an alternative)
you also could write the file to a temp directory and call a cmd file for the copy operation
With a little care (make the cmd file configurable) the stuff will work when moving your Domino to Unix/Linux too
Let us know how it goes
For an application I'm writing, i want to programatically find out what computer on the network a file came from. How can I best accomplish this?
Do I need to monitor network transactions or is this data stored somewhere in Windows?
When a file is copied to the local system Windows does not keep any record of where it was copied. So unless the application that created it saved such information in the file then it will be lost.
With file auditing file and directory operations can be tracked, but I don't think that will include the source path with file copies (just who created it and when).
Yes, it seems like you would either need to detect the file transfer based on interception of network traffic, or if you have the ability to alter the file in some way, use public key cryptography to sign files using a machine-specific key before they are transferred.
Create a service on either the destination computer, or on the file hosting computers which will add records to an Alternate Data Stream attached to each file, much the way that Windows handles ZoneInfo for files downloaded from the internet.
You can have a background process on machine A which "tags" each file as having been tagged by machine A on such-and-such a date and time. Then when machine B downloads the file, assuming we are using NTFS filesystems, it can see the tag from A. Or, if you can't have a process at the server, you can use NTFS streams on the "client" side via packet sniffing methods as others have described. The bonus here is that future file-copies will retain the data as long as it is between NTFS systems.
Alternative: create a requirement that all file transfers must be done through a Web portal (as opposed to network drag-and-drop). Built in logging. Or other type of file retrieval proxy. Do you have control over procedures such as this?
I have a Windows service developed in VB.NET. This Windows service picks a file every night at 8 PM from copies a file from my C:\ftpDocs to Y:\FtpDocs folder.
Y: is a mapped drive which is \\sourceServer\Output files. When I run the same code from a VB.NET Windows application instead of a Windows service it is working absolutely fine. But from the service it is throwing access denied error accessing \\sourceServer\Output.
It seems the Windows service runs from C:\windows\system32. For this reason I tried changing the current directory to C:\ftpService (This is the folder where my application is).
To access the mapped drive I provide a userid and password which is not my Windows userid and password. Do you think this is the reason why it is not able to access it from the Windows service?
If yes, how is it working from Windows application? This issue is not going away for the past one month now.
What drives are currently mapped is maintained per user -- it'd be a big no-no for me to be able to access files on a share on which you have credentials just because we're both logged on at the same time.
Your service will need to map the share itself using saved credentials of some kind (you could hard code them, if you like, though that's not terribly secure and represents a maintainability burden besides). A good example of how to do this is here -- though, I haven't used this code, I've just read the article.
Typically a Windows service runs under an id whose credentials are not authorized to access files on the network. Try running your windows service under the domain account which can access the network files. Make sure that this account has access to both the network and local folders/files that it will be reading and writing.
Also, you'll want to use the UNC path, not a mapped drive. The mapped drive won't be mounted for the service.