Unexpected behavior of WScript.Shell SpecialFolders function

saj

New member
Local time
Yesterday, 22:19
Joined
Feb 10, 2011
Messages
3
Hi all, I just had a quick question regarding the functionality of the SpecialFolders function of WScript.Shell.

In my code I have the pretty standard lines:

Set objWSHShell = CreateObject("WScript.Shell")
SpecialFolderPath = objWSHShell.SpecialFolders(strFolder)

Where strFolder is going to be "Desktop". What I'm expecting is a path to: "C:\Users\Steve\Desktop" but what I'm getting is a path to "C:\Users\Public\Desktop".

Just wondering if this is actually supposed to be the expected behavior and if I just misunderstood the purpose of the function or if something else is occurring. Could this be a case of some environment variables not properly set up? For what it's worth noting I'm running Windows 7.

Any help would be greatly appreciated.

Also a note, I was doing a look around the forums and noticed a different approach to the same problem posted by odin1701 (access-programmers.co.uk/forums/showpost.php?p=628457&postcount=2) where he does the following:

strUserName = Environ("UserName")
strPath = "C:\documents and settings\" & strUserName & "\Desktop"

So worse comes to worst I'll fall back on a similar solution, but I'd still like to know what's going on with this function.
 
On XP that returns "C:\Documents and Settings\<username>\Desktop"
 
All,

I know this is an old thread, but I am also getting unexpected behavior.

If I use CreateObject("WScript.Shell").SpecialFolders("mydocuments"), everything works fine. However, if I attempt to assign "mydocuments" to the string variable strFolderName, and then use CreateObject("Wscript.Shell").SpecialFolders(strFolderName), I'm getting users\public\desktop. Doing further testing, I noticed that if you assign a random string of characters ("Why42", for example) to strFolderName, it returns the same result (public\desktop), however if you use the string literal "Why42" it seems to return a null string.

Has anyone else observed this kind of behavior?
 

Users who are viewing this thread

Back
Top Bottom