Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Validating VB6 Function 19 56
vb6 connector to SQL Server 2 34
Exit a vb6 apps when a calling it apps closes 15 43
Visual Studio search word table and return Cell index 8 48
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now