Solved

Copying files to a runtime defined folder

Posted on 2004-04-02
4
314 Views
Last Modified: 2010-04-13
Hi,

 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






0
Comment
Question by:RaedKhlaifat
  • 2
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
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%
Administrator

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.

0
 

Author Comment

by:RaedKhlaifat
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

 

0
 
LVL 7

Expert Comment

by:Chatable
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.
0
 

Author Comment

by:RaedKhlaifat
ID: 10747801
Thanks, that works just fine.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now