Solved

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

Posted on 2004-04-22
5
143 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

777 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