Windows mobile 下讀取手機SIM卡資訊
最近在忙一個移動警務的專案,需要獲取SIM卡的資訊,來做身份的驗證。考慮到獲取:國際移動裝置識別碼(IMEI:International Mobile Equipment Identification Number)和國際移動使用者識別碼(IMSI:International Mobile Subscriber Identification Number),讀取這兩個號碼用到TAPI的lineGetGeneralInfo()函。在新版的OpenNetCF裡沒有發現對這個函式的封裝(也許我沒找到),於是到網上找了找,找到一個以前版本OpenNetCF裡的:TapiLib.dll,包含對Windows ce phone api 的封裝(TAPI),綜合網上的一些資料,實現程式碼如下:
public struct GeneralInfo
{
public string Manufacturer;
public string Model;
public string Revision;
public string SerialNumber;
public string SubscriberNumber;
}
public struct GeneralInfo
{
public string Manufacturer;
public string Model;
public string Revision;
public string SerialNumber;
public string SubscriberNumber;
}
///
/// Tapi控制類
///
public class ControlTapi
{
/// Tapi控制類
///
public class ControlTapi
{
[DllImport("cellcore.dll")]
private static extern int lineGetGeneralInfo(IntPtr hLigne,byte[]lpLineGeneralInfo );
private static extern int lineGetGeneralInfo(IntPtr hLigne,byte[]lpLineGeneralInfo );
///
/// 呼叫cellcore.dll獲取sim卡的綜合資訊
///
///
///
private GeneralInfo GetGeneralInfo(Line l)
{
GeneralInfo lgi = new GeneralInfo();
byte[] buffer = new byte[512];
BitConverter.GetBytes(512).CopyTo(buffer, 0);
/// 呼叫cellcore.dll獲取sim卡的綜合資訊
///
///
///
private GeneralInfo GetGeneralInfo(Line l)
{
GeneralInfo lgi = new GeneralInfo();
byte[] buffer = new byte[512];
BitConverter.GetBytes(512).CopyTo(buffer, 0);
if (lineGetGeneralInfo(l.hLine, buffer) != 0)
{
throw new System.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error(), "TAPI Error: " + System.Runtime.InteropServices.Marshal.GetLastWin32Error().ToString("X"));
}
{
throw new System.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error(), "TAPI Error: " + System.Runtime.InteropServices.Marshal.GetLastWin32Error().ToString("X"));
}
int subscsize = BitConverter.ToInt32(buffer, 44);
int subscoffset = BitConverter.ToInt32(buffer, 48);
lgi.SubscriberNumber = System.Text.Encoding.Unicode.GetString(buffer, subscoffset, subscsize).ToString();
lgi.SubscriberNumber = lgi.SubscriberNumber.Replace("\0", "");
return lgi;
int subscoffset = BitConverter.ToInt32(buffer, 48);
lgi.SubscriberNumber = System.Text.Encoding.Unicode.GetString(buffer, subscoffset, subscsize).ToString();
lgi.SubscriberNumber = lgi.SubscriberNumber.Replace("\0", "");
return lgi;
}
///
/// 獲取sim卡的IMSI
///
///
public static string GetIMSINumber()
{
string result = "";
try
{
Tapi t = new Tapi();
t.Initialize();
Line l = t.CreateLine(0, LINEMEDIAMODE.INTERACTIVEVOICE, OpenNETCF.Tapi.LINECALLPRIVILEGE.MONITOR);
ControlTapi ctapi = new ControlTapi();
GeneralInfo gi = ctapi.GetGeneralInfo(l);
result = gi.SubscriberNumber;
l.Dispose();
t.Shutdown();
/// 獲取sim卡的IMSI
///
///
public static string GetIMSINumber()
{
string result = "";
try
{
Tapi t = new Tapi();
t.Initialize();
Line l = t.CreateLine(0, LINEMEDIAMODE.INTERACTIVEVOICE, OpenNETCF.Tapi.LINECALLPRIVILEGE.MONITOR);
ControlTapi ctapi = new ControlTapi();
GeneralInfo gi = ctapi.GetGeneralInfo(l);
result = gi.SubscriberNumber;
l.Dispose();
t.Shutdown();
}
catch// (Exception ex)
{
result = "";
}
catch// (Exception ex)
{
result = "";
}
return result;
}
///
/// 獲取IMEI的號碼
///
///
public static string GetIMEINumber()
{
string result = "";
try
{
Tapi t = new Tapi();
t.Initialize();
Line l = t.CreateLine(0, LINEMEDIAMODE.INTERACTIVEVOICE, OpenNETCF.Tapi.LINECALLPRIVILEGE.MONITOR);
ControlTapi ctapi = new ControlTapi();
GeneralInfo gi = ctapi.GetGeneralInfo(l);
result = gi.SerialNumber;
l.Dispose();
t.Shutdown();
/// 獲取IMEI的號碼
///
///
public static string GetIMEINumber()
{
string result = "";
try
{
Tapi t = new Tapi();
t.Initialize();
Line l = t.CreateLine(0, LINEMEDIAMODE.INTERACTIVEVOICE, OpenNETCF.Tapi.LINECALLPRIVILEGE.MONITOR);
ControlTapi ctapi = new ControlTapi();
GeneralInfo gi = ctapi.GetGeneralInfo(l);
result = gi.SerialNumber;
l.Dispose();
t.Shutdown();
}
catch// (Exception ex)
{
result = "";
}
catch// (Exception ex)
{
result = "";
}
return result;
}
}
}
vb 的程式碼你可以去看看這裡:http://www.peterfoot.net/RetrieveIMEIThroughTAPI.aspx
另:
1、環境:在vs2005+windows mobile 5.0 +多普達818測試通過。
2、
關於獲取SIM卡的本機號碼,你可以用:http://www.microsoft.com/china/msdn/archives/library/dnnetcomp/html/netcfPhoneAPI.asp,這裡 提供的方法,不過這個方法需要安全認證,比較麻煩,具體認證的方式見:http://www.microsoft.com/china/MSDN/library/Mobility/pocketpc/2k3smartphonesecurity.mspx?pf=true。
3、TapiLib.dll的下載地址:http://files.cnblogs.com/xjb/TapiLib.rar
4、參考資料:
http://hucgy.bokee.com/3328836.html
本文首發地址:http://www.watch-life.net/windows-mobile/windows-mobile-sim.html
----------------------------------------------
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/14766526/viewspace-573378/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Windows Phone 7 SIM卡資訊獲取Windows
- iOS獲取SIM卡資訊iOS
- asp.net讀取Windows域(AD)資訊ASP.NETWindows
- android雙待手機獲取每一張SIM卡的imeiAndroid
- Android獲取手機配置資訊Android
- android 從SIM卡獲取聯絡人資訊Android
- java讀取(華視)刷卡機的刷卡資訊Java
- .net讀取Windows登入使用者資訊(downmoon)Windows
- iOS 之獲取APP與手機 資訊iOSAPP
- Java解析微信獲取手機號資訊Java
- 微軟公佈Win10手機版正式名稱:Windows 10 Mobile微軟Win10Windows
- AdDuplex:執行Windows 10 Mobile的WP手機僅佔15.2%Windows
- windows mobile下的檔案路徑Windows
- windows下讀取Linux分割槽軟體WindowsLinux
- Android如何獲取手機各項資訊Android
- sim卡及手機的密碼詳解密碼
- adb 獲取Android手機資訊命令(1)Android
- 南行取經記(一)重啟Windows Mobile裝置Windows
- 手機管理軟體(syncios mobile manager)iOS
- 如何區分物聯網路卡與手機SIM卡
- uniapp微信小程式獲取手機號 位置資訊APP微信小程式
- c#如何讀取相機手機的拍攝時間C#
- 【Windows Mobile開發系列 之 前言一】被智慧手機新聞報導所吸引Windows
- 堅果手機怎麼裝卡 堅果手機 sim卡安裝圖文教程
- Windows Mobile下非同步使用WinInet庫下載資料Windows非同步
- 手機網頁用Bootstrap還是jQuery Mobile網頁bootjQuery
- JavaScript判斷是否是手機mobile登入JavaScript
- 轉帖:Mobile widget—手機的"門戶"
- angular中$location讀取url資訊Angular
- C#讀取EXIF資訊類C#
- Windows下磁碟只讀Windows
- 360奇酷手機怎麼裝卡 360奇酷手機 sim卡安裝圖文教程
- android系統中獲取imei號和其他手機資訊Android
- 紅米手機3 sim卡安裝教程 紅米3怎麼裝卡
- 蘋果手機使用技巧:iPhone6 Plus怎麼安裝SIM卡?蘋果iPhone
- iOS 獲取裝置uuid,公網ip,手機ip等資訊iOSUI
- Windows環境下的資訊收集Windows
- PowerShell讀取Windows產品金鑰Windows