Solved

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

Posted on 2008-10-02
2
701 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
2 Comments
 
LVL 22

Accepted Solution

by:
Paka earned 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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

21 Experts available now in Live!

Get 1:1 Help Now