May 09 2020 06:35 AM - edited May 09 2020 07:47 AM
How can I get properties of Windows Interface for OneNote (2016 Win32 Desktop Client) using Powershell?
In this PowerShell example, I'm trying to access the CurrentPageId of CurrentWindow
$OneNote = New-Object -ComObject OneNote.Application
Write-Output $OneNote.Windows.CurrentWindow.CurrentPageId
But, I get empty string.
In this PowerShell example, I'm trying to access the CurrentPageId of CurrentWindow another way:
$OneNote = New-Object -ComObject OneNote.Application
$binding = "System.Reflection.BindingFlags" -as [type]
$active_window = [System.__ComObject].InvokeMember("CurrentWindow", $binding::GetProperty, $null, $OneNote, $null)
$active_window_pageId = [System.__ComObject].InvokeMember("CurrentPageId", $binding::GetProperty, $null, $active_window, $null)
Write-Output $active_window_pageId
But I get errors (detailed output on Pastepin:(
Exception calling "InvokeMember" with "5" argument(s): "Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))"
Exception calling "InvokeMember" with "5" argument(s): "Method 'System.__ComObject.CurrentPageId' not found."
In this example, I'm trying to access CurrentPageId of all open OneNote windows
$OneNote = New-Object -ComObject OneNote.Application
$binding = "System.Reflection.BindingFlags" -as [type]
foreach ($window in $OneNote.Windows) {
$page_id = [System.__ComObject].InvokeMember("CurrentPageId", $binding::GetProperty, $null, $window, $null)
Write-Output $page_id
}
I get similar error for each of 6 active OneNote windows (detailed output on Pastepin):
Exception calling "InvokeMember" with "5" argument(s): "Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))"
I'm using Windows 10, and have OneNote 2016 (Win32 Desktop Client).