Copying files to a runtime defined folder

Posted on 2004-04-02
Last Modified: 2010-04-13

 I am trying to write a batch file, with a command text that will enable me to install the VbaProject.OTM Outlook Macro file in the right destination folder on the target PC.

 All I need to do to achieve this is:

1) Lockate where the existing VbaProject.OTM file is on the target machine, and retrieve that path (Usually that path is C:\Documents and Settings\Administrator\Application Data\Microsoft\Outlook\VbaProject.OTM

2) Replace the existing VbaProject.OTM with the new VbaProject.OTM using XCOPY command for example

 The problem is that the user intending to use the application is not neccesarly the 'Administartor', and sometimes MS Outllok is not installed on drive C:\, but for now let us suppose that MS Outlook is installed on drive C:\, and the only problem is to find out what the user name is, so we can place that user name in the path :
C:\Documents and Settings\[RETRIEVED USER NAME]\Application Data\Microsoft\Outlook\VbaProject.OTM
and copy the new VbaProject.OTM file to that folder ... to install the Outlook Macro.

 can you please advise me on how to retrieve the user name of the user running the batch file, store it in a variable [RETRIEVED USER NAME], and place it in hard coded path:
C:\Documents and Settings\[RETRIEVED USER NAME]\Application Data\Microsoft\Outlook\VbaProject.OTM
to copy the VbaProject.OTM  file to that path.

 So far this is the only batch command I have:

XCOPY C:\DA\VbaProject.OTM  C:\Documents and Settings\[RETRIEVED USER NAME]\Application Data\Microsoft\Outlook\VbaProject.OTM

Thank You

Question by:RaedKhlaifat
  • 2
  • 2

Accepted Solution

Chatable earned 500 total points
ID: 10746999
The username environment variable stores the current username in Win2K (/NT/XP/2003 etc.)
Try this:

C:\> echo %username%

However, there is an even better way to do the specific task you wish to preform, so it will also solve the problem of the drive in which the user profile is installed. Try this:

C:\> echo %userprofile%
C:\Documents and Settings\Administrator

So the EXACT command you need to type is:
XCOPY C:\DA\VbaProject.OTM "%userprofile%\Application Data\Microsoft\Outlook\VbaProject.OTM"
(The quotes are needed since the path contains whitespcaes).

To see all the other neat data stored in environment variables and available for use in batches type "set".
That's all. Hope it helped.


Author Comment

ID: 10747574
Thanks 'Chatable' that was beautifuly just right ...

 The dstination path works just the way I want it now, but I have a small question about the source path if you don't mind? I was wondering if there was a way of using a relative path to the batch file to lockate the VbaProject.OTM source file, rather than using a fixed path like C:\DA\VbaProject.OTM, because I am thinking of distributing the VbaProject.OTM and the batch file together in a folder called DA, but according to the current batch, the users will have to save the DA folder on thier C: Drive, to make the  C:\DA\VbaProject.OTM path correct.

 My question is: Is ther a way to make the path of source file, relative to the Batch file, no matter where the folder containing the file was saved?

Thank U Again



Expert Comment

ID: 10747770
Sure, a batch file usually runs from the location in which it was stored, so if simply use this:
xcopy DA\VbaProject.OTM "%userprofile%\Application Data\Microsoft\Outlook\VbaProject.OTM"
Then it should do the trick.

Author Comment

ID: 10747801
Thanks, that works just fine.

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
This tutorial shows how to create a greeting card by combining two image layers and a text layer on a PC using a free image editing app.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question