允许表单仅在笔驱动程序内打开 [英] Allow the form to open only inside the pen driver

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

问题描述

我想要做的是确定我的笔式驱动程序,并且只有当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


推荐答案

我建​​议使用 DriveInfo类(System.IO) [ ^ ]



如何获取可移动驱动器列表?

I'd suggest to use DriveInfo Class (System.IO)[^]

How to get list of removable drives?
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





现在,您必须检查 Application.StartupPath Property(System.Windows.Forms) [ ^ ]是一个可移动的驱动器。



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


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