Get Special Folders such as user's Application Data folder

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Get Special Folders such as user's Application Data folder

Post by Marcus Tettmar » Thu Feb 03, 2005 1:56 pm

This example retrieves the Application Data folder:


VBSTART
Function GetFolder(Folder)
Set WShell = CreateObject("WScript.Shell")
GetFolder = WShell.SpecialFolders(Folder)
Set WShell = Nothing
End Function
VBEND
//See following for list of available folder types:
//http://msdn.microsoft.com/library/en-us ... olders.asp
VBEval>GetFolder("AppData"),AppData
MessageModal>AppData


Other folder names include:

AllUsersDesktop
AllUsersStartMenu
AllUsersPrograms
AllUsersStartup
Desktop
Favorites
Fonts
MyDocuments
NetHood
PrintHood
Programs
Recent
SendTo
StartMenu
Startup
Templates

An alternative method for some paths is to use GetEnvVar:

GetEnvVar>APPDATA,result
GetEnvVar>USERPROFILE,result

Type SET in a command prompt to see the values available.

User avatar
Grovkillen
Automation Wizard
Posts: 1024
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Post by Grovkillen » Fri Aug 30, 2013 7:54 am

I know this is an old post but I have been using these commands on a recent script and like to add that it's possible to do this without VBScript.

Just use:

ExecuteFile>shell:%COMMAND%
Where "COMMAND" is anyone of the below:

Appdata
AllUsersPrograms
AllUsersStartup
Desktop
Favorites
Fonts
MyDocuments
NetHood
PrintHood
Programs
Recent
SendTo
StartMenu
Startup
Templates

Ok, so I've used this to get the Startup folder since my clients user names sometimes is got the domain name attached (.DOMAIN)... but my problem is that it's somewhat cumbersome to find the correct patch using this (I have to scan the open window...)

C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
could sometimes be
C:\Users\USERNAME.DOMAIN\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

I'd be happy if someone could help me with this (is it possible to collect the folder path some other way?)
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
Grovkillen
Automation Wizard
Posts: 1024
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Post by Grovkillen » Fri Aug 30, 2013 7:56 am

Ok, stupid me... Using the VBScript I could get these paths... sorry for the post!
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1354
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Post by Dorian (MJT support) » Sat Aug 31, 2013 12:03 am

Don't worry, Grovkillen. :D

Maybe this is a good place to post a list of system variables. I'd think a lot of these have been added since the original thread was created.

http://www.mjtnet.com/manual/index.html ... iables.htm

Probably the most important one of these is USERDOCUMENTS_DIR

Examples :
XLOpen>%USERDOCUMENTS_DIR%\mybook.xlsx,1,xlBook

ReadLn>%userdocuments_dir%\L and K\illegalchar.txt,1,char1

Let>inFolder=%USERDOCUMENTS_DIR%\Websites\
Let>outFolder=%USERDOCUMENTS_DIR%\Websites\new\

WriteLn>%USERDOCUMENTS_DIR%\L and K\url output.txt,result,Hello
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts