Solved

I need code to detect if Infared is turned on on a laptop

Posted on 2004-04-22
5
151 Views
Last Modified: 2010-05-02
Can someone give me code that will detect if infared is turned on on a laptop and if so, give me a button that will turn it off?
(maybe one to turn it back on as well?)
0
Comment
Question by:rbender
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 10895814
Here's the code you can use to detect if the notebook has an infrared port and whether it's on or not (along with a lot of other information about the port).  However, according to Microsoft's documentation on using WMI with infrared devices you can't cycle the power.  Here's a link to Microsoft's documentation on this (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_infrareddevice.asp).  Look at SetPowerState.

Private Sub Command1_Click()
    On Error Resume Next
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_InfraredDevice", , 48)
    For Each objitem In colItems
        Debug.Print "Availability: " & objitem.Availability
        Debug.Print "Caption: " & objitem.Caption
        Debug.Print "ConfigManagerErrorCode: " & objitem.ConfigManagerErrorCode
        Debug.Print "ConfigManagerUserConfig: " & objitem.ConfigManagerUserConfig
        Debug.Print "CreationClassName: " & objitem.CreationClassName
        Debug.Print "Description: " & objitem.Description
        Debug.Print "DeviceID: " & objitem.DeviceID
        Debug.Print "ErrorCleared: " & objitem.ErrorCleared
        Debug.Print "ErrorDescription: " & objitem.ErrorDescription
        Debug.Print "InstallDate: " & objitem.InstallDate
        Debug.Print "LastErrorCode: " & objitem.LastErrorCode
        Debug.Print "Manufacturer: " & objitem.Manufacturer
        Debug.Print "MaxNumberControlled: " & objitem.MaxNumberControlled
        Debug.Print "Name: " & objitem.Name
        Debug.Print "PNPDeviceID: " & objitem.PNPDeviceID
        Debug.Print "PowerManagementCapabilities: " & objitem.PowerManagementCapabilities
        Debug.Print "PowerManagementSupported: " & objitem.PowerManagementSupported
        Debug.Print "ProtocolSupported: " & objitem.ProtocolSupported
        Debug.Print "Status: " & objitem.Status
        Debug.Print "StatusInfo: " & objitem.StatusInfo
        Debug.Print "SystemCreationClassName: " & objitem.SystemCreationClassName
        Debug.Print "SystemName: " & objitem.SystemName
        Debug.Print "TimeOfLastReset: " & objitem.TimeOfLastReset
    Next
End Sub
0
 

Author Comment

by:rbender
ID: 10898817
BlueDevilFan
I am developing this on a PC without Infared.
What kind of output should I see on this machine.
I see nothing.
I ever ported the output to a file and it remains empty.
Are there any libraries or componants that I have to install to run this.
Seems it does nothing.
??
0
 

Author Comment

by:rbender
ID: 10898982
Ok...I got a hold of a laptop and tested the code. It works so forget the previous question.

but....if I can't cycle the power, can I disable the infared port and re-enable it using VB?
If so how..
.
0
 
LVL 76

Accepted Solution

by:
David Lee earned 50 total points
ID: 10900665
rbender,

Sorry, I should have mentioned that the code wouldn't do anything unless it found an infrared port.  

There must be some way to disable a port but I can't seem to discover it.  I searched for a way to turn the device off in Device Manager (i.e. Do not use this device in the current hardware profile (disable)), but no luck there.  I also looked for some means of disabling a COM port (i.e. a serial port), since at least on my system the IR port is seen as a serial port.  No joy there either.  I did discover that on my system there's a service called "Infrared Monitor" that says it "Supports infrared devices installed on the computer and detects other devices that are in range."  Assuming it's crucial to using the infrared port, then disabling it would render the IR port unusable.  I do know how to stop a service so if you think that'll do the trick, then I can supply you with the necessary code.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question