Solved

VBScript - profile path

Posted on 2006-11-14
5
1,674 Views
Last Modified: 2008-01-09
What is the best way to retrieve the current user's local profile path (documents and settings\username\...) in a script?
I'm working on a script to copy files to a folder in the user's profile.
0
Comment
Question by:artthegeek
  • 3
  • 2
5 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 17943389
This should do it - reference the shell's volatile environment...


Dim objEnv
Dim strProfile

Set WshShell = WScript.CreateObject("WScript.Shell")
Set objEnv = WshShell.Environment("Volatile")
strProfile=objEnv("HomeDrive") & objEnv("HomePath")

msgbox strProfile

set objEnv=Nothing
wscript.quit
0
 
LVL 3

Author Comment

by:artthegeek
ID: 17943413
This looks good -
do I need the  

set objEnv=Nothing
wscript.quit

?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17943432
set objEnv=Nothing
'supposedly' releases the memory used for that object (I suppose it's debatable - but good coding to terminate these objects to prevent potential memory leaks - although a small script like this shouldn't matter much).

wscript.quit
again, not 'really' necessary - more just standard coding practice so that you control when the script terminates.  It basically says - time to stop processing.
0
 
LVL 3

Author Comment

by:artthegeek
ID: 17943443
Great stuff - thank you.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 17943448
Happy to have helped. :^)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 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

16 Experts available now in Live!

Get 1:1 Help Now