How to get local computer My Document FULL path?

I use MFC Visual C++ 4.2. How to acquire full path of every computer My 
Document folder? So when my application ran, it will directly detect the new 
full path.

Thank you very much.
0
landon (165)
6/17/2008 12:51:01 AM
vc.mfc 33608 articles. 0 followers. Follow

8 Replies
532 Views

Similar Articles

[PageSpeed] 8

"Landon" <Landon@discussions.microsoft.com> wrote in message 
news:D378F204-D5FA-43AF-8CE7-21197C45571C@microsoft.com...
>I use MFC Visual C++ 4.2. How to acquire full path of every computer My
> Document folder? So when my application ran, it will directly detect the 
> new
> full path.
>

What do you mean by "Every Computer"? Are you looking to find My Documents 
folder on network?

--
Ajay

0
ajaykalra (6842)
6/17/2008 3:00:11 AM
No, I mean that my application will be installed on many PC and I need to 
look for the default My Documents path from that PC.

How?

0
landon (165)
6/17/2008 4:35:01 AM
"=?Utf-8?B?TGFuZG9u?=" :
<news:D378F204-D5FA-43AF-8CE7-21197C45571C@microsoft.com> 
mar, 17 jun 2008 00:51:01 GMT 

> I use MFC Visual C++ 4.2. How to acquire full path of every computer
> My Document folder? So when my application ran, it will directly
> detect the new full path.
> 
> Thank you very much.


Maybe is this what you searching,

CString ClassX::GetMyDocumentsFolder()
{
#define BUFSIZE 1024
	HKEY hKey;
	TCHAR szDocFolder[BUFSIZE];
	DWORD dwBufLen = BUFSIZE;
	LONG lRet;
							
	lRet = RegOpenKeyEx( HKEY_CURRENT_USER,
          _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\
User Shell Folders"),
			 0,
			 KEY_QUERY_VALUE,
			 &hKey );

	if( lRet == ERROR_SUCCESS )
	{
		lRet = RegQueryValueEx( hKey,
                                _T("Personal"),
                                NULL,
                                NULL,
                                (LPBYTE) szDocFolder,
                                &dwBufLen);

		if( (lRet == ERROR_SUCCESS) || (dwBufLen < BUFSIZE) )
		{
			RegCloseKey( hKey );
			
			CString string(szDocFolder);

			if( ExpandEnvStrings( string ) )
				return string;
		}
	}

    return CString();
}


BOOL ClassX::ExpandEnvStrings(CString &str)
{
	LPTSTR lpszSystemInfo = 0;  // pointer to system information string 
	TCHAR tchBuffer[BUFSIZE];   // buffer for string
	DWORD dwResult = 0;         // function return value

	memset((void*)tchBuffer, 0, sizeof(tchBuffer)/sizeof(tchBuffer[0]));
	
	lpszSystemInfo = tchBuffer; 

	dwResult = ExpandEnvironmentStrings( str, lpszSystemInfo, BUFSIZE);
	
	CString s;

	if( dwResult <= BUFSIZE )
	{
		s = lpszSystemInfo;
		str = s;
		return TRUE;
	}
	
	return FALSE;
}



// get MyDocuments Folder
    CString dir = GetMyDocumentsFolder(); 



Nivel.


** Posted from http://www.teranews.com **
0
6/17/2008 6:35:53 AM
"Landon" <Landon@discussions.microsoft.com> wrote in message 
news:D378F204-D5FA-43AF-8CE7-21197C45571C@microsoft.com...
>I use MFC Visual C++ 4.2. How to acquire full path of every computer My
> Document folder? So when my application ran, it will directly detect the 
> new
> full path.

SHGetFolderPath(NULL, CSIDL_PERSONAL , NULL, 0, str);

Leo Havmøller. 

0
rtxleh (1)
6/17/2008 6:45:21 AM
Take a look at SHGetFolderPath:

http://msdn.microsoft.com/en-us/library/bb762181(VS.85).aspx

--
Ajay

"Landon" <Landon@discussions.microsoft.com> wrote in message 
news:6D506E55-9CEA-448D-858B-909B629C9B1D@microsoft.com...
> No, I mean that my application will be installed on many PC and I need to
> look for the default My Documents path from that PC.
>
> How?
> 

0
ajaykalra (6842)
6/17/2008 12:14:19 PM
IMO, Its much easier to use SHGetFolderPath and its variants rather
than opening the registry and checking it.

--
Ajay

