?
Solved

Copying files to a runtime defined folder

Posted on 2004-04-02
4
Medium Priority
?
331 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
Chatable earned 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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…
What's worse than having your data encrypted by ransomware? Getting attacked by a so-called "wiper," which simply destroys the data and offers you no hope of ever seeing it again.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

741 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