Solved

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

Posted on 2008-10-02
2
745 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 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

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…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month7 days, 9 hours left to enroll

632 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