On Jun 17, 2:35 am, "-Nivel-" <nom...@mail.org> wrote:
> "=?Utf-8?B?TGFuZG9u?=" :
> <news:D378F204-D5FA-43AF-8CE7-21197C45571C@microsoft.com>
> mar, 17 jun 2008 00:51:01 GMT
>
> > I use MFC Visual C++ 4.2. How to acquire full path of every computer
> > My Document folder? So when my application ran, it will directly
> > detect the new full path.
>
> > Thank you very much.
>
> Maybe is this what you searching,
>
> CString ClassX::GetMyDocumentsFolder()
> {
> #define BUFSIZE 1024
>         HKEY hKey;
>         TCHAR szDocFolder[BUFSIZE];
>         DWORD dwBufLen = BUFSIZE;
>         LONG lRet;
>
>         lRet = RegOpenKeyEx( HKEY_CURRENT_USER,
>           _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\
> User Shell Folders"),
>                          0,
>                          KEY_QUERY_VALUE,
>                          &hKey );
>
>         if( lRet == ERROR_SUCCESS )
>         {
>                 lRet = RegQueryValueEx( hKey,
>                                 _T("Personal"),
>                                 NULL,
>                                 NULL,
>                                 (LPBYTE) szDocFolder,
>                                 &dwBufLen);
>
>                 if( (lRet == ERROR_SUCCESS) || (dwBufLen < BUFSIZE) )
>                 {
>                         RegCloseKey( hKey );
>
>                         CString string(szDocFolder);
>
>                         if( ExpandEnvStrings( string ) )
>                                 return string;
>                 }
>         }
>
>     return CString();
>
> }
>
> BOOL ClassX::ExpandEnvStrings(CString &str)
> {
>         LPTSTR lpszSystemInfo = 0;  // pointer to system information string
>         TCHAR tchBuffer[BUFSIZE];   // buffer for string
>         DWORD dwResult = 0;         // function return value
>
>         memset((void*)tchBuffer, 0, sizeof(tchBuffer)/sizeof(tchBuffer[0]));
>
>         lpszSystemInfo = tchBuffer;
>
>         dwResult = ExpandEnvironmentStrings( str, lpszSystemInfo, BUFSIZE);
>
>         CString s;
>
>         if( dwResult <= BUFSIZE )
>         {
>                 s = lpszSystemInfo;
>                 str = s;
>                 return TRUE;
>         }
>
>         return FALSE;
>
> }
>
> // get MyDocuments Folder
>     CString dir = GetMyDocumentsFolder();
>
> Nivel.
>
> ** Posted fromhttp://www.teranews.com**

0
ajaykalra (6842)
6/19/2008 1:30:11 AM
See my ShGetFolder explorer on my MVP Tips site.  It generates the code for you, and you
only have to copy-and-paste it into your app.
					joe

On Mon, 16 Jun 2008 17:51:01 -0700, Landon <Landon@discussions.microsoft.com> wrote:

>I use MFC Visual C++ 4.2. How to acquire full path of every computer My 
>Document folder? So when my application ran, it will directly detect the new 
>full path.
>
>Thank you very much.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
6/23/2008 12:50:00 AM
An overly-convoluted solution to a trivial problem.  SHGetFolderPath does it all, with far
less effort.
				joe

On Tue, 17 Jun 2008 02:35:53 -0400, "-Nivel-" <nomail@mail.org> wrote:

>"=?Utf-8?B?TGFuZG9u?=" :
><news:D378F204-D5FA-43AF-8CE7-21197C45571C@microsoft.com> 
>mar, 17 jun 2008 00:51:01 GMT 
>
>> I use MFC Visual C++ 4.2. How to acquire full path of every computer
>> My Document folder? So when my application ran, it will directly
>> detect the new full path.
>> 
>> Thank you very much.
>
>
>Maybe is this what you searching,
>
>CString ClassX::GetMyDocumentsFolder()
>{
>#define BUFSIZE 1024
>	HKEY hKey;
>	TCHAR szDocFolder[BUFSIZE];
>	DWORD dwBufLen = BUFSIZE;
>	LONG lRet;
>							
>	lRet = RegOpenKeyEx( HKEY_CURRENT_USER,
>          _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\
>User Shell Folders"),
>			 0,
>			 KEY_QUERY_VALUE,
>			 &hKey );
>
>	if( lRet == ERROR_SUCCESS )
>	{
>		lRet = RegQueryValueEx( hKey,
>                                _T("Personal"),
>                                NULL,
>                                NULL,
>                                (LPBYTE) szDocFolder,
>                                &dwBufLen);
>
>		if( (lRet == ERROR_SUCCESS) || (dwBufLen < BUFSIZE) )
>		{
>			RegCloseKey( hKey );
>			
>			CString string(szDocFolder);
>
>			if( ExpandEnvStrings( string ) )
>				return string;
>		}
>	}
>
>    return CString();
>}
>
>
>BOOL ClassX::ExpandEnvStrings(CString &str)
>{
>	LPTSTR lpszSystemInfo = 0;  // pointer to system information string 
>	TCHAR tchBuffer[BUFSIZE];   // buffer for string
>	DWORD dwResult = 0;         // function return value
>
>	memset((void*)tchBuffer, 0, sizeof(tchBuffer)/sizeof(tchBuffer[0]));
>	
>	lpszSystemInfo = tchBuffer; 
>
>	dwResult = ExpandEnvironmentStrings( str, lpszSystemInfo, BUFSIZE);
>	
>	CString s;
>
>	if( dwResult <= BUFSIZE )
>	{
>		s = lpszSystemInfo;
>		str = s;
>		return TRUE;
>	}
>	
>	return FALSE;
>}
>
>
>
>// get MyDocuments Folder
>    CString dir = GetMyDocumentsFolder(); 
>
>
>
>Nivel.
>
>
>** Posted from http://www.teranews.com **
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15974)
6/23/2008 12:50:47 AM
Reply:

