Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enable %UserProfile% for scripting with Folder Redirection?

Tags:

vbscript

I'm experimenting with Folder Redirection and after getting it set up, I quickly realized that any VBS scripts that have environmental variables such as %UserProfile% become unusable.

For example:

 C:\MD %UserProfile%\Desktop\Not_Created_On_Real_Desktop\

And

'Place to deposit excel output file
Depo=oShell.ExpandEnvironmentStrings("%userprofile%" & "\Desktop\Folder_This_User_Needs_Easy_Access_To\")
if not objfso.folderexists(Depo) then
objFSO.CreateFolder(Depo)
end if

These no longer work when using Folder Redirection. I'm hoping there is a work around for this because a lot of my existing scripts depend on this variable remaining valid. I've found that .NET is able to pull the redirected folder with:

Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)

I haven't had much luck find an equivalent for VBS though.

Any help is appreciated. Thanks!

like image 339
Kevin Denham Avatar asked Apr 01 '26 22:04

Kevin Denham


1 Answers

I think SpecialFolders is what you are looking for

Depo=oShell.SpecialFolders("Desktop") & "\Test"

It will return the location of the Desktop-folder also with Redirected Folders.

like image 165
lsmooth Avatar answered Apr 03 '26 16:04

lsmooth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!