LIUTANG
驱动大牛
驱动大牛
  • 注册日期2001-03-30
  • 最后登录2020-12-27
  • 粉丝0
  • 关注0
  • 积分8分
  • 威望58点
  • 贡献值0点
  • 好评度12点
  • 原创分0分
  • 专家分0分
  • 社区居民
阅读:1363回复:6

请问如何能编程实现设备的拔出

楼主#
更多 发布于:2002-12-03 16:47
举例子说就是如果我插入一个U盘或其他设备,这时在WINDOWS2000或XP中的右下角会有一个小图标表示有设备插入。拔出设备时我们一般要点那个小图标,然后选择停止设备,这样才安全。现在我想编程实现这一功能,执行这一功能后再拔出设备系统不会出现不安全的设备删除对话框。不知各位有何高见?

我是过用删除设备和DISABLE设备的方法,能达到效果,但是这样做这个状态会保持到下一次设备插入,也就是说下次设备插入的时候还是处于删除(此时需重新安装驱动)或DISABLE(此时设备不能使用,必须手工把它的状态改为ENABLE),另外,有一个什么STOP的状态,但是这样设结果失败,所以我实在是没办法了,哪位大哥知道怎么弄,请一定告诉我,谢谢了先。
LIUTANG
驱动大牛
驱动大牛
  • 注册日期2001-03-30
  • 最后登录2020-12-27
  • 粉丝0
  • 关注0
  • 积分8分
  • 威望58点
  • 贡献值0点
  • 好评度12点
  • 原创分0分
  • 专家分0分
  • 社区居民
沙发#
发布于:2002-12-05 08:31
我自己顶一下,大伙给点建议也好啊。
ydyuse
驱动老牛
驱动老牛
  • 注册日期2002-07-25
  • 最后登录2005-03-26
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2002-12-05 08:47
我给点建议,去看DDK的TOASTER,它实现了EJECT设备。
生命驱动,活力无限!
lvwj
驱动老牛
驱动老牛
  • 注册日期2001-08-21
  • 最后登录2021-01-31
  • 粉丝0
  • 关注0
  • 积分13分
  • 威望181点
  • 贡献值0点
  • 好评度52点
  • 原创分0分
  • 专家分0分
  • 社区居民
地板#
发布于:2002-12-05 09:44
版主好像谈过这个问题,你在本论坛或是 zboard 论坛看看吧.
 :D
www.bjjcz.com
wesintj
驱动牛犊
驱动牛犊
  • 注册日期2002-12-05
  • 最后登录2007-04-29
  • 粉丝0
  • 关注0
  • 积分10分
  • 威望1点
  • 贡献值0点
  • 好评度1点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2002-12-06 10:17
我有同样的问题,各位老大们帮帮忙吧~~~~
tigerzd
驱动老牛
驱动老牛
  • 注册日期2001-08-25
  • 最后登录2004-12-13
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2002-12-06 10:54
看DDK文档定义,在响应IRP_MN_QUERY_CAPABILITIES时作相应的处理:
typedef struct _DEVICE_CAPABILITIES {
    USHORT Size;
    USHORT Version;
    ULONG DeviceD1:1;
    ULONG DeviceD2:1;
    ULONG LockSupported:1;
    ULONG EjectSupported:1;//注意这个
    ULONG Removable:1;
    ULONG DockDevice:1;
    ULONG UniqueID:1;
    ULONG SilentInstall:1;
    ULONG RawDeviceOK:1;
    ULONG SurpriseRemovalOK:1;//注意这个
    ULONG WakeFromD0:1;
    ULONG WakeFromD1:1;
    ULONG WakeFromD2:1;
    ULONG WakeFromD3:1;
    ULONG HardwareDisabled:1;
    ULONG NonDynamic:1;
    ULONG WarmEjectSupported:1;
    ULONG Reserved:15;
    ULONG Address;
    ULONG UINumber;
    DEVICE_POWER_STATE DeviceState[PowerSystemMaximum];
    SYSTEM_POWER_STATE SystemWake;
    DEVICE_POWER_STATE DeviceWake;
    ULONG D1Latency;
    ULONG D2Latency;
    ULONG D3Latency;
} DEVICE_CAPABILITIES, *PDEVICE_CAPABILITIES;

