We help IT Professionals succeed at work.

All users Desktop

Andy Brown
Andy Brown asked
on
Through VBA, I am trying to reliably ascertain the Desktop folder location for all users(XP, Vista, Win7).  I have a feeling that it can be done using the "Environ" function, but I could do with some guidance - as this has to be spot on.

We are creating a shortcut, which needs to reside on the Desktop of each PC for All users.

Any ideas?
Comment
Watch Question

Most Valuable Expert 2012
Top Expert 2013
Commented:
Does this do what you need?

Function foo()
    Dim  objWS As Object
    Set = CreateObject("WScript.Shell")

    Debug.Print objWS.SpecialFolders("Desktop")
    set objWS = nothing
End Function

Open in new window

Andy BrownDeveloper

Author

Commented:
Perfect - I assume this will work across the three versions of Windows (I've only tried it on Win7 32bit)
Most Valuable Expert 2012
Top Expert 2013

Commented:
If that doesn't work, try replacing "Desktop" with "AllUsersDesktop":

Function foo()
    Dim  objWS As Object
    Set = CreateObject("WScript.Shell")

    Debug.Print objWS.SpecialFolders("AllUsersDesktop")
    set objWS = nothing
End Function 

Open in new window

Since NT there's been the HOMEDRIVE and HOMEPATH environment variables.
http://support.microsoft.com/kb/100843
Those environment variables are certainly set on our XP and Vista and Win 7 machines.
So the desktop folder should be %HOMEDRIVE%\HOMEPATH%\Desktop
Most Valuable Expert 2012
Top Expert 2013

Commented:
<<I assume this will work across the three versions of Windows >>

allUsersDesktop seems to do what you need for Windows XP.

There is no distinction in Windows 7 from what I can tell.

(I haven't tried Vista)