zoukankan      html  css  js  c++  java
  • 创建符号链接

    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);
  • 相关阅读:
    mysql登录和连接 权限
    No package mysql-server available.
    rails开发demo(一)搭建环境
    chrome和搜狗浏览器的js问题
    setInterval setTimeout clearInterval
    几道面试题
    du df 查看文件和文件夹大小
    win7开启休眠功能
    ssh key scp命令 scp无密码传输
    dd 生成指定大小文件
  • 原文地址:https://www.cnblogs.com/IMyLife/p/4826187.html
Copyright © 2011-2022 走看看