LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to programmatically locate My Documents folder?

Hi Everyone,
 
I was wondering if anyone knows a method of programmatically locating the folder 'My Documents' no matter what user is logged into Windows...
 
I'm not sure how to get this path if the user login to windows changes, because then the path to the folder changes.  For instance, if DrXavier logged into windows his my documents folder would be located at C:\Documents and Settings\DrXavier\My Documents\, if Wolverine logged in C:\Documents and Settings\Wolverine\My Documents, or if Jean Grey C:\Documents and Settings\SuperHottie\My Documents.  You get the idea
 
Thanks,
 
Jonathan
0 Kudos
Message 1 of 14
(7,587 Views)
Would this work?
Environment.GetFolderPath(Environment.SpecialFolder.Personal).ToString();

0 Kudos
Message 2 of 14
(7,584 Views)
Ok, I had another programming language just in mind 🙂

You could write a .NET Assembly (Visual Studio Express is free available), paste this line into it and get the result from this method. You could then call this line from within LV (I think I read somewhere that there's a possibility to call .NET assemblies from within LV).

0 Kudos
Message 3 of 14
(7,570 Views)
That's the .NET method, which is the cleanest way to do it.

The old way to do it using the shell32 DLL is a mess: How to find My Documents path?

Another method is to check the registry key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Personal. You can do this with LabVIEW functions.
0 Kudos
Message 4 of 14
(7,563 Views)
Ok, since I've wanted to try that once for a long time, I just did it 🙂

The zip archive contains the source and the resulting dll (release directory) and a test VI.

Open the test VI, maybe you have to link the contructor node to the WinInfo dll which is located in the release directory, then start the VI and it should display the location.


Oh, besides: I think you need the .NET Runtime 2 installed for this to work.

0 Kudos
Message 5 of 14
(7,559 Views)
Oh pipped at the post!
 
Here is the registry method in LV8
 
David
Message 6 of 14
(7,560 Views)
Well, never let it be said that this forum isn't helpful! Smiley Happy
0 Kudos
Message 7 of 14
(7,552 Views)
@david: What does pipped mean?

0 Kudos
Message 8 of 14
(7,551 Views)
Maybe this is the wrong place to ask this, but I've been thinking about what happens to applications that rely on certain registry paths once Windows Vista will be out. Will these registry paths still be valid or will we have to update the applications?

Just a thought...

0 Kudos
Message 9 of 14
(7,545 Views)

@Thomas: In the UK "to be pipped at the post" an common expression to say that I came in a close second place in a race. It really comes from horse racing sport where one horse beats another horse by a narrow margin at the finishing post.

See http://idioms.thefreedictionary.com/be+pipped+at%2fto+the+post

David

0 Kudos
Message 10 of 14
(7,544 Views)