Similar Artilces:

"C:\document.xls could not be found"?
After doing a HD data transfer, all my spreadsheets open with this message, followed by a series of .xls file Excel couldn't find (apparently). File reads OK, and I can save changes, but clicking through this series of warnings on every spreadsheet is getting boring. This PC was a gift, so I don't have the MS Office disk. How to fix? Sometimes one of these works when you're having trouble with double clicking on the file in windows explorer: Tools|Options|General|Ignore other applications (uncheck it) --- or --- Close Excel and Windows Start Button|Run excel /unregserver the...

Different Type of Picture in a Document
I have received a document that i have to work on that was compiled by various folks and I have no idea who did what. When I select pictures within the document, I have some pictures with the usual single border; circles at the corners, and squares at the edge. I have other pictures, that when selected, have a double border, that is turquoise. There are three dots in a row at the sides and three dots in a triangle at the corner. With this type of picture I cannot explicitly set the size or other options available with the type above. Does anyone know why some pictures would be ...

Document ID Field Locked
Hi, I'm trying to use VBA to unlock the DocumentID field (TypeID on the Sales Transaction Entry window). Initially when entering a new order it is unlocked but when you navigate off this field it locks and cannot be changed. The people who installed GP are no longer here so I'm not sure if this is a customization or if all GP installations work this way. In any case, I'd like to unlock this field completely so that users can change the Type ID at any time in case they put in the wrong one. No matter what VB code I use and what event, the field stays locked after tabbing off...

Upgrade the local database
I’ve upgraded from 1.3 to dynamics 2.0 and when I 'Z' out I receive this error message. “Upgrade the offline database before synchronization can be restored” What are the steps to upgrade the local DB? Thanks for any help. How did you upgrade to version 2? Did you use SO Administrator, connected to your 1.3 db then selected database - upgrade? If so, you could update the local db the same way - at the register (where the local offline db is located) use SO administrator to connect (local) to the offline db - then database - upgrade. If you are a single store, single regi...

networked computer emails
Hi all, I don't know if this is possible or not but i'm trying to set up an email for a networked computer using the same domain name. have the domain of freeuk.com with a username in front i,e xxxxxxx@freeuk.com and i want to set it up so the other pc has name.xxxxxxxx.freeuk.com/ Is this even possble?? -- egg987 Are you wanting to name the computer or create an email address for it? You can certainly create any email address you want, if you own the domain, but the computer can't receive email directly - you need to use an email client on that computer. If you just wan...

Still get limit warnings after change
I have been working with my E2K3 server to enable more convienient use of the Mail message warning limit. I installed the Quota message service which works very well but when i change a users limits and/or the limits set in the ESM console (mailbox store properties) i am still getting a warning for a user who is now within limits. Is there a lag time? can i manually update something? so the user doesn't receive limit warnings anymore?? Quota changes can take up to two hours to take effect. -- Ed Crowley MVP - Exchange "Protecting the world from PSTs and brick backups!" &q...

How can I move multiple linked workbooks between computers
without having to define the links? I would guess that if they'er all in the same folder, you could just copy them and paste them into a single folder. If the files were in separate folders, then I'd open each in excel, save them to one folder and copy them to one folder on the recipient pc. But that could even be more work than just Edit|Links???? TAG wrote: > > without having to define the links? -- Dave Peterson Dave, Thanks for your reply. Each of the files are in separate folders. I would be easier to copy than the edit links because each file has multiple lin...

