Drive letter for program

Is it possible to get the drive letter from which the 
program is running? If it is, how? (I have already tried 
_getdrive() (only returns C) and _getcwd() (also retreives 
a path from C)
0
joape382 (52)
8/21/2003 5:55:25 PM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
803 Views

Similar Articles

[PageSpeed] 59

On Thu, 21 Aug 2003 10:55:25 -0700, "Joachim"
<joape382@student.liu.se> wrote:

>Is it possible to get the drive letter from which the 
>program is running? If it is, how? (I have already tried 
>_getdrive() (only returns C) and _getcwd() (also retreives 
>a path from C)

GetModuleFileName() and _splitpath().

Ruben



0
ruben4008 (24)
8/21/2003 7:10:32 PM
Thanks,
however, there was a new problem when trying this:

char* buf = new char[255];
GetModuleFileName(NULL, buf, 255);
CString _driveLetter = CString(buf).GetAt(0);
delete buf;
AfxMessageBox(CString(_driveLetter),MB_OK);

CString copyTo(_dir + "\\" + fileName);
CString copyFrom(_driveLetter + ":\\");
if (condition)
	copyFrom += "Program";
else
	copyFrom += "Databaser";
copyFrom += "\\" + fileName;
AfxMessageBox(CString("FROM=")+CString2charPtr
(copyFrom),MB_OK);

if (CopyFile(CString2charPtr(copyFrom), CString2charPtr
(copyTo), TRUE) == 0)
	displayError(fileName);

The strange thing is that the line
AfxMessageBox(CString("FROM=")+CString2charPtr
(copyFrom),MB_OK);
which should show the drive letter plus the copy from path 
(as the line AfxMessageBox(CString(_driveLetter),MB_OK); 
does), but it shows:
FROM=memory or resources.Program\filename

What's wrong?


>-----Original Message-----
>On Thu, 21 Aug 2003 10:55:25 -0700, "Joachim"
><joape382@student.liu.se> wrote:
>
>>Is it possible to get the drive letter from which the 
>>program is running? If it is, how? (I have already tried 
>>_getdrive() (only returns C) and _getcwd() (also 
retreives 
>>a path from C)
>
>GetModuleFileName() and _splitpath().
>
>Ruben
>
>
>
>.
>
0
joape382 (52)
8/21/2003 9:25:19 PM
Try

CString strPath;
CString strDrive;

int len=GetModuleFileName(NULL,strPath.GetBuffer(_MAX_PATH),_MAX_PATH);
strPath.ReleaseBuffer();
if (len!=0){
	_splitpath(strPath,strDrive.GetBuffer(_MAX_DRIVE),NULL,NULL,NULL);
	strDrive.ReleaseBuffer();
} else {
	error
}

Now the strDrive should hold the drive letter which could be empty if it is run from a network path i.e beginning with
two backslashes "\\".

Ruben


On Thu, 21 Aug 2003 14:25:19 -0700, "Joachim" <joape382@student.liu.se> wrote:

>Thanks,
>however, there was a new problem when trying this:
>
>char* buf = new char[255];
>GetModuleFileName(NULL, buf, 255);
>CString _driveLetter = CString(buf).GetAt(0);
>delete buf;
>AfxMessageBox(CString(_driveLetter),MB_OK);
>
>CString copyTo(_dir + "\\" + fileName);
>CString copyFrom(_driveLetter + ":\\");
>if (condition)
>	copyFrom += "Program";
>else
>	copyFrom += "Databaser";
>copyFrom += "\\" + fileName;
>AfxMessageBox(CString("FROM=")+CString2charPtr
>(copyFrom),MB_OK);
>

This looks suspicious. Why not just CString("FROM")+copyFrom?

>if (CopyFile(CString2charPtr(copyFrom), CString2charPtr
>(copyTo), TRUE) == 0)
>	displayError(fileName);
>
>The strange thing is that the line
>AfxMessageBox(CString("FROM=")+CString2charPtr
>(copyFrom),MB_OK);
>which should show the drive letter plus the copy from path 
>(as the line AfxMessageBox(CString(_driveLetter),MB_OK); 
>does), but it shows:
>FROM=memory or resources.Program\filename
>
>What's wrong?
>
>
>>-----Original Message-----
>>On Thu, 21 Aug 2003 10:55:25 -0700, "Joachim"
>><joape382@student.liu.se> wrote:
>>
>>>Is it possible to get the drive letter from which the 
>>>program is running? If it is, how? (I have already tried 
>>>_getdrive() (only returns C) and _getcwd() (also 
>retreives 
>>>a path from C)
>>
>>GetModuleFileName() and _splitpath().
>>
>>Ruben
>>
>>
>>
>>.
>>

0
ruben1 (50)
8/22/2003 6:29:49 AM
Reply:

Similar Artilces:

Newbie- Subtask duration not driving main task duration
Just started with Project 2007 last week and I already have an issue! Let's say I create a task, then put some subtasks under it (indented). If I put in a duration for one of the subtasks at 5 days, the blue bar for the subtask extends 5 days, but the main task stays at the default 1 day. It doesn't matter if I open a new project, open a project someone else sends me, etc., same thing happens. However, if I send my Project to someone else, everything looks as it should. I assume I have some kind of formatting or filtering issue, but I'm not experienced enough in p...

Mapped vs Network drives
hi, is there a way to show a network drive via formula when a drive is being mapped? Different users mapping of the same drive to a various letters is causing issues. I thought of writing an UDF combining a string with a network drive name with a combination of cell("filename") & hyperlink function, but there has to be an easier way. Thank you, -- ______ Regards, Greg Take a look at http://vbnet.mvps.org/index.html?code/network/uncfrommappeddrive.htm HTH Bob "Greg" <Greg@discussions.microsoft.com> wrote in message news:3FE...

Using Access with other db programs
I work for a health organization and we have upgraded to ACCESS after years of using various other db programs. Is it possible for me to import a DBIII file into ACCESS and then match it to another db file? If so, how? Also, is there a good book on ACCESS which discusses this type of question and good overall reference once you're past the beginner stage? Thanks. Hi. > Is it possible for me to import a DBIII file into ACCESS > and then match it to another db file? Yes. See "Supported data sources for importing, for exporting, and for linking in a Microsoft Office A...

Can Excel be use to a limited degree without the full program
Can an Excel spreadsheet be distributed that allows only limited values be changed, not formulas, to users without Excel? Sort of mortgage amortization tables, etc. as example. User can plug in some numbers, see results, but can not change the core algorithms. If s, how would this be done? Thanks, Doug Sanders Doug You can download the Excel viewer from here http://www.microsoft.com/downloads/details.aspx?FamilyID=c8378bf4-996c-4569-b547-75edbd03aaf0&displaylang=EN -- HTH Nick Hodge Microsoft MVP - Excel Southampton, England nick_hodgeTAKETHISOUT@zen.co.ukANDTHIS web: www.ni...

Start program in minimized window
How do I start a program (e.g. Internet Explorer Version 8) in a minimized window, just a tab in the toolbar? Can this be done for any program and is there a universal switch for this? PSRumbagh wrote: > How do I start a program (e.g. Internet Explorer Version 8) in a minimized > window, just a tab in the toolbar? Can this be done for any program and is > there a universal switch for this? - To start the program minimized to the Taskbar: Create a shortcut to the program, right-click the shortcut, click Properties, change "Run:" to "Minimized". ...

output.c error in multithreaded program
Hi, My multithreaded program is occasionally crashing. I tend to get several types of crashes (I think) as the call stack often looks different and I'm finding them a real pain to track down Anyway the "current" one crashes in output.c. When I look at the file description it states **** DOESN'T CURRENTLY DO MTHREAD LOCKING **** So, how do I get around this? I'm not sure where output.c is called in my program - this is the earliest entry on the call stack (it goes from top to bottom earliest bottom right?) Anyway most of the other entries are for ntdll.dll which I ca...

Macro open a file in any drive/directory
Hello, I'm tryign to do a macro that will open a file. I want it to bring up the Open File dialog, so that users can search the file they want. Example, the file might be in any drive and one user might call the file differently, so need to be able for users to open the file. I know there'' GetFile code, but can't figure right coding. please advise any help. thank you, juan To show the file>open window use Application.Dialogs(xlDialogOpen).Show -- Regards, Peo Sjoblom "Juan" <jhernan562@aol.com> wrote in message news:00c601c3dc5e$45ef40d0$a401...

Current Money Program Update: What's it Do?
I just went through the update process for the most recent software update -- is there a file somewhere that lists changes in this update? Click the link that talks about it on the What's New module on Money's home page. -Mark "Ben" <benjimen@mail.com> wrote in message news:165DF8BF-3D8B-45F8-BBE7-C3D462D48065@microsoft.com... >I just went through the update process for the most recent software >update -- is there a file somewhere that lists changes in this update? > ...

Change drive in Exchange Cluster
Hi, Sorry for the long post, trying to make sure I have everything Background: Windows 2003 Cluster Exchange 2003 Cluster, singl;e virtual server in Active/Passive config (3 node cluster) Additional SRS server Exchange 5.5 server Single site, single Org When the Exchange cluster was installed (new resource created), the Data path was configured as M:\Exchsrvr (located on shared SAN as physical disk) The server is currently not live (only has test users, public folder replicas, not primary RUS) It has been decided that they wish to remove Exchange from the M: drive and change the drive ...

DBX on mapped drive
Hello, Users in our domain are getting an OE error: 0x800C013B from time to time. I know, I know, sent item corruption and all. I have recreated all dbx's many times already, but it does not fix the problem. We use schema where users maiboxes are stored in servers mapped drive and if I move mailboxes to local machine, OE starts to work fine again. When I move them back, it works until some big attach comes to mailserver and when OE starts to pull that mail, I get the same error again. Outlook Express version 6.0 -- Pawel Rutkowski 1) Outlook Express questions go to: microsoft.p...

Conditional format to determine if last character in a cell is a number or a letter
I have a spreadsheet where I enter weights. The weights can be any whole number 1-99999. I would like to be able to flag suspicious weights using conditional formatting by putting a letter as the last character, such as 123a, or 57b, 4471c, etc.What conditional formatting formula can I use to accomplish this? Thanks, Tonso Assuming your weights are in column A, starting with A2, highlight the cells in that column with A2 as the active cell, and use this formula in the CF dialogue box: =3DAND(CODE(UPPER(RIGHT(A2)))>=3D65,CODE(UPPER(RIGHT(A2)))<=3D90) Then click on the Format button a...

No audio for program events
I've upgraded my Money 2004 trial version via the "upgrade" option in the tools menu. I also downloaded the Multimedia files from the website. However, the audio files were not included in those downloads. Does anyone know where I can get the audio files for program events? TIA -Pete ...

Program an automatic creation of an UML attributes
Please, I want to program an application which creates an UML class and add attributs to the class. I have done it but it modifies only the text of attributs. When we double clik to the created class, nothing appears. please response at zmmail@web.de thx a lot ...

Add In Program Only Problem On Lap Top
I have loaded a Visual Basic on my desktop for Excell. But it will not run the same Visual Basic w/ the same software on my Lap Top ? "ddinsmore@ontimecsi.com" <anonymous@discussions.microsoft.com> skrev i melding news:5cba01c42d89$fe205dc0$a101280a@phx.gbl... > I have loaded a Visual Basic on my desktop for Excell. > But it will not run the same Visual Basic w/ the same > software on my Lap Top ? "It will not run" narrows it down just a few thousand possible causes. Can you provide more detail that that ? Best wishes Harald ...

Driving Me Nuts
Hi: Posted earlier about an issue with a leftover public folder hierarchy from 5.5 migration and now this is driving me nuts. I just want to get rid of the entire PF tree but cannot set permissions on any folders or delete them. Shows owner as blank. I fear deleting the entire PF store because of the free/busy used for calendaring. What can I do to whack these things already. Thanks Hi, Download pfdavadmin (from Microsoft) and set the desired permissions from this program. Leif "Joe" <a@a.com> wrote in message news:OU7E$SKnGHA.4788@TK2MSFTNGP02.phx.gbl... > Hi...

Putting Microsoft Money 2006 Application on a Thumb Drive
Hello Does any know how to put Microsoft Money 2006 application and data file on a Thumb drive to use on any computer? Also what size Thumb Drive would you need? -- Thanks Inquiring Minds In microsoft.public.money, Inquiring Minds wrote: >Hello > > Does any know how to put Microsoft Money 2006 application and data file >on a Thumb drive to use on any computer? Also what size Thumb Drive would >you need? No. However people have reported successfully putting the data file on a USB flash drive. For the data file, you would want to go for speed. 256 MB up to 2 GB w...

Letters to Numbers
Is it possible to convert letters (Like initials for an employees name) to numbers? -- Andrew H.W. Lochner On Sat, 13 Feb 2010 19:14:01 -0800, Andrew <Andrew@discussions.microsoft.com> wrote: >Is it possible to convert letters (Like initials for an employees name) to >numbers? Yes. Chr("A") is equal to 65 for example. What exactly are you trying to accomplish? If you're trying to come up with a unique identifier, you're on the wrong track: David Aaron Palmer and Dorothy Ann Peterson will give the same number. -- John W....

MFC program to download a URL
Can someone send me a simple MFC program to download any URL -OR- at least point me to the library functions that I can use ? Thanks ThewhizKId thewhizkid wrote: > Can someone send me a simple MFC program to download any URL -OR- > at least point me to the library functions that I can use ? > > Thanks > ThewhizKId I am not sure what you mean by URL. If you mean getting a web page HTML then have a look at http://www.codeproject.com/internet/webgrab.asp otherwise choose what you need in the list http://www.codeproject.com/internet/ Simon. thewhizkid@rock.com (thewhizkid) ...

hyperlink is opening file with wrong program
I have a hyperlink to a tif file set up in an excel spreadsheet. I have brava reader set up as the default program to open tif files and whenever I open the tif files from Windows Explorer it opens correctly. However, whenever I click on the hyperlink to open the exact same file, it opens up with Micrografx Picture Publisher instead of Brava Reader. Any thoughts on why that would be happening? ...

restoring exchange on a server with no tape drive
Exchange 2000/Windows 2000 Need to get some old mails from an old DAT tape, which backed up Exchange using NTbackup. Now for files it is simple to have the files restored to a different computer, but seems not possible for Exchange. The restore server (computer) that I have setup Windows/Exchange does not have a tape drive, as the only DAT drive is on the current server (which is being used). Now I had an Exchange backup to file on disk, and that worked fine, but I can't see how I can get the data off the tape without installing the drive in the second server (which I cannot take offline ...

calling a C++ program from Excel 2000 and passing a result from C++ back to an excel spreadsheet
I have an excel spreadsheet and call a C++ program from a VBA macro using the command below. (I am not using visual C++ but a command line driven version, Borland C++ compiler) retval = Shell ("c:\options\options1.exe", vbNormalFocus) What I want to be able to do is to pass some of the values in my excel spreadhseet to the C++ program when calling it. There are 5 variables(spreadsheet cells) whose numerical values I want to pass across to the program. Once the C++ program has run I want to put a value that it caluculates in to a cell in my excel spreadsheet. Any help much...

RegQueryValueEx retrieved only one letter
I want to retrieve the string value of a register key which is "C: \program files\test", but every time I only get one letter as "C" returned. My code is as follows, can somebody help me find out what happened? /////////////////////////////////////////////////////////////////////////////////////// HKEY hKEY LPCTSTR data_Set=_T("Software\\test\\Settings"); long ret0=(::RegOpenKeyEx (HKEY_CURRENT_USER, data_Set, 0, KEY_READ, &hKEY)); if(ret0!=ERROR_SUCCESS) AfxMessageBox(_T("error: cannot open hKEY!")); char *szPath = new char[256]; ...

My Book World Edition II External Drive Hangs When Opening The Fil
Having a very odd problem. Installed the My Book World Edition II external hard drive to my Windows Vista about a year or 2 ago, and it was working fine until recently. I tried to create a new folder to add files from iTunes, and all of a sudden it locked up and gave me the "Not Responding" error. I closed the program, and then tried to open it again, but the same thing happened. Now every time when I click on the icon to open it, it starts hanging/locking up and "Not Responding". I disconnected it and plugged into a Windows XP computer to see if I would...

Selecting certain letters in address book closes Outlook
I'm using Outlook 2000 Pro with Windows XT. When you open the address book, then select u,v,w,x,y,or z, Outlook immediately closes. PLEASE HELP! Thank you. Try running Detect and Repair from the Help menu. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the Swen virus, all e-mails sent to my actual account will be deleted w/out reading. After searching google.groups.com and finding no answer ALB <anonymous@discussions.microsoft.com> asked: | I'm using Outlook 2000 Pro with Windows XT. When you open | the address boo...

Importing mail from other mail programs
Hi, Can Windows live mail import messages from MS Outlook or Outlook Express? I have Windows 7, so I don't have OE on this computer, but I do have the .dbx files archived on backup media. How is the import done, from either program? Thanks in advance. You can use those OE .dbx files as follows: http://www.vista4beginners.com/Migrate-from-Outlook-Express-to-Windows-Mail Migrating from Outlook is much more involved, and requires using OE as the middleman. Gary VanderMolen, Microsoft MVP (Mail) "sheana" wrote in message news:3FAF3EDC-8957-4982-AA4A-CE2E5...