Solved

VBScript - profile path

Posted on 2006-11-14
5
1,676 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA color chart bars 12 86
Windows 10 start screen issues 9 55
Looking for VB6 code to read SQL table export it to ascii 8 38
How to Add / Edit Windows Menu 4 61
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

810 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