GVKun编程网logo

在Windows上检测插入的USB(windows检测到)

11

在本文中,我们将为您详细介绍在Windows上检测插入的USB的相关知识,并且为您解答关于windows检测到的疑问,此外,我们还会提供一些关于android–如何在Windows7上安装NexusO

在本文中,我们将为您详细介绍在Windows上检测插入的USB的相关知识,并且为您解答关于windows检测到的疑问,此外,我们还会提供一些关于android – 如何在Windows 7上安装Nexus One的USB驱动程序以进行调试?、android – 检测插入的USB设备、c – 如何在Windows上检测QtCreator中的内存泄漏?、c# – 在Windows 10中部署Windows Phone 8.1应用程序时找不到IpOverUsbSvc的有用信息。

本文目录一览:

在Windows上检测插入的USB(windows检测到)

在Windows上检测插入的USB(windows检测到)

我目前正在用python编写一个安全程序,该程序在主机上作为守护程序运行。每当检测到USB存储设备时,它都会将所有文件从USB复制到主机上的某个目录中。有什么简单的方法可以进行这种USB检测/接口?提前致谢!

答案1

小编典典

是的,您需要使用RegisterDeviceNotificationWindows
API调用。据我所知,没有包装此功能的Python模块,因此您必须使用它ctypes来调用此功能。

幸运的是,您不是第一个想要这样做的人,因此网上有一些代码示例。WxPython提供了一个代码示例,但是当您编写守护程序时,您可能对此并不感兴趣。您可能想尝试下面的代码示例,该示例依赖于ctypespywin32,从Tim
Golden毫不客气地进行了研究:

import win32serviceutilimport win32serviceimport win32eventimport servicemanagerimport win32guiimport win32gui_structstruct = win32gui_struct.structpywintypes = win32gui_struct.pywintypesimport win32conGUID_DEVINTERFACE_USB_DEVICE = "{A5DCBF10-6530-11D2-901F-00C04FB951ED}"DBT_DEVICEARRIVAL = 0x8000DBT_DEVICEREMOVECOMPLETE = 0x8004import ctypes## Cut-down clone of UnpackDEV_BROADCAST from win32gui_struct, to be# used for monkey-patching said module with correct handling# of the "name" param of DBT_DEVTYPE_DEVICEINTERFACE#def _UnpackDEV_BROADCAST (lparam):  if lparam == 0: return None  hdr_format = "iii"  hdr_size = struct.calcsize (hdr_format)  hdr_buf = win32gui.PyGetMemory (lparam, hdr_size)  size, devtype, reserved = struct.unpack ("iii", hdr_buf)  # Due to x64 alignment issues, we need to use the full format string over  # the entire buffer.  ie, on x64:  # calcsize(''iiiP'') != calcsize(''iii'')+calcsize(''P'')  buf = win32gui.PyGetMemory (lparam, size)  extra = {}  if devtype == win32con.DBT_DEVTYP_DEVICEINTERFACE:    fmt = hdr_format + "16s"    _, _, _, guid_bytes = struct.unpack (fmt, buf[:struct.calcsize(fmt)])    extra[''classguid''] = pywintypes.IID (guid_bytes, True)    extra[''name''] = ctypes.wstring_at (lparam + struct.calcsize(fmt))  else:    raise NotImplementedError("unknown device type %d" % (devtype,))  return win32gui_struct.DEV_BROADCAST_INFO(devtype, **extra)win32gui_struct.UnpackDEV_BROADCAST = _UnpackDEV_BROADCASTclass DeviceEventService (win32serviceutil.ServiceFramework):  _svc_name_ = "DevEventHandler"  _svc_display_name_ = "Device Event Handler"  _svc_description_ = "Handle device notification events"  def __init__(self, args):    win32serviceutil.ServiceFramework.__init__ (self, args)    self.hWaitStop = win32event.CreateEvent (None, 0, 0, None)    #    # Specify that we''re interested in device interface    # events for USB devices    #    filter = win32gui_struct.PackDEV_BROADCAST_DEVICEINTERFACE (      GUID_DEVINTERFACE_USB_DEVICE    )    self.hDevNotify = win32gui.RegisterDeviceNotification (      self.ssh, # copy of the service status handle      filter,      win32con.DEVICE_NOTIFY_SERVICE_HANDLE    )  #  # Add to the list of controls already handled by the underlying  # ServiceFramework class. We''re only interested in device events  #  def GetAcceptedControls(self):    rc = win32serviceutil.ServiceFramework.GetAcceptedControls (self)    rc |= win32service.SERVICE_CONTROL_DEVICEEVENT    return rc  #  # Handle non-standard service events (including our device broadcasts)  # by logging to the Application event log  #  def SvcOtherEx(self, control, event_type, data):    if control == win32service.SERVICE_CONTROL_DEVICEEVENT:      info = win32gui_struct.UnpackDEV_BROADCAST(data)      #      # This is the key bit here where you''ll presumably      # do something other than log the event. Perhaps pulse      # a named event or write to a secure pipe etc. etc.      #      if event_type == DBT_DEVICEARRIVAL:        servicemanager.LogMsg (          servicemanager.EVENTLOG_INFORMATION_TYPE,          0xF000,          ("Device %s arrived" % info.name, '''')        )      elif event_type == DBT_DEVICEREMOVECOMPLETE:        servicemanager.LogMsg (          servicemanager.EVENTLOG_INFORMATION_TYPE,          0xF000,          ("Device %s removed" % info.name, '''')        )  #  # Standard stuff for stopping and running service; nothing  # specific to device notifications  #  def SvcStop(self):    self.ReportServiceStatus (win32service.SERVICE_STOP_PENDING)    win32event.SetEvent (self.hWaitStop)  def SvcDoRun(self):    win32event.WaitForSingleObject (self.hWaitStop, win32event.INFINITE)    servicemanager.LogMsg (      servicemanager.EVENTLOG_INFORMATION_TYPE,      servicemanager.PYS_SERVICE_STOPPED,      (self._svc_name_, '''')    )if __name__==''__main__'':  win32serviceutil.HandleCommandLine (DeviceEventService)

