Solved

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

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

762 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

18 Experts available now in Live!

Get 1:1 Help Now