This project is read-only.

Add a New Modem Programmatically

May 6, 2011 at 8:49 AM

Hi Jeff,

I wanted to add a new modem in the "Control Panel" > "Phone and Modem Options" > "Modems" tab.

I tried to use the RasDevice.Create method, which requires me to have a Name and a Device Type, but apparently it's not created.  And I'm also wondering if there's a way to specify the COM port for the modem that I want to add?  I'd really be happy to know the correct method that I should use to add a new modem programmatically.

Thanks in advance.

Regards,

Ems

May 9, 2011 at 5:34 PM
Edited May 9, 2011 at 5:36 PM

As indicated in the help documentation, that particular method will not actually "create" new hardware. All it does is create a reference to piece of hardware which may or may not be present on the machine when the code is executed but is expected to be present when the connection is dialed. The reason for this is a piece of hardware can't actually be "created", they can only be installed on a machine.

Normally I would suggest you use the RasDevice.GetDevices method if possible to enumerate through the list of devices the machine says are present, but if the device you expect to use isn't connected at the time the method is called (or if Windows doesn't recognize that it's present which has happened before) the Create method just exposes the ability for you to create the instance of the class that is passed around DotRas for referencing devices.

As for setting device specific values (ie your COM port request), that's outside the scope of this project.

Edit: I wanted to add that if you need to call RasDevice.Create, the device name would match what is registered in Windows, and the device type would be one of the RasDeviceType values.

May 10, 2011 at 2:28 AM

Got it.  Thank you very much Jeff.

I just then resorted to popping up the "Phone and Modem Options" dialog for manually adding the modem.

Once the modem is added, I was then able to create the dialup connection.

Thanks for this project.  Great help! :)