本文介绍了允许表单仅在笔驱动程序内打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是确定我的笔式驱动程序,并且只有当exe文件在其中时才允许打开表单。



我有什么试过:



What I would like to do is identify my pen driver and allow the form to open only if the exe is inside it.

What I have tried:

Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher("SELECT * FROM Win32_volume")
       Dim drive As Integer
       For Each wmi_USB As ManagementObject In searcher.Get()
           If (wmi_USB("SerialNumber")) = "1820527542" Then
               drive = 1
               Exit For
           End If
       Next
       If Not drive = 1 Then
           MsgBox("Error - The pendriver was not found!", MsgBoxStyle.Critical, "title")
           Me.Close()
       End If

推荐答案

Dim RemoveableDrives = DriveInfo.GetDrives().Where(Function(x) x.DriveType=DriveType.Removable).ToList()
For Each d As DriveInfo In RemoveableDrives
    Console.WriteLine(" Drive name: {0} type: {1}", d.Name, d.DriveType)
    If d.IsReady = True Then
        Console.WriteLine("  Volume label: {0}", d.VolumeLabel)
        Console.WriteLine("  File system: {0}", d.DriveFormat)
        Console.WriteLine("  Available space to current user:{0, 15} bytes", d.AvailableFreeSpace)
        Console.WriteLine("  Total available space: {0, 15} bytes", d.TotalFreeSpace)
        Console.WriteLine("  Total size of drive: {0, 15} bytes ", d.TotalSize)
    End If
Next





现在,您必须检查 []是一个可移动的驱动器。



Now, you have to check if drive of Application.StartupPath Property (System.Windows.Forms)[^] is a removable drive.


这篇关于允许表单仅在笔驱动程序内打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 20:07