gpt4 book ai didi

c++ - 如何限制 MFC 应用程序仅从已知的 USB 闪存驱动器运行

转载 作者:行者123 更新时间:2023-11-30 04:28:06 24 4
gpt4 key购买 nike

我想制作一个只能从已知 USB 闪存驱动器运行的 MFC 应用程序。如果我们复制到其他地方,它不应该运行。我在 here 发现了类似这样的问题但我真的不明白。请给我提示。

最佳答案

在 MFC 中:GetFileInformationByHandle

 BY_HANDLE_FILE_INFORMATION info;
DWORD dwSerialNumber = 0;

if(GetFileInformationByHandle(FileHandle, &info) != 0)
{
dwSerialNumber = info.dwVolumeSerialNumber;
swprintf(szTemp, L"The Volume Serial Number = %d", info.dwVolumeSerialNumber);
MessageBox(NULL, szTemp, L"Success", MB_OK);
}
else
{
swprintf(szTemp, L"GetFileInformationByHandle Error = %d", GetLastError());
MessageBox(NULL, szTemp, L"Success", MB_OK);
}

在 C#/C++.NET 中:使用 WMI USB 驱动器的内部序列号。

试试这个代码,如果没有序列号,是因为有的U盘有,有的没有。

//import the System.Management namespace at the top in your "using" statement. Then in a method, or on a button click:

ManagementObjectSearch theSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive WHERE InterfaceType='USB'");
foreach (ManagementObject currentObject in theSearcher.Get())
{
ManagementObject theSerialNumberObjectQuery = new ManagementObject("Win32_PhysicalMedia.Tag='" + currentObject["DeviceID"] + "'");
MessageBox.Show(theSerialNumberObjectQuery["SerialNumber"].ToString());
}

关于c++ - 如何限制 MFC 应用程序仅从已知的 USB 闪存驱动器运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10426229/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com