码迷,mamicode.com
首页 > 其他好文 > 详细

创建符号链接

时间:2015-09-21 15:36:29      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

NTSTATUS CreateMyDevice(IN PDRIVER_OBJECT pDriverObject)
{
    NTSTATUS status;
    PDEVICE_OBJECT pDevObj;
    PDEVICE_EXTENSION pDevExt;

    //创建设备名称
    UNICODE_STRING devName;
    RtlInitUnicodeString(&devName, L"\\Device\\My_DriverLinkName");

    //创建设备
    status = IoCreateDevice(pDriverObject,sizeof(DEVICE_EXTENSION),&devName,FILE_DEVICE_UNKNOWN,0, TRUE,&pDevObj);
    if (!NT_SUCCESS(status))
        return status;

    pDevObj->Flags |= DO_DIRECT_IO;
    pDevExt = (PDEVICE_EXTENSION)pDevObj->DeviceExtension;
    pDevExt->pDevice = pDevObj;
    pDevExt->ustrDeviceName = devName;

    //申请模拟文件的缓冲区
    pDevExt->buffer = (PUCHAR)ExAllocatePool(PagedPool, 1024);
    //设置模拟文件大小
    pDevExt->file_length = 0;

    //创建符号链接
    UNICODE_STRING symLinkName;
    RtlInitUnicodeString(&symLinkName, L"\\??\\My_DriverLinkName");
    pDevExt->ustrSymLinkName = symLinkName;
    status = IoCreateSymbolicLink(&symLinkName, &devName);

    if (!NT_SUCCESS(status))
    {
        IoDeleteDevice(pDevObj);
        return status;
    }
    return STATUS_SUCCESS;
}



删除符号链接
UNICODE_STRING symLinkName;
//取符号链接名字
    RtlInitUnicodeString(&symLinkName, L"\\??\\My_DriverLinkName");
    //删除符号链接
    IoDeleteSymbolicLink(&symLinkName);

 

创建符号链接

标签:

原文地址:http://www.cnblogs.com/IMyLife/p/4826187.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!