Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

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

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
rbender
Asked:
rbender
  • 2
  • 2
1 Solution
 
David LeeCommented:
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
 
rbenderAuthor Commented:
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
 
rbenderAuthor Commented:
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
 
David LeeCommented:
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now