Update 1 of 1 installing, computer won't shut down
Hi, When I shut down my computer and get the message, 1 of 1 updates installing, do not turn off your computer", nothing installs and my computer doesn't automatically turn off like it usually does. I have had to turn it off at the power switch, when I press the off button on the CPU, nothing happens. It just continually goes back and forth from, " installing 1 of 1 updates," to "do not shut down your computer, it will shut down automatically." I would appreciate any help in fixing this issue. Thanks KTexas wrote: > When I shut down my com...

How do you view a document that was done in publisher without hav
How do you view a document that was done in publisher if you do not have publisher or you have an older version than what it was designed in? Is there a reader file for this? no you could output the file to a pdf if you have Acrobat distiller/writer or use CutePDF or PrimoPDF "Becky" <Becky @discussions.microsoft.com> wrote in message news:4409C440-727A-4988-9614-E04DB27CBE80@microsoft.com... | How do you view a document that was done in publisher if you do not have | publisher or you have an older version than what it was designed in? Is | there a reader file for t...

Transfer of psts from one computer to another
I was given a hand-me-down pc and have installed my Office Enterprise 2007 on the new machine (which operates on Vista). I've configured my Outlook addresss. I've copied my psts from the old machine (running XP and Outlook 2003) to an external hard drive and have attempted to import them to the new machine. I get an error "don't have permission to access these personal folders". Is this because I need to first delete the previous user's profile and create one for myself? Or is there another issue? Please advise. Locate the pst files in the Document...

Outlook on two computers
I typically run Outlook on two different computers - a desktop which has an always-on connection to the Internet, and a laptop that I use when away from home. Generally, I send and receive mail only from the desktop machine. However, when I am going to be away for several days, I copy the Outlook.pst and Archive.pst files to the laptop, send and receive e-mail from that machine, then copy the files back to the desktop when I return. The *.pst files are quite large (presently about 281 and 500 MB respectively), so this is kind of cumbersome, but I haven't found a better way. Recently, I ...

importing a large word document into Publisher XP
I am having a horrible time trying to figure out how to import a 24 page word document into a booklet format. I have been trying for two days to no avail. Please help me, this really shouldn't be this difficult! On your booklet's first page arrange the margins, create a text box to fit within your margin, with the text box selected, right-click, click change text, text file, browse to your Word file. Publisher will automatically create text boxes and pages. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "theworkin...

