Detecting a Laptop in LotusScript (on Windows)
by florian vogler :: Lotus Notes Client Management | LotusScript
Have you ever needed to detect whether a particular piece of LotusScript code runs on a Laptop?
Instead of having to maintain groups in the Lotus Notes Names- and Addressbook, or going down the path of deriving this from the computername, you can easily detect this on Windows (NT4SP4 and up) using WMI (Windows Management Instrumentations).
As opposed to groups, this Script works perfectly on as many computers a single user may have (using groups, any scriptcode would behave the same for an end user on all her/his computers).
The following script simply asks windows whether the computer it is running on is identified as a computer with a battery bay.
This LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.
The only thing to watch out for in this script is that it also identifies workstations with a UPS (uninterruptable power supply) as "Laptops".
Whilst the WMI class CMI_Battery (as opposed to the one used, which is Win32_Battery) would solve this problem, as it only reports existing batteries, removing a battery from a Laptop would then report it as a "Desktop". Even more problematic in this context is the fact that IBM Notebooks, for example, hide the battery from the OS (ok, I guess the OS hides it from whatever) for charge optimization and thus would wrongly be identified as "Desktops" from time to time.
Using the Win32_Battery WMI class ensures that Laptops are always correctly identified, regardless of whether the battery is actually inserted or not, or "hidden from the OS".
There is *a lot* more that you can do with WMI, I'll post more examples in the next few days ...
Instead of having to maintain groups in the Lotus Notes Names- and Addressbook, or going down the path of deriving this from the computername, you can easily detect this on Windows (NT4SP4 and up) using WMI (Windows Management Instrumentations).
As opposed to groups, this Script works perfectly on as many computers a single user may have (using groups, any scriptcode would behave the same for an end user on all her/his computers).
The following script simply asks windows whether the computer it is running on is identified as a computer with a battery bay.
Sub Initialize On Error Goto error_handler Set s = New notessession 'Instantiates a WMI object Dim objWMIService As Variant Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") 'Just for info (JFI): replacing the . (dot) in above parameter with an IP-Address 'would query the computer with that IP-Address! So, for example, 'Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\192.168.0.1\root\cimv2") 'would do a WMI query on a remote computer with the IP-Address 192.168.0.1 Dim colItems As Variant 'This is where we specify the WMI-Query; 'there are tons of examples on the web - search for "WMI and vb" (vb for visual basic) Set colItems = objWMIService.ExecQuery("Select * from Win32_Battery") Dim flg_is_laptop As Integer Dim n_result_length As Integer Forall objItem In colItems 'the objitem data structure and results obtainable from it depend on the query - see MSDN for more 'for more see http://msdn2.microsoft.com/en-us/library/aa394572(VS.85).aspx 't_result=objItem.Description 'the possible results and further details of this particular WMI query can be found at 'http://msdn2.microsoft.com/en-us/library/aa394074.aspx n_result_length=Len(objItem.Description) If n_result_length <> 0 Then flg_is_laptop=1 Else flg_is_laptop=0 End If End Forall If flg_is_laptop=1 Then Messagebox "This is a laptop OR a workstation with a UPS." Else Messagebox "This is desktop (without UPS)" End If Exit Sub error_handler: Messagebox "Error " & Err & " in Line " & Erl & ": " & Error End Sub
provided by Julian Robichaux at nsftools.com.
The only thing to watch out for in this script is that it also identifies workstations with a UPS (uninterruptable power supply) as "Laptops".
Whilst the WMI class CMI_Battery (as opposed to the one used, which is Win32_Battery) would solve this problem, as it only reports existing batteries, removing a battery from a Laptop would then report it as a "Desktop". Even more problematic in this context is the fact that IBM Notebooks, for example, hide the battery from the OS (ok, I guess the OS hides it from whatever) for charge optimization and thus would wrongly be identified as "Desktops" from time to time.
Using the Win32_Battery WMI class ensures that Laptops are always correctly identified, regardless of whether the battery is actually inserted or not, or "hidden from the OS".
There is *a lot* more that you can do with WMI, I'll post more examples in the next few days ...
Comments
Norman Cox, 2008-03-31 14:55