EjectSupported
Specifies whether the device supports software-controlled device ejection while the system is in the PowerSystemWorking state. This member pertains to ejecting the device from its slot, rather than ejecting a piece of removeable media from the device.


SurpriseRemovalOK
Specifies whether the system should display a pop-up window if a user removes the device from the machine without first going through the Unplug or Eject Hardware applet (a \"surprise-style\" removal).




[编辑 -  12/6/02 by  tigerzd]
犯强汉者,虽远必诛! [img]http://www.driverdevelop.com/forum/upload/tigerzd/2002-12-13_sf10.JPG[/img]
tigerzd
驱动老牛
驱动老牛
  • 注册日期2001-08-25
  • 最后登录2004-12-13
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
6楼#
发布于:2002-12-06 11:06
再给你贴一段代码(ISO_USB中的)用来设置Capabilities的:

NTSTATUS
IsoUsb_QueryCapabilities(
    IN PDEVICE_OBJECT PdoDeviceObject,
    IN PDEVICE_CAPABILITIES DeviceCapabilities
    )

/*++

Routine Description:

    This routine generates an internal IRP from this driver to the PDO
    to obtain information on the Physical Device Object\'s capabilities.
    We are most interested in learning which system power states
    are to be mapped to which device power states for honoring IRP_MJ_SET_POWER Irps.

    This is a blocking call which waits for the IRP completion routine
    to set an event on finishing.

Arguments:

    DeviceObject        - Physical DeviceObject for this USB controller.

Return Value:

    NTSTATUS value from the IoCallDriver() call.

--*/

{
    PIO_STACK_LOCATION nextStack;
    PIRP irp;
    NTSTATUS ntStatus;
    KEVENT event;


    // This is a DDK-defined DBG-only macro that ASSERTS we are not running pageable code
    // at higher than APC_LEVEL.
    PAGED_CODE();


    // Build an IRP for us to generate an internal query request to the PDO
    irp = IoAllocateIrp(PdoDeviceObject->StackSize, FALSE);

    if (!irp) {
        return STATUS_INSUFFICIENT_RESOURCES;
    }


    // IoGetNextIrpStackLocation gives a higher level driver access to the next-lower
    // driver\'s I/O stack location in an IRP so the caller can set it up for the lower driver.
    nextStack = IoGetNextIrpStackLocation(irp);
    ISOUSB_ASSERT(nextStack != NULL);
    nextStack->MajorFunction= IRP_MJ_PNP;
    nextStack->MinorFunction= IRP_MN_QUERY_CAPABILITIES;

    // init an event to tell us when the completion routine\'s been called
    KeInitializeEvent(&event, NotificationEvent, FALSE);

    // Set a completion routine so it can signal our event when
    //  the next lower driver is done with the Irp
    IoSetCompletionRoutine(irp,
                           IsoUsb_IrpCompletionRoutine,
                           &event,  // pass the event as Context to completion routine
                           TRUE,    // invoke on success
                           TRUE,    // invoke on error
                           TRUE);   // invoke on cancellation of the Irp


    // set our pointer to the DEVICE_CAPABILITIES struct
    nextStack->Parameters.DeviceCapabilities.Capabilities = DeviceCapabilities;

    ntStatus = IoCallDriver(PdoDeviceObject,
                            irp);

    ISOUSB_KdPrint( DBGLVL_MEDIUM,(\" IsoUsb_QueryCapabilities() ntStatus from IoCallDriver to PCI = 0x%x\\n\", ntStatus));

    if (ntStatus == STATUS_PENDING) {
       // wait for irp to complete

       KeWaitForSingleObject(
            &event,
            Suspended,
            KernelMode,
            FALSE,
            NULL);
    }

    // failed? this is probably a bug
    ISOUSB_KdPrintCond( DBGLVL_DEFAULT,(!NT_SUCCESS(ntStatus)), (\"IsoUsb_QueryCapabilities() failed\\n\"));

    IoFreeIrp(irp);

    return ntStatus;
}
犯强汉者,虽远必诛! [img]http://www.driverdevelop.com/forum/upload/tigerzd/2002-12-13_sf10.JPG[/img]
游客

返回顶部