Jump to content

How to determine file that's open in WordPad?


qwert
 Share

Recommended Posts

Would anyone know how a script can read the path and filename of the document that is open in a WordPad window?

What I thought would be forthright now seems to be difficult, maybe impossible.  I've found a (very) few posts from three years ago that are in the ballpark of "determining the active file of a window" ... but no clear method was identified.  Maybe I've used poor search terms, but nothing has turned up.

The only registry entries I can find are for the Last 10 files ... and the current file isn't listed.

Any help will be appreciated.

 

Edited by qwert
Link to comment
Share on other sites

I found sometimes (not always) the current file will be saved to a default directory and not to the original directory that the current file is from.  
Saving the current file in WordPad before running this example guarantees the full path of the current file is returned from the example.

May be someone will come along with a better way to get the path and file name of the document that is open in a WordPad window.

; Read the path and filename of the document that is open in a WordPad window.

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

;ConsoleWrite(ProcessClose(ProcessExists("WordPad.exe")) & @LF) ; Close hidden WordPad

If WinExists("WordPad") Then
    ConsoleWrite("From Title: " & StringRegExpReplace(WinGetTitle("WordPad", ""), " - WordPad", "") & @LF)

    WinActivate(" - WordPad", "")
    WinWaitActive(" - WordPad", "")
    Send("!f") ; Open File menu
    Send("!a") ; Open SaveAs window
    WinWaitActive("Save As", "")
    Local $sRet = ControlGetText("Save As", "", "ToolbarWindow323") & "\" & ControlGetText("Save As", "", "Edit1") ; Gets Full Path & File Name.
    ConsoleWrite("Current WordPad File: " & StringRegExpReplace($sRet, "^(Address:\h)*", "") & @LF)
    ControlClick("Save As", "", "Button3") ; Close SaveAs window
EndIf


; ============ Recent File List ================
Local $sVar, $sRecentList, $iCount = 1
Do
    $sVar = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Wordpad\Recent File List", "File" & $iCount)
    If @error Then
        ExitLoop
    Else
        $sRecentList &= $sVar & @LF
        $iCount += 1
    EndIf
Until 0
ConsoleWrite(@LF & "Recent WordPad Files:" & @LF & $sRecentList & @LF)

 

Link to comment
Share on other sites

It might also be possible to get on OLE interface or object associated with wordpad, but of course a COM witchdoctor would only know or sure.

Take a look in registry, and find HKEY_CLASSES_ROOT\CLSID\{73FDDC80-AEA9-101A-98A7-00AA00374959}

It has a progid of Wordpad.Document.1

Unfortunately 

$ObjWordpad = ObjGet("", "Wordpad.Document.1")

If IsObj($ObjWordpad) Then
    MsgBox(0,0,0)
EndIf

Does not appear to work, nor does its ObjCreate counterpart.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

maybe WordPad use some kind of MRU ?

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

maybe WordPad use some kind of MRU ?

 

try this concept:

#include <WinAPIFiles.au3>
_Example()
Func _Example()
    Local $sFilePath = RegRead ( "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Wordpad\Recent File List", "File1" )
    If Not @error then 
        MsgBox(0, '', _WinAPI_FileInUse ( $sFilePath ))
    EndIf
EndFunc

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

This is my Concept.

Its working, but limited as I have no idea how to get an object for the current Document and such.  I am fairly new to this.  

