[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Copying files to a runtime defined folder

Posted on 2004-04-02
4
Medium Priority
?
333 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

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…
Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

656 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