如何访问隐藏分区/卷 [英] How to access hidden partitions/volumes

查看:342
本文介绍了如何访问隐藏分区/卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须写代码来访问使用C#或C ++隐藏的磁盘分区/卷。
也没有找到这方面的任何帮助参考。

I have to write a code to access hidden disk partitions/volumes using c# or c++. But could not find any help reference on the matter.

作为隐藏卷,它不包含一个盘符,让你不容只需键入C:\并对其进行访问。
一个例子是恢复分区随Windows。您不容看到它在资源管理器中,但它的存在。

As a hidden volume, it does not contain a "Disk Letter", so you can´t just type "C:\" and access it. A example would be the "recovery partition" that comes with Windows. You can´t see it on explorer but it is there.

我的应用程序会写,并从thoose分区读取​​数据,我必须要找到做这样的事情的一种方式 C:\。为thoose

My application will write and read data from thoose partitions and I have to find a way of doing something like "c:\" for thoose.

在上面的图片,数量5和6是隐藏分区。
我已经发现这个计算器链接,但它只是排行榜德分区:
https://msdn.microsoft.com/en-us/library/cc542456(v = VS.85)的.aspx

In the above image, volumes 5 and 6 are hidden partitions. I have found this link on stackoverflow but it only "list" de partitions: https://msdn.microsoft.com/en-us/library/cc542456(v=VS.85).aspx

修改

现在的问题是:即使在使用WMI作为suguested我便无法找到如何筛选音量当寻找文件。
例如 SELECT * FROM win32_DataFile 将列出所有文件中的机器。

The problem is: even using WMI as suguested I could´t find how to filter the the Volume when looking for files. Example, select * from win32_DataFile will list all Files in the machine.

我想应该是使用他们的ID(或名称)过滤所述卷的方法。
是这样的:

I think should be a way of filtering the Volumes using their ID(or name). Something like:

select * from win32_DataFile 
where volumeId = '\\?\Volume{2d5f3a68-75f5-44c4-aa42-716b45811916}\'

或更华丽的方式一样

var files = Directory.GetFiles(@"\\?\Volume{6ff7748e-78db-4838-8896-254b074918f5}\");



另外,我发现了一个外观极好awenser约分区和卷(他们是不一样的东西)
https://social.technet.microsoft.com/Forums/en-US/e7b2ddd6-f245-49ed-8fec-3b6e08e75369/how-do-i-find-the-partition- GUID?论坛= winservergen

EDIT2

由于awensered通过哈利,使用\.\Volume ......是恢复文件的好方法。但我不能找到一种方法使用C#写(创建)一个新的文件。
的最优计算策略迄今使用的PInvoke到C ++的CreateFile方法/句柄。

As awensered by Harry, using "\.\Volume...." was a good way to recovery files. But I could not find a way to write(create) a new file using c#. The best approch so far is using pinvoke to c++ CreateFile method/handle.

任何意见?

推荐答案

FindFirstVolume()API 返回到系统上的每个卷的根目录的路径。

The FindFirstVolume() API returns a path to the root of each volume on the system.

例如,下面的代码打印路径先容,并在该卷的根目录中的第一个文件的名称:

For example, this code prints the path to the first volume, and the name of the first file in the root directory of that volume:

    HANDLE h1, h2;
    wchar_t volpath[4096];
    WIN32_FIND_DATA find_data;

    h1 = FindFirstVolume(volpath, _countof(volpath));

    printf("%ws\n", volpath);

    wcscat_s(volpath, _countof(volpath), L"*.*");

    h2 = FindFirstFile(volpath, &find_data);

    printf("%ws\n", find_data.cFileName);



(在生产中的代码,你需要添加错误检查等。)

(In production code, you would need to add error checking, etc.)

附录

FindFirstVolume返回这样的路径: \\ ?\Volume {6ff7748e-78分贝-4838-8896-254b074918f5} \

FindFirstVolume returns a path like this: \\?\Volume{6ff7748e-78db-4838-8896-254b074918f5}\

如果您正在使用Win32 API(的CreateFile,等),在C ++中,你可以直接使用这条道路,但是由于在.NET中的错误或限制它不与文件管理类,如Directory.GetFiles工作()。 (你可以P / Invoke来Win32 API的,当然,不过这是尴尬的。)

If you're using the Win32 API (CreateFile, etc.) in C++ you can use that path directly, but due to a bug or limitation in .NET it doesn't work with file management classes such as Directory.GetFiles(). (You could P/Invoke to the Win32 API, of course, but that's awkward.)

相反,您可以通过更换出现在问号解决问题以点路径的开头:

Instead, you can work around the problem by replacing the question mark that appears at the beginning of the path with a dot:

var files = Directory.GetFiles(@"\\.\Volume{6ff7748e-78db-4838-8896-254b074918f5}\");

这篇关于如何访问隐藏分区/卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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