Solved

Copying files to a runtime defined folder

Posted on 2004-04-02
4
317 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

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…
With more and more people tethered to the internet, advertisers can reach you in new and creative ways. Push notifications on your smartphone, customized advertisements based on your previous searches, and email inboxes filled with promotional pitch…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

914 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

17 Experts available now in Live!

Get 1:1 Help Now