scsnake Posted April 17, 2008 Posted April 17, 2008 Is there any method to get the full path of a file? ie. There's a Office Word file opened, and I want to get its full path in the computer. If impossible, any idea not using autoit?
weaponx Posted April 17, 2008 Posted April 17, 2008 Well generally you already know the full path of a file you opened. Some programs load a file into memory and leave a handle open to the file (Adobe Acrobat Professional), whereas others read in the file and release the handle (Notepad). You may be able to get a list of open file handles, which would include every single file you don't "see" running. There is no generic way of seeing what documents you have open, you need to narrow it down to the exact programs you want to check because the method will probably differ.
scsnake Posted April 17, 2008 Author Posted April 17, 2008 thx for your reply I am managing with M$ Office documents.... to be specific, it is M$ PowerPoint 2003 any hints would be appreciated
rasim Posted April 17, 2008 Posted April 17, 2008 scsnakeYou need this?$pid = ProcessExists("notepad.exe") MsgBox(0, '', _ProcessGetLocation($pid)) Func _ProcessGetLocation($iPID) Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID) If $aProc[0] = 0 Then Return SetError(1, 0, '') Local $vStruct = DllStructCreate('int[1024]') DllCall('psapi.dll', 'int', 'EnumProcessModules', 'hwnd', $aProc[0], 'ptr', DllStructGetPtr($vStruct), _ 'int', DllStructGetSize($vStruct), 'int*', 0) Local $aReturn = DllCall('psapi.dll', 'int', 'GetModuleFileNameEx', 'hwnd', $aProc[0], _ 'int', DllStructGetData($vStruct, 1), 'str', '', 'int', 2048) If StringLen($aReturn[3]) = 0 Then Return SetError(2, 0, '') Return $aReturn[3] EndFunc
weaponx Posted April 17, 2008 Posted April 17, 2008 He wants the path to the actual document that is open, not the program.
weaponx Posted April 17, 2008 Posted April 17, 2008 (edited) You could try:Sysinternals Handle or Nirsoft OpenedFilesViewEDIT: For historical purposes, here is an older topic with the same question:http://www.autoitscript.com/forum/index.ph...e++handle++list Edited April 17, 2008 by weaponx
Siao Posted April 17, 2008 Posted April 17, 2008 (edited) $oWord = ObjGet("","Word.Application") $oDocs = $oWord.Documents For $o In $oDocs ConsoleWrite($o.FullName & @CRLF) Next Edited April 17, 2008 by Siao "be smart, drink your wine"
scsnake Posted April 17, 2008 Author Posted April 17, 2008 $oWord = ObjGet("","Word.Application") $oDocs = $oWord.Documents For $o In $oDocs ConsoleWrite($o.FullName & @CRLF) Next I'm not familiar with COM >"< can you tell me how to use it .... what to do after "Next" ??
scsnake Posted April 17, 2008 Author Posted April 17, 2008 Siao's code returns file name, not the full path >"<I just found this http://www.autoitscript.com/forum/index.ph...path%5C+processbut this returns the full path of program, not the file opened
gigi1 Posted April 7, 2011 Posted April 7, 2011 hi, i'd like to Bump this thread, because i'm looking for the same thing: Getting the full path of an opened file in an application, such as MS word, or MS Excel. everything i fould returns the path of the application, not of the opened file. Thanks in advance
BrewManNH Posted April 7, 2011 Posted April 7, 2011 One way you could do it is to find the documents that are open by looking at the Window title for all the Word processes open, then searching the registry under the HKCU\Software\Microsoft\Office\12.0\Word\File MRU key for the open document. The File MRU key has the full paths of all open documents for Word/Excel/etc. By the way, the 12.0 value is only valid for Office 2007, Office 2003 would be under 11.0 as an example. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator
KaFu Posted April 7, 2011 Posted April 7, 2011 For me Siaos example above works fine. $oWord = ObjGet("","Word.Application") ; http://msdn.microsoft.com/de-de/library/ms265834%28v=Office.11%29.aspx $oDocs = $oWord.Documents For $o In $oDocs ConsoleWrite($o.Path & @CRLF) ConsoleWrite($o.FullName & @CRLF) Next Additionally to the Word.Application object MS Office seems to expose also "Excel.Application" and "PowerPoint.Application" objects. Google's your friend to find the right methods and properties . Â OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13)Â BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16)Â ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
gigi1 Posted April 8, 2011 Posted April 8, 2011 thanks for all replies, @BrewManNH: thanks for that suggestion. I'm not experienced at all with registry stuff, but i'll try. @KaFu: yeah that works but i forgot to mention, i can't seem to be able to get Word application object safely. _WordAttach fails sometimes and ObjGet is even worse. I don't know why but i quite gave up, so i'm looking for some way that is Object-free
gigi1 Posted April 8, 2011 Posted April 8, 2011 well... $var = RegRead("HKCU\Software\Microsoft\Office\12.0\Word\", "File MRU") ConsoleWrite("return value: "& $var & @CRLF & "error: "&@error& @CRLF&"extended: "&@extended&@CRLF) this returns: return value: error: -1 extended: 2 any suggestion?
KaFu Posted April 8, 2011 Posted April 8, 2011 You're sure that the key exists? I got ...\Office\14.0\Word\ and no "File MRU" at all. Maybe try: #AutoIt3Wrapper_UseX64=n Might also work for the ObjGet part ... Â OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13)Â BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16)Â ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
gigi1 Posted April 8, 2011 Posted April 8, 2011 #AutoIt3Wrapper_UseX64=n doesn't change anything. i have a 32bit winword on a 32bit system, why should x64 work? anyway, the requested key should exist, from what i read in the helpfile, error -1 means that value doesn't exists, while error 1 means that the whole key doesnt exist. I get error 1 if i change the path, for example if i use RegRead("HKCU\Software\Microsoft\Office\11.0\Word\", "File MRU") error is 1. so The key seem to exist from what i understand.
sahsanu Posted April 8, 2011 Posted April 8, 2011 any suggestion? This script returns last files used on Office Word. Don't know whether this is useful to you but... Global $var[100] Global $officeVersion="14.0" ;change it to your version For $i = 1 to 100 $var[$i-1] = RegEnumVal("HKCU\Software\Microsoft\Office\" & $officeVersion & "\Word\File MRU\", $i) If @error <> 0 Then ExitLoop EndIf Next For $i=0 To Ubound($var)-1 If StringInStr($var[$i], "Item") <> 0 Then $result=StringRegExp(RegRead("HKCU\Software\Microsoft\Office\" & $officeVersion & "\Word\File MRU\", $var[$i]),".*\*(.*)",1) ConsoleWrite($var[$i] & " value is: " & $result[0] & @CRLF) EndIf Next Note: Keep in mind that I did the script in a hurry so maybe there are a lot of ways to do it much better
gigi1 Posted April 11, 2011 Posted April 11, 2011 to anyone with the same problem: sahsanu's method above works great, but from what i have seen (4 PCs) Office 12.0 (2007) works good, while Office 11.0 (2003) doesn't store recent files in that position. To find the correct registry path just open a word document (so that it is included in the recent used list) then open regedit (run->regedit) and search for the name or path of the file just used.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now