C / C ++确定正在运行程序的驱动器 [英] C/C++ Determine Drive a program is running on

查看:157
本文介绍了C / C ++确定正在运行程序的驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在识别代码中的闪存驱动器时遇到问题。

I have been having a problem identifying a flash drive in my code.

幸运的是,我的代码可以从闪存驱动器运行。所以有一种方法在C(或C ++)来告诉什么驱动器号(或驱动器名)的程序运行吗?

Luckily my code can be run from the flash drive. So is there a way in C (or C++) to tell what drive letter (or drive name) a program is running on?

原因我需要知道的是,当我插入USB驱动器,它运行的程序将文件从计算机复制到USB驱动器本身。

Reason I need to know is when I plug the USB drive in, it is running a program that copies files from the computer to the USB drive itself.

推荐答案

GetModuleFileName 可以找到您的驱动程序信件,如这:

GetModuleFileName can find out the driver letter for you, like this:

TCHAR ExeName[MAX_PATH];
GetModuleFileName(NULL, ExeName, MAX_PATH);
TCHAR DriveLetter = ExeName[0];

您可能会发现 GetDriveType API也很有用。

You might find the GetDriveType API useful as well.

这篇关于C / C ++确定正在运行程序的驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