Trying to create completely server side, document merge
I was given the task of designing a complete web based document prep system. In simplest terms (using a msword explanation) create a database of merge fields, and a library of templates. Allow the webuser to select the template, merge his DB record, and produce a formatted document that can be printed or downloaded. We need to do this without specialized software on the client, since it will be universally available to webusers. We considered using PDF, but the creation of the templates were painfully slow, and the datamerge had severe space limitations (the form could not adequately...

how to open a new Word document in draft view as default
I saw some posings on it as to go to Word options, advanced, general and choose allow opening a document in draft view. It worked for me one time, but not this time. The new documents keep opening in the small print layout (can't even see what is in there, the size is so small), and I have to keep putting documents in Draft view file manually. Change the zoom setting - http://word.mvps.org/FAQs/General/SaveViewAndZoom.htm or You can control the zoom and the view with auto macros in normal.dot. The following will set it to 100% zoom and normal/draft view regardless of what ...

How do I get rid of/refresh the browsed pages links in the hyperli
It's driving me nuts just to find one link. Ig I could clear it up once in a while that would be cool. thanks for the help. :) In Internet Explorer, tools, Internet Options, delete files. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "adumbledore" <adumbledore@discussions.microsoft.com> wrote in message news:04FCEF52-5F12-43CB-B0D1-B093AEA91A23@microsoft.com... > It's driving me nuts just to find one link. Ig I could clear it up once in a > while that would be cool. thanks for the help. :) ...

Word: The document 'Filename' caused a serious error the last time ...
Upon opening some previously created Word 2003 documents, users on our network are receiving the message: The document 'Filename' caused a serious error the last time it was opened. Would you like to continue opening it? At which point the document can not be opened and the user is presented with the option to pull available unformatted text from the <ocument. ... or ... Word stops responding completely and you have to end-task on Word. Searching Microsoft will tell that you can remove the documents in question from the disabled list in Word. Indeed you can, but thi...

Using MDIChildFrame for different views of document
I have two separate questions: Question 1: ----------- How do I use my MDIChildFrame derived class in an MDI application to show different views of the same document? This is what I want: 1. When the document is initially opened, it will be opened in a MDIChildFrame-derived window with the "default" view. 2. In response to certain commands/menus, another child window should open and show another view of the same document. There may be more than one view. How do I do this? Question 2: ----------- Due to the application having many views and the corresponding GUI classes, the appli...

Certain e-mails get bounced back to me with the following error.
Please help, Certain contacts I could send to recently now come back undelivered with the following error message. I have looked into the knowledge base and nothing matches. 553 Sorry, that domain isn't allowed (#5.7.1) Thank you in advance for any assistance. Lance You may need to authenticate to your outgoing server, which can be set up on the "Outgoing Server" tab for your account. -- Jeff Stephenson Outlook Development This posting is provided "AS IS" with no warranties, and confers no rights "Lance Stevens" <lance_of_denver@yahoo.com> wr...

Locale Explorer
Wow... Joe.. that DID get away from you. What an amazing tool. Thanks. Thanks. It was a lot of fun to write, and I learned a lot about the NLS support while doing it... joe On Tue, 28 Nov 2006 21:18:14 GMT, "Elan Magavi" <Elan@nomailnospam.com> wrote: >Wow... Joe.. that DID get away from you. What an amazing tool. > >Thanks. > Joseph M. Newcomer [MVP] email: newcomer@flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm ...

http://LongPathTool.com
http://LongPathTool.com - Copy, Unlock and Delete Path Too Long files Do you have error messages?, like : Path too long. Error cannot delete file: cannot read from source file or disk Cannot delete file: Access is denied There has been a sharing violation. Cannot delete file or folder The file name you specified is not valid or too long. Specify a different file name. The source or destination file may be in use. The file is in use by another program or user. Error Deleting File or Folder Make sure the disk is not full or write-protected and that the file is not currently in use. Error Copyi...

retrieval of one note documents
I was trying to save a powerpoint I had downloaded into One Note the other day that included additional notes I had added and for some reason it didn't save correctly and the information was lost. Is there any way to retrieve the documents with the notes I added? Is there any other way to search in one note other than searching "all notebooks" using keywords? Thanks I would suggest asking your question in either a PowerPoint or One Note newsgroup. This has nothing to do with Word. -- JoAnn Paules MVP Microsoft [Publisher] Tech Editor for "Microsoft Publish...

getting other folders than inbox synchronized when checking internet mail
I am using Outlook 2002 with Windows XP. can I download mail messages from an internet based account (defined as pop3) that are in a folder other than my inbox? Merrav <anonymous@discussions.microsoft.com> wrote: > I am using Outlook 2002 with Windows XP. > can I download mail messages from an internet based > account (defined as pop3) that are in a folder other than > my inbox? If you want messages received with another account to go into a folder other than Inbox, you'll have to create a rule to move them there. -- Brian Tillman Smiths Aerospace 3290 Patterson A...

GP 10 Web Service - CreateSalesOrder method
I am using the Dynamics GP 10 Web Service, CreateSalesOrder method to create a sales order from my Windows Forms application. I would like to display for the user the Sales Order number that is assigned (automatically) when the order is created. MSDN says the key.id is automatically populated in the SalesOrder class. This may be true, but if so the scope does not extend back to my call because SalesOrder.key.ID is null. The CreateSalesOrder method returns void, so the answer is not there either. I have a kluge answer in which I read the SOP10106 to get back the number of the order just cr...

How do I get PPt 2007 out of safe mode
Just installed PPT2007. Switched an older version presentation to 2007 and it seems to be locked in safe mode. Any ideas on what caused this and how to get it out? Save as a new name "delcoronado" <delcoronado@discussions.microsoft.com> a �crit dans le message de news: 4C54D52D-875B-46CE-8961-386B86D649D7@microsoft.com... > Just installed PPT2007. Switched an older version presentation to 2007 and > it > seems to be locked in safe mode. Any ideas on what caused this and how to > get > it out? Has the trial period expired on the new 2007 i...

HOw do I get the formula to figure out a percentage?
Example H & P Consent Pre-Sedation YES NO YES NO YES NO Total Cases 11 13 12 98 I need the percentage of each column. Assuming that your numbers are from A2 to F2, here is a very simpl solution, i.e., not an elegant formula but will work. If you want the percentages to appear below the numbers, enter in B2 =if(A2="","",A2/sum($A$2+$F$2)) and copy this up to cell F2. Another option is =if(A2="",0,A2/sum($A$2:$F$2)) Also, don't forget to "percent" format your cells (B2:F2). Jen Wrote: > Example > H & P Consent Pr...