[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

How do you dynamically redirect a program to a directory (where it is can change)?

My first question on ExpertsExchange...

  I am looking for some ideas to get around an old problem.  I have an application that needs to be able to find files on one of our servers.  I need a quick way of implementing directory redirection so I can change the location on our servers and all of the outside computers will know to go to the new location without any user interaction.

  I had thought to try a folder redirections scheme, but I am not finding much on doing that for server files (normally just for my documents).

  I tried using a DNS redirect from a name to an IP address of a system with a shared directory name and could not get that to work.

  I thought this might be my first valid SOA need (although a minor one - GetFileStorageLocation... or something like that).  I am not too worried about the data being sent, I can encrypt it.  I am not even too worried about an outside entity getting their hands on the location since they would need access.

  I will award points to all who can give me a workable solution that meets my needs - with the bulk going to the one I wind up using.  Please show examples, or links to examples, in Delphi code (.NET or WIN32).
1 Solution
MerijnBSr. Software EngineerCommented:
what protocol is used to get these files?
Create a NTFS Reparse Point (http://msdn2.microsoft.com/en-us/library/aa365503.aspx) on the server. See http://www.microsoft.com/technet/sysinternals/FileAndDisk/Junction.mspx for a utility to do that like

junction.exe OldDir NewDir

OldDir will now point to NewDir transparently.
developmentguruAuthor Commented:
  I am using a VPN and authenticating on our network so I have accesss to the files.  I am using a TFileStream descendant to read the file (normal file access).

  I will check out the links, but do you know off hand if a NTFS parse point can redirect from, say, a virtual machine name?  Sort of like a DNS redirect?
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

No, not from a machine name, that would have to be a file system entry.
developmentguruAuthor Commented:
I guess I am looking for something along the lines of


If this is to be done at the OS level I would want a server (DNS like operation) to see the request for \\MyRedirect and reroute the rest of the path to another server and sub directory.

Of course if it is NOT handled at the OS level there are likely a number of options others have used.
developmentguruAuthor Commented:
Ok, I thought maybe I could get the ball rolling again...

  One possibility I can think of would be a simple HTTPS request.  This is encrypted and would allow me to transfer information from a server which can be redirected using a DNS entry.  This could be done with INDY components.

  One possibility would be to create a SOAP project.  Granted that it is not needed for this one thing, but it would leave me an open door for further requests later on.

  I should also mention that I am keeping a local copy of the file in question on the outside systems.  This is to allow me to get a new version (which will contain other forms of redirection - the primary redirection source).  The problem is updating this information in a way that can be redirected easily.  I have to think I am not the first to run into this problem... can anyone relate what they have done?
Why not introducing a DNS alias?
developmentguruAuthor Commented:
 The DNS alias will equate a name with an IP address.  Using the windows explorer, if you try to type in the name from the DNS entry, it will try to redirect you to a web site hosted at the IP address.  If you can show me how to set up windows to use the DNS alias to accomplish this I would love to see it.

  I have a DNS entry set up for our intranet if I type in \\intranet it shows the machine under the web client network.  If I just type in "intranet" then it displays the intranet web page on the right side (after changing the address line to http://intranet/).

  If I type in a machine name like "\\MyServer" then it goes to the server as listed under Microsoft Windows Network.  This is the type of activity I want, but from a pseudo name pointing to a redirected location.  Is there anything like a DNS redirect but for the windows file system?  There must be a Windows file system api that could handle such a network redirect...  If not, any other type of work around in Delphi code would be good as long as it accomplishes the task.
For the Explorer issue, there's  LANMAN's 'lmhosts' (http://support.microsoft.com/kb/102725)
developmentguruAuthor Commented:
I will check into that on Monday, thanks for the new idea jkr.  Have a good weekend experts :-)
developmentguruAuthor Commented:
jkr I have been unable to use the lmhosts file.  I added the following line     MyStuff           #PRE #DOM:workgroup

and tried to use the file browser to go to MyStuff.  It didn't work.  Can you give any examples?  I would love to find that I can use this.  If I can't I will split awarded points between the two best ideas and "roll my own".
developmentguruAuthor Commented:
Well, I was unable to verify the lmhosts functionality.  I will be creating an SOA service where I can request a value by name and use it to request my folder location.  This will give me the ability to update a database record and effectively reroute all of the outside systems to look for their files elsewhere.
Re-opened by Asker request.
Please see my comments at the request and respond here if you would like to add anything.


Experts Exchange Moderator

developmentguruAuthor Commented:
 I had a long round with CodeGear technical support and got instructions on how to create a simple web service to help me with this problem.  Here is the list of instructions I was sent.

Here's a pointer: ms-help://borland.bds5/devwin32/soapwritingserversthatsupportwebservices_xml.html .
After opening the IDE's help window, enter the above link.

The following steps are a bit lengthy, but it shows you what to do.

A way of creating what you need:

1. File, New, Other, Delphi Projects, Web Services, SOAP Server Application
2. Select Web App Debugger executable, and enter a class name.
3. Answer yes to the Create Interface for SOAP module prompt.
4a) In the Add New WebService dialog, enter the service name and identifier name, eg, GetDirectory.
4b) Uncheck generate comments, and check Generate sample methods, and click Ok.
5. In GetDirectoryIntf.pas, for the IGetDirectory interface, add function GetDirectory: string; stdcall; to the declaration and remove all the other echoXXX declarations.
You may want to remove all the other types, and class declarations in GetDirectoryIntf.pas as well, or comment them out.
6. In GetDirectoryImpl.pas, in the TGetDirectory class, delete all the other echoXXXX declarations.
While in the class, press Ctrl-Shift, and double click on the GetDirectory entry in the Code Complete window.
7. Delete all other TGetDirectory.echoXXXX implementation, and go back to within the TGetDirectory class, and press Ctrl-Shift-C.
8. In the implementation for TGetDirectory.GetDirectory, return your directory.
9. Compile your application. If you can't get it to compile, ensure that the Library path setting in Tools, Options, Environment Options, Delphi Options, Library - Win32 refers to Indy9 instead of Indy10, eg, $(BDS)\Lib\Indy9.
10. Run your web service application once.
11. Close the web service application.
11. From the IDE Tools menu, run Web App Debugger, and when it comes up, and gets started, click on the default URL. This brings up your Web Browser, which browses to a Registered Server page.
12. In your web browser, in the Registered Servers list, select your web service application, and click Go. Your web browser now shows a Service Info Page, with a WSDL url for your app.
13.  Back in the IDE, right click in the Project Manager, and select, Add New Project.
14. Select Delphi Projects, and VCL Forms application.
15. From the IDE menu, select File, New, Other...
16. Select Web Services under Delphi projects, then WSDL Importer, and click Ok.
17. Copy and paste the WSDL url in Step 12 into the WSDL Import Wizard's WSDL Source prompt for location of WSDL URL.
18. Activate your main form, and from the IDE menu, select  File, Uses, and select the only entry in it, and click Ok.
19. Drop a button onto your form.
20. Double click on the button to create a click handler.
21. Declare a variable LGetDirectory: IGetDirectory within the scope of the click handler, eg var
  LGetDirectory: IGetDirectory;
22. Code the following in the click handler:
  LGetDirectory := GetIGetDirectory();
23. Now, if you run the app, you should see a dialog box showing the directory string you have provided in Step 8.

Once you think it's satisfactory, you can follow the steps given in ms-help://borland.bds5/devwin32/wservertypesofwebserverapplications_xml.html to convert your Web App Debugger to an actual web service.
I had a problem getting to step 9 because the code completion would not work.  I found out later that this was due to my IDE being set to Indy9 instead of Indy10.  Later I had a problem getting the web app debugger to bring up the Registered Server Page as indicated in step 11.  This was the solution to get that portion working:

In your BDS\4.0\bin directory, there is an application named serverinfo.exe. Run it once and close it.
Then, redo the steps for the Web App Debugger.

  Now everything is working from the Web App Debugger, but I am having a hard time getting it deployed on IIS (I am no expert there).  I have a small library of books arriving on the subject today.

  Back to my original question... this will allow me to, in effect, ask the home office, "Where do I get my stuff" and get an answer.  This step will give me an easy point to redirect where "my stuff" is.

  I hope others will be able to use this, it took a bit of work to get CodeGear to show me how.
developmentguruAuthor Commented:
Sorry, my IDE was set to Indy 10 instead of Indy 9...

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now