1
NOTE: Required Drivers for GSM Modem should be installed first.
First Import System.Management in your project References. to import this,
right click on References then click on add References then select assemblies from left sidebar and search for System.Management, select it and add.
and use this namespace
using System.Management;
now You can fetch GSM Devices List connected to your laptop using WMI Query
ManagementObjectSearcher devices = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM win32_SerialPort");
then connect it using SerialPort Class.
// Pass COM Port to SerialPort object.
System.IO.Ports.SerialPort _Port = new System.IO.Ports.SerialPort("COM4");
complete code is attached.