android – 如何在Windows 7上安装Nexus One的USB驱动程序以进行调试?

android – 如何在Windows 7上安装Nexus One的USB驱动程序以进行调试?

我已经实现了一个简单的 Android应用程序,我现在想在真实设备上进行测试.我有一个Nexus One.

在Android Eclipse插件中,我已经下载并安装了USB驱动程序(修订版3)包.但是当我使用USB线将Nexus One连接到我的PC(运行Windows 7)时,会弹出一个消息框,显示“Nexus One”找不到“找不到驱动程序”.

我已在设备上激活USB调试.当我在我的PC上运行adb设备时,它只打印附加的设备列表,并且没有列出任何设备.如果我在Windows中使用设备管理,并尝试更新“Nexus One”的驱动程序,我无法在Android SDK的“驱动程序目录”中选择驱动程序.

如何在Windows 7上安装Nexus One的驱动程序,以便在真实设备上使用它来调试我的Android应用程序?

解决方法

http://developer.android.com/sdk/win-usb.html

The USB driver for Windows is a downloadable component for the Android SDK. If you are developing on Windows and would like to connect an Android-powered device to test your applications,then you will need to install the USB driver.

This document provides information about the latest version of the USB driver and a guide to installing the driver on your development computer.

USB Driver for Windows,Revision 3 (January 2010)
Adds support for the Nexus One.

The USB Driver for Windows is
available for download as an optional
SDK component. You need the driver
only if you are developing on Windows
and want to connect an Android-powered
device to your development environment
over USB.

To install the driver or upgrade your
existing driver to the latest
revision,you must first download the
driver to your development computer.

