Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

create a folder in my documents via VBS without knowing the users name

Posted on 2008-10-02
2
Medium Priority
?
755 Views
Last Modified: 2010-04-21
I want to create a folder in My Documents on another persons computer via a vbscript.  I want to have a bat file open the VBS file after the user clicks on it and run the script.  How do I get this to occur in the users My Documents folder without knowing who the current user is?
0
Comment
Question by:Dier02
[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 Comments
 
LVL 22

Accepted Solution

by:
Paka earned 2000 total points
ID: 22623103
Save the code below to a file named newfolder.vbs.  (Change the line that has "\NewDirectory" to the directory name you would like to create.)

Call newfolder.vbs from your batch like this:
cscript newfolder.vbs


Set objWshShell = WScript.CreateObject("WScript.Shell")
strUserProfile = objWshShell.Environment("PROCESS")("UserProfile")
 
strNewDirectory = strUserProfile + "\NewDirectory" 
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
on error resume next
Set objFolder = objFSO.CreateFolder(strNewDirectory)
on error goto 0
 
WScript.Quit 

Open in new window

0
 

Author Closing Comment

by:Dier02
ID: 31502331
Great work - thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…
Suggested Courses

670 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