#Include <Word.au3>
Local $sDocument = @ScriptDir & "\TestDoc.docx"
Local $oWord = _Word_Create()
Local $oDoc = _Word_DocOpen($oWord, $sDocument, Default, Default, True)
MsgBox(0, "", $oDoc.Path & "\" & $oDoc.Name)
_Word_Quit($oWord)

 

Edit This Works Also:

#Include <Word.au3>
Local $sDocument = @ScriptDir & "\TestDoc.docx"
Local $oWord = _Word_Create()
Local $oDoc = _Word_DocOpen($oWord, $sDocument, Default, Default, True)
MsgBox(0, "", $oDoc.FullName)
_Word_Quit($oWord)

 

Edit Again: I found what I was looking for by taking apart Waters UDF and seeing how it works, but I also actually read the first post and noticed the small detail WordPad not MS Word :(  At anyrate incase anybody wants to know how to do it for Word this is working great for me.

$oAppl = ObjGet("", "Word.Application")
$oDocument = $oAppl.ActiveDocument
MsgBox(0, "", $oDocument.FullName)

 

Edited by ViciousXUSMC
Link to comment
Share on other sites

From the help file:

#AutoIt3Wrapper_UseX64=y ;adjust this according to your os architecture
#RequireAdmin

#include <Array.au3>
#include <WinAPI.au3>
#include <WinAPIProc.au3>

Local $aAdjust, $aList = 0

; Enable "SeDebugPrivilege" privilege for obtain full access rights to another processes
Local $hToken = _WinAPI_OpenProcessToken(BitOR($TOKEN_ADJUST_PRIVILEGES, $TOKEN_QUERY))

_WinAPI_AdjustTokenPrivileges($hToken, $SE_DEBUG_NAME, $SE_PRIVILEGE_ENABLED, $aAdjust)

; Retrieve command-line arguments for all processes the system
If Not (@error Or @extended) Then
    $aList = ProcessList("wordpad.exe")
    For $i = 1 To $aList[0][0]
        $aList[$i][1] = _WinAPI_GetProcessCommandLine($aList[$i][1])
    Next
EndIf

; Enable SeDebugPrivilege privilege by default
_WinAPI_AdjustTokenPrivileges($hToken, $aAdjust, 0, $aAdjust)
_WinAPI_CloseHandle($hToken)

_ArrayDisplay($aList, '_WinAPI_GetProcessCommandLine')

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

@UEZ: Excellent find!  Not as simple as what I'd hoped ... but it does the job.  Below is the result I got with two occurrences of WordPad open.  The first entry is for a New document that hasn't yet be saved.  The second is for an opened document.

Filepaths.thumb.PNG.21377be8c96f5bc1a718

One caveat from the help file:  "This function uses undocumented API functions and may stop working properly in future versions of Windows."

Thanks very much for your response!

 

Link to comment
Share on other sites

Indeed, a file opened from inside WordPad doesn't show up.  I had used a double-click operation to open the one in my earlier example,  Here's the result of a 3rd file that was just opened:

Alas.thumb.PNG.0083f2870e4f889b13722a515

So I guess I'm back to square one on a direct method.

On a related note, however, I uncovered this rather obscure feature of windows that provides a copy/paste method in some circumstances:

To copy the full path for an individual file, hold down the Shift key as you right-click the file, and then choose Copy As Path.

Copy_as_path.thumb.png.f9f64676c7437e1c4

... which does work and might form the basis of some other method.

Thanks for all the responses.

 

 

Edited by qwert
Link to comment
Share on other sites

Here's something that almost works:

; Read the path and filename of the document that is open in a WordPad window.
#include <WinAPIFiles.au3>

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

If WinExists("WordPad") Then
    WinActivate(" - WordPad", "")
    WinWaitActive(" - WordPad", "")
    ConsoleWrite("From Title: " & StringRegExpReplace(WinGetTitle("WordPad", ""), " - WordPad", "") & @LF)
EndIf

$dir = _WinAPI_GetCurrentDirectory ( )
ConsoleWrite("From Dir: " & $dir & @LF)

Exit

The problem is: it reports the current directory for my script ... not for the active window.  Would anyone have a suggestion of how to redirect the GetCurrentDirectory operation?

 

 

Link to comment
Share on other sites

The example I gave isolates the proper file name.  If the GetCurrentDirectory could be made to operate on the active window, that would give the proper path. 

I'm sorry if that wasn't clear.

 

Edited by qwert
Link to comment
Share on other sites

I still don't see how that will help you at all.

Here is a link which contains C++ code to get the Current Directory of process.

I believe translating it to AutoIt for this purpose is a waste of someone's time, so it will not be mine.

http://stackoverflow.com/questions/14018280/how-to-get-a-process-working-dir-on-windows

Do keep us informed though.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

This is a really heavy artillery. Are there no simpler way to do this? – Yury
Not to my best knowledge. –  Anton

Thanks for the link.  I think Yury and Anton have it right, though.  But maybe another method will turn up.

 

 

 

Edited by qwert
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...