How can I get properties of "Windows Interface" for OneNote 2016 (Win32 Desktop Client)?

%3CLINGO-SUB%20id%3D%22lingo-sub-1376513%22%20slang%3D%22en-US%22%3EHow%20can%20I%20get%20properties%20of%20%22Windows%20Interface%22%20for%20OneNote%202016%20(Win32%20Desktop%20Client)%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1376513%22%20slang%3D%22en-US%22%3E%3CP%3EHow%20can%20I%20get%20properties%20of%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice%2Fclient-developer%2Fonenote%2Fwindow-interfaces-onenote%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EWindows%20Interface%3C%2FA%3E%20for%20OneNote%20(2016%20Win32%20Desktop%20Client)%20using%20Powershell%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20this%20PowerShell%20example%2C%20I'm%20trying%20to%20access%20the%20%3CSTRONG%3E%3CEM%3ECurrentPageId%3C%2FEM%3E%3C%2FSTRONG%3E%20of%20%3CSTRONG%3E%3CEM%3ECurrentWindow%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24OneNote%20%3D%20New-Object%20-ComObject%20OneNote.Application%0AWrite-Output%20%24OneNote.Windows.CurrentWindow.CurrentPageId%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%2C%20I%20get%20empty%20string.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20this%20PowerShell%20example%2C%20I'm%20trying%20to%20access%20the%20%3CSTRONG%3E%3CEM%3ECurrentPageId%3C%2FEM%3E%3C%2FSTRONG%3E%20of%20%3CSTRONG%3E%3CEM%3ECurrentWindow%26nbsp%3B%3C%2FEM%3E%3C%2FSTRONG%3Eanother%20way%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24OneNote%20%3D%20New-Object%20-ComObject%20OneNote.Application%0A%24binding%20%3D%20%22System.Reflection.BindingFlags%22%20-as%20%5Btype%5D%0A%24active_window%20%3D%20%5BSystem.__ComObject%5D.InvokeMember(%22CurrentWindow%22%2C%20%24binding%3A%3AGetProperty%2C%20%24null%2C%20%24OneNote%2C%20%24null)%0A%24active_window_pageId%20%3D%20%5BSystem.__ComObject%5D.InvokeMember(%22CurrentPageId%22%2C%20%24binding%3A%3AGetProperty%2C%20%24null%2C%20%24active_window%2C%20%24null)%0AWrite-Output%20%24active_window_pageId%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20I%20get%20errors%20(%3CA%20href%3D%22https%3A%2F%2Fpastebin.com%2FUCmRzG69%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Edetailed%20output%20on%20Pastepin%3C%2FA%3E%3A(%3C%2Fimg%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EException%20calling%20%22InvokeMember%22%20with%20%225%22%20argument(s)%3A%20%22Library%20not%20registered.%20(Exception%20from%20HRESULT%3A%200x8002801D%20(TYPE_E_LIBNOTREGISTERED))%22%0AException%20calling%20%22InvokeMember%22%20with%20%225%22%20argument(s)%3A%20%22Method%20'System.__ComObject.CurrentPageId'%20not%20found.%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20this%20example%2C%20I'm%20trying%20to%20access%20%3CSTRONG%3E%3CEM%3ECurrentPageId%3C%2FEM%3E%3C%2FSTRONG%3E%20of%20all%20open%20OneNote%20windows%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24OneNote%20%3D%20New-Object%20-ComObject%20OneNote.Application%0A%24binding%20%3D%20%22System.Reflection.BindingFlags%22%20-as%20%5Btype%5D%0Aforeach%20(%24window%20in%20%24OneNote.Windows)%20%7B%0A%20%20%24page_id%20%3D%20%5BSystem.__ComObject%5D.InvokeMember(%22CurrentPageId%22%2C%20%24binding%3A%3AGetProperty%2C%20%24null%2C%20%24window%2C%20%24null)%0A%20%20Write-Output%20%24page_id%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20get%20similar%20error%3CSPAN%3E%26nbsp%3Bfor%20each%20of%206%20active%20OneNote%20windows%26nbsp%3B(%3CA%20href%3D%22https%3A%2F%2Fpastebin.com%2FrHgf8xy0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Edetailed%20output%20on%20Pastepin%3C%2FA%3E)%3C%2FSPAN%3E%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EException%20calling%20%22InvokeMember%22%20with%20%225%22%20argument(s)%3A%20%22Library%20not%20registered.%20(Exception%20from%20HRESULT%3A%200x8002801D%20(TYPE_E_LIBNOTREGISTERED))%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20using%20Windows%2010%2C%20and%20have%20OneNote%202016%26nbsp%3B(Win32%20Desktop%20Client).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1376513%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3E.Net%20Core%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAPI%20Management%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
Visitor

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).

 

 

0 Replies