To download the driver,use the
Android SDK and AVD Manager tool that
is included with the Android SDK. If
you haven’t yet installed the Android
SDK,as described in 07001,please do so before
continuing with the driver
installation.

When you are ready to download the
driver,follow the instructions given
in 07002 to launch the
Android SDK and AVD Manager. From the
Available Packages panel,select “Usb
Driver Package” and download it to
your computer. The driver files are
downloaded into the <sdk>\usb_driver
directory.

After the download,follow the
instructions below to install or
upgrade the driver,based on your
needs and Windows operating system
version. If you are connecting an
Android-powered device to your
computer for the first time,follow
the below procedure to “Perform a
fresh installation.” If you have
installed one of the older USB drivers
and would like to upgrade to the
latest version,follow the procedure
to “Upgrade an existing driver.”

Once you’ve completed the USB driver installation,please see 07003 for other important information about using an Android-powered device for development.

android – 检测插入的USB设备

android – 检测插入的USB设备

我想知道,系统的哪个部分负责检测USB端口中的插入设备

它可能是USB主机端口,因此插入的设备将被视为USB客户端(因此端口所有者是主机),
或者它可能是USB客户端端口,因此插入的设备将被视为USB主机(因此端口所有者是客户端)

我感兴趣的是当系统实际检测到(通过改变电阻)插入某些东西,并根据信号来自哪个端口(主机端口或客户端端口),主机端口驱动程序或部署客户端端口驱动程序
我想知道,系统如何根据“插入”事件选择这个或那个驱动程序

我应该在哪里找那个?在USB核心可能吗?

最佳答案
我理解你在问什么,正确地当连接USB设备时,电流波动(跨电阻)会导致通知.然后是主机(可以协商谁将在OTG模式下托管,但也会在枚举过程后发生).

枚举是最重要的主要过程. USB遵循星级层拓扑,整个系统基于相同.

注意:请务必注意,数据包的所有事务都由主机启动.客户受主人的怜悯.这对于理解usb系统非常重要.

请参考:http://www.beyondlogic.org/usbnutshell/usb1.shtml

c – 如何在Windows上检测QtCreator中的内存泄漏?

c – 如何在Windows上检测QtCreator中的内存泄漏?

如何在 Windows上检测QtCreator中的内存泄漏?在文档中,他们建议使用Memcheck,但它只适用于Mac和 Linux.任何Windows的建议?

解决方法

所以经过很多尝试,我终于找到了一种方法来检测Windows上Qt项目的内存泄漏:

1)首先,它不能直接在Qt Creator中完成,因此您需要创建一个Visual C项目来进行内存泄漏检测.幸运的是,qmake使这很容易.打开Qt SDK命令行工具并运行:

qmake -spec win32-msvc2008 -tp vc

这将将您的项目转换为.vcproj.

2)打开此项目并添加内存泄漏检测所需的代码:

到你的main.cpp文件:

// Necessary includes and defines for memory leak detection:
#ifdef _MSC_VER
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#endif // _MSC_VER


#if defined(_MSC_VER)

// Code to display the memory leak report
// We use a custom report hook to filter out Qt's own memory leaks
// Credit to Andreas Schmidts - http://www.schmidt-web-berlin.de/winfig/blog/?p=154

_CRT_REPORT_HOOK prevHook;

int customreportHook(int /* reportType */,char* message,int* /* returnValue */) {
  // This function is called several times for each memory leak.
  // Each time a part of the error message is supplied.
  // This holds number of subsequent detail messages after
  // a leak was reported
  const int numFollowupDebugMsgParts = 2;
  static bool ignoreMessage = false;
  static int debugMsgPartsCount = 0;

  // check if the memory leak reporting starts
  if ((strncmp(message,"Detected memory leaks!\n",10) == 0)
    || ignoreMessage)
  {
    // check if the memory leak reporting ends
    if (strncmp(message,"Object dump complete.\n",10) == 0)
    {
      _CrtSetReportHook(prevHook);
      ignoreMessage = false;
    } else
      ignoreMessage = true;

    // something from our own code?
    if(strstr(message,".cpp") == NULL)
    {
      if(debugMsgPartsCount++ < numFollowupDebugMsgParts)
        // give it back to _CrtDbgReport() to be printed to the console
        return FALSE;
      else
        return TRUE;  // ignore it
    } else
    {
      debugMsgPartsCount = 0;
      // give it back to _CrtDbgReport() to be printed to the console
      return FALSE;
    }
  } else
    // give it back to _CrtDbgReport() to be printed to the console
    return FALSE;
}

#endif



int main(int argc,char *argv[]) {
    #if defined(_MSC_VER)
    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
    prevHook = _CrtSetReportHook(customreportHook);
    // _CrtSetBreakAlloc(157); // Use this line to break at the nth memory allocation
    #endif

    QApplication* app = new QApplication(argc,argv);   
    int appError = app->exec();
    delete app;

    #if defined(_MSC_VER)
    // Once the app has finished running and has been deleted,// we run this command to view the memory leaks:
    _CrtDumpMemoryLeaks();
    #endif 

    return appError;
}

3)为此,您的项目现在应该能够检测内存泄漏.注意_MSC_VER定义,以便只有当您从Visual C(而不是来自Qt Creator)运行此代码时才执行此代码.这意味着您仍然可以使用Qt Creator进行开发,只要您需要检查内存泄漏,就重新运行步骤1.

4)要打破特定的内存分配,请使用_CrtSetBreakAlloc()更多信息Microsoft网站上的内存泄漏检测:http://msdn.microsoft.com/en-us/library/e5ewb1h3%28v=vs.80%29.aspx

c# – 在Windows 10中部署Windows Phone 8.1应用程序时找不到IpOverUsbSvc

c# – 在Windows 10中部署Windows Phone 8.1应用程序时找不到IpOverUsbSvc

我正在尝试在 Windows 10中部署 Windows Phone 8.1应用程序.我收到以下错误:

Error : DEP6200 : Boostrapping ‘Device’ Failed. Device cannot be found. Windows Phone IP over USB Transport (IpOverUsbSvc) is not running. Retry after starting Windows Phone IP over USB Transport (IpOverUsbSvc) from the services management console.

Error : DEP6100 : The following unexpected error occurred during boostrapping stage ‘Connecting to the device’:
SmartDeviceException – Windows Phone IP over USB Transport (IpOverUsbSvc) is not running. Retry after starting Windows Phone IP over USB Transport (IpOverUsbSvc) from the services management console.

我的Lumia手机已连接,可从Windows文件资源管理器访问.

我已经检查了IpOverUsbSvc服务的服务,但它不在那里.所以我也检查了powershell:get-service IpOverUsbSvc

Status   Name               displayName
------   ----               -----------
Stopped  IpOverUsbSvc       Windows Phone IP over USB Transport...

我在使用Windows 8.1时没有收到这些错误.似乎此服务在Windows 10中不可用.

任何人都可以帮我解决这个问题吗?

解决方法

当我将我的开发系统从10166升级到10240时,我遇到了类似的问题 – IpOverUsbSvc无法启动.

似乎……在某些情况下,ipoverusbsvc的注册信息已损坏.要修复它,只需将正确的信息放入注册表.

您可以找到ms guy将正确的.reg文件上传到他的onedrive的以下链接.

[UWP][SDK]IpOverUsbSvc service missing in windows 10 RC (Build 10240)

我们今天的关于在Windows上检测插入的USBwindows检测到的分享已经告一段落,感谢您的关注,如果您想了解更多关于android – 如何在Windows 7上安装Nexus One的USB驱动程序以进行调试?、android – 检测插入的USB设备、c – 如何在Windows上检测QtCreator中的内存泄漏?、c# – 在Windows 10中部署Windows Phone 8.1应用程序时找不到IpOverUsbSvc的相关信息,请在本站查询。

本文标签: