English 中文(简体)
公开名录
原标题:Open Directory Using CreateFile

我正试图利用创造力功能获取目录信息。 然而,我对5部双赢法进行了解释,这意味着“准入被击落”。 请提出咨询意见。

CreateFile(path, GENERIC_READ, FILE_SHARE_READ, IntPtr.Zero, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, IntPtr.Zero);

这是人们发出的呼吁,正如文件指出的那样,正在使用方济会联合会。 DL进口似乎在做工时很重,与以下方面一样:

[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr CreateFile(string filename,
                                    uint desiredAccess,
                                    uint sharedMode,
                                    IntPtr securityAttributes,
                                    uint creationDisposition,
                                    uint flagsAndAttributes,
                                    IntPtr templateFile);

最新情况:我需要获得一份名录,以便使用GetFile InformationByHandle()和提取独一无二的id。 这种方法目前使用档案,目前并不与目录合作。

最新情况:这一问题的X需要一个独特的目录识别标志,该名录不是其绝对道路。 即使名录被移至或改名为名录,也需要保持相同。 NET没有像刚才提到的那样提供任何独特的识别信息,只能通过使用双赢才能做到这一点。

问题回答

首先,在您的申请书中应明确表明,这符合署长的特权。 然后,请SE_BACKUP_NAME。 特权<代码>Adjust TokenPrivileges 页: 1 然后,我建议你使用<代码>FILE_SHARE_DELETE。 FILE_SHARE_READ FILE_SHARE_ITEcodes as the commdMode. 现在,你们应当能够使用<代码>CreateFile,开放名录处理和使用GetFile Information ByHandle to have BY_HANDLE_FILE_INFORMATION.

<>UPDATED: 或许,以下简单易行的方案可以帮助你

#include <windows.h>
#include <tchar.h>

int _tmain()
{
    HANDLE hAccessToken = NULL;
    HANDLE hFile = INVALID_HANDLE_VALUE;

    __try {
        LUID luidPrivilege;
        DWORD dwErrorCode;
        BY_HANDLE_FILE_INFORMATION fiFileInfo;

        // -----------------------------------------------------
        // first of all we need anable SE_BACKUP_NAME privilege
        // -----------------------------------------------------
        if (!OpenProcessToken (GetCurrentProcess(),
                               TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                               &hAccessToken))
            __leave;

        if (LookupPrivilegeValue (NULL, SE_BACKUP_NAME, &luidPrivilege)) {
            TOKEN_PRIVILEGES tpPrivileges;
            tpPrivileges.PrivilegeCount = 1;
            tpPrivileges.Privileges[0].Luid = luidPrivilege;
            tpPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
            AdjustTokenPrivileges (hAccessToken, FALSE, &tpPrivileges, 
                                   0, NULL, NULL);
            if ((dwErrorCode = GetLastError ()) != ERROR_SUCCESS)
                __leave;
        }
        else
            __leave;

        // -----------------------------------------------------
        // now one can open directory and get 
        // -----------------------------------------------------
        hFile = CreateFile (TEXT("C:\"),
                            0, //GENERIC_READ, 
                            0, //FILE_SHARE_READ, //FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
                            NULL,
                            OPEN_EXISTING, 
                            FILE_FLAG_BACKUP_SEMANTICS,
                            NULL);
        if (hFile == INVALID_HANDLE_VALUE)
            __leave;
        if (!GetFileInformationByHandle (hFile, &fiFileInfo))
            __leave;

        _tprintf(TEXT("VolumeSerialNumber: 0x%08X
"), fiFileInfo.dwVolumeSerialNumber);
        _tprintf(TEXT("FileIndex: 0x%08X%08X
"), fiFileInfo.nFileIndexHigh, fiFileInfo.nFileIndexLow);
    }
    __finally {
        if (hFile != INVALID_HANDLE_VALUE)
            CloseHandle (hFile);
        if (hAccessToken != NULL)
            CloseHandle (hAccessToken);
    }

    return 0;
}

该方案开放了<代码>C:的目录和显示序列号Serial number和文档索引,其中标明了NTFS的目录。 为了缩短方案时间,我删除了所有错误信息(见_leave)。 和 我在前面已经提到过,请将<条码>查询<>条码>作为“UACmp Level”(见“Manifest file”部分链接环境)。 上述法典经过测试,在我工作。 你可以在C#中照搬同样的法典。

UPDATED:以下简单易行的方案可以帮助你......

我试图确定时间,但是错误的。 我已修改如下:

hFile = CreateFile(  TEXT("C:\MyDirectory"),
// 0, //GENERIC_READ,
GENERIC_READ | GENERIC_WRITE,
// 0, //FILE_SHARE_READ, //FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS,
NULL);

ok。 感谢。 安德烈。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签