Jump to content

Recommended Posts

Posted (edited)

Hi

 

Imagine this:

You open an image file with MSPaint.EXE,

and now when Paint's window is open, ou need to get the File's Full Path.

How should I do it?

 

I am using Windows XP SP3.

The TitleBar of the window shows "Filename.png - Paint", so this gives me the Filename part,

but I also need to get the folder in which the file is located..

 

Anyone has an idea how can I do it?

 

Thank you

Edited by Zohar
Posted

Check MRU

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Check this key

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Paint\Recent File List

You have File1, File2 etc. is the path of the files opened in Paint. You can delete that subkey firstly, open the file in Paint and check the File1 subkey value.

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Posted

Hello,

The problem with that method is that if you open a pic file with MsPaint and you check inside the program the list of MRU you will see the file in the list but it is not written in registry till you close the program so this method doen't work if you just have opened a file and want to check the full path.

Proof of concept ;)

Open a file with MsPaint and run below script... you will get No match found. Close MsPaint and open again the same pic file... you will get the full path.

Opt("WinTitleMatchMode", 2)
If WinExists("- Paint") Then
    $sTitle = WinGetTitle("- Paint")
    $sPicName = StringRegExpReplace($sTitle, "(.+)\s-\sPaint", "$1")

    Local $sSubKey = "", $sValKey = ""
    Local $sParenteKey = "HKCU\Software\Microsoft\Windows\CurrentVersion\Applets\Paint\Recent File List\" ;Maybe this key is different on Win XP machine
    For $i = 1 To 10
        $sSubKey = RegEnumVal($sParenteKey, $i)
        If @error Then
            ConsoleWrite("No match found" & @CRLF)
            ExitLoop
        EndIf
        $sValKey = RegRead($sParenteKey, $sSubKey)
        If StringInStr($sValKey, $sPicName) Then
            ConsoleWrite("PicName full path is: " & $sValKey & @CRLF)
            ExitLoop
        EndIf
    Next
EndIf

Note: As I comment inside the code, I don't know what is the correct RegKey for WinXP.

And sorry, I don't know any other way to get the full path of a recently file opened on MsPaint :(.

Cheers,

sahsanu

Posted (edited)

Thank you all

 

  On 8/16/2014 at 8:57 AM, Awais said:

i think there is a menu item recent pic 

it holds the information of last open pics

 

Yes there is, when you go to the File Menu, then on the bottom you see the recently opened files.

The only problem, is that like the TitleBar, it shows only the FileName, without the Path, which is what I am missing..

 

  On 8/16/2014 at 11:36 AM, Terenz said:

Check this key

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Paint\Recent File List

You have File1, File2 etc. is the path of the files opened in Paint. You can delete that subkey firstly, open the file in Paint and check the File1 subkey value.

 

Thank you Terenz

As sahsanu just wrote, the list there only updates with the last file, only after I close the program.

I need the Path while the program is working..

 

Anyone has any other creative idea?

 

Technically the program holds a variable in Memory that contains the FullPath of the currently opened file.

Is there a way to find this variable, and read its content, with AutoIt?

Edited by Zohar
Posted (edited)

I guess that there is some sequence odf system calls that will allow you to grab full pathes of open handles. For instance you can see them with Process Explorer with Lower Pane set to Handles.

Time to spend a month or more digging in MSDN mess or wait for an OS guru to pop up.

Instant googling turned up this which pointed to that. Just hints.

Edited by jchd
  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted

The OP is after the full path.

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted (edited)

Maybe this (command line feeware utility)

http://www.nirsoft.net/utils/opened_files_view.html

 

EDIT:

here is better link :

http://www.codeproject.com/Articles/18975/Listing-Used-Files

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

When you select "Save As ..." the path and filename of the last opened file is being pre-set.

Maybe you can grab it from there.

My UDFs and Tutorials:

  Reveal hidden contents

 

  • Moderators
Posted

Zohar,

A bit of a long-winded way to do it, but you could search for all files which match the name in the title bar. This works fine for me: :)

#include <StringConstants.au3>
#include <File.au3>
#include <Array.au3>

Opt("WinTitleMatchMode", 2)

$sFileName = StringSplit(WinGetTitle(WinGetHandle("Paint")), " - ", $STR_ENTIRESPLIT)[1]

$aList = _FileListToArrayRec("M:\", $sFileName, $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)

_ArrayDisplay($aList, "", Default, 8)
If you get multiple returns then _WinAPI_FileInUse might be a good way to detect which one is in use. ;)

M23

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

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

  On 8/16/2014 at 10:00 PM, jchd said:

I guess that there is some sequence odf system calls that will allow you to grab full pathes of open handles.

For instance you can see them with Process Explorer with Lower Pane set to Handles.

 

Thank you jhcd and mLipok

 

I actually tried that yesterday, among the many things I tried to get the Full Path.

When using SysInternal's Process Explorer, 1 out of 4 of the times, you see there a File Handle to the open file.

But it's only 1 out of 4.

the other 3 times, it's simply not htere, and I cannot understand why..

So this is not a ttrustable solution.

 

 

  On 8/17/2014 at 6:51 AM, water said:

When you select "Save As ..." the path and filename of the last opened file is being pre-set.

Maybe you can grab it from there.

 

Thank you, this is indeed something I checkde in the past, and I have a small problem there that prevents me from taking this option further:

The FileSave CommonDialog window, does not show the full path, and only the Last SubFolder name.

You could say that we can make a trick, and iterate the TreeView in the ComboBox, and compose the full path like that,

but even that is problematic because sometimes there are folders that don't have their Parent/Ancestor folders displayed in the ComboBox

(for example known folders, like "my Pictures", etc.. and network shared folders, and more)

 

But!

I believe that the FileSave CommonDialog window, like the main program's window, holds a variable to the path that it is showing.

So if for example the FileSave CommonDialog window shows some folder - I believe there is a variable that holds the Path for that folder.

But I don't know where this variable is, and how to get it.

(it is not inside some GUI element that's for sure, since I checked well with AutoIt's Window Info tool)

 

Maybe you guys have an idea how to get it from the FileSave CommonDialog window?

 

 

  On 8/17/2014 at 7:29 AM, Melba23 said:

Zohar,

A bit of a long-winded way to do it, but you could search for all files which match the name in the title bar. This works fine for me: :)

 

Hi Melba :)

This will work, but will make alot of hard disk noise :)

 

Amazing how the path is hidden in MSPaint.EXE!!! :)

Will there be a solution? :)

Edited by Zohar
Posted

With Windows 7 "Save As ..." shows the full path.

Unfortunately I have no Windows XP to do further tests.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted
  Quote

 

When using SysInternal's Process Explorer, 1 out of 4 of the times, you see there a File Handle to the open file.

But it's only 1 out of 4.

the other 3 times, it's simply not htere, and I cannot understand why..

I can't see an explanation either. Very strange, or does that mean that the file is open, read from and closed? Then why do you sometimes see it open is a mystery.

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted
  On 8/17/2014 at 7:49 AM, water said:

With Windows 7 "Save As ..." shows the full path.

Unfortunately I have no Windows XP to do further tests.

 

I understand.

  On 8/17/2014 at 8:12 AM, jchd said:

I can't see an explanation either. Very strange, or does that mean that the file is open, read from and closed? Then why do you sometimes see it open is a mystery.

 

It's probably opened, read, and closed,

and as you said, I have no idea why only sometimes it remains open.

 

Well,

Is the idea I offered, regarding the fact that there must be some variable in memory, holding the current file's Full Path, feasible?

Can AutoIt somehow get that?

Because we both know it's in memory..

Both for the program's main window,

and also for its sub-window - the Save As window..

Posted

MRU shorthand also has the full path but I've no idea where it hides. Registry probably user hive.

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Posted

'?do=embed' frameborder='0' data-embedContent>>

'?do=embed' frameborder='0' data-embedContent>>

#include <WinAPI.au3>

Local $iPID = ProcessExists('mspaint.exe')
If Not $iPID Then Exit
Local $aFiles = _ProcessListFiles("mspaint.exe") ; Get a list of files currently opened by the process
MsgBox(64, "File opened is: ", $aFiles[UBound($aFiles) - 1] & "\" & StringTrimRight(WinGetTitle(_WinGetByPID($iPID)), 8))

Func _ProcessListFiles($vProcess, $nMaxFiles = 1000)
    Static Local $aPrivilege = DllCall("ntdll.dll", "int", "RtlAdjustPrivilege", "int", 20, "int", 1, "int", 0, "int*", 0)
    Local $nProcessId = ProcessExists($vProcess), $aRet
    Static Local $hCurrentProcess = _WinAPI_GetCurrentProcess()
    Local $aHandles = _WinAPI_EnumProcessHandles($nProcessId)
    Local $hObject, $aFiles[$nMaxFiles+1], $sPath
    Local $hProcess = _WinAPI_OpenProcess(0x0040, 0, $nProcessId, True)
    For $i = 1 To $aHandles[0][0] Step 1
        If $aHandles[$i][3] = 0x00120189 Or $aHandles[$i][3] = 0x0012019f Or $aHandles[$i][3] = 0x00100000 Then ContinueLoop
        $hObject = _WinAPI_DuplicateHandle($hProcess, $aHandles[$i][0], $hCurrentProcess, 0, False, $DUPLICATE_SAME_ACCESS)
        If Not $hObject Then ContinueLoop
        If __IsFileObject($hObject) Then
            $sPath = __FileObjectPath($hObject)
            _WinAPI_CloseHandle($hObject)
            If FileExists($sPath) Then
                For $n = 1 To $aFiles[0]
                    If $aFiles[$n] = $sPath Then
                        $sPath = 0
                        ExitLoop
                    EndIf
                Next
                If $sPath Then
                    $aFiles[0] += 1
                    $aFiles[$aFiles[0]] = $sPath
                    If $aFiles[0] >= $nMaxFiles Then ExitLoop
                EndIf
            EndIf
        EndIf
    Next
    ReDim $aFiles[$aFiles[0]+1]
    Return $aFiles
EndFunc

Func __IsFileObject(ByRef $hObject)
    Static Local $tPOTI = DllStructCreate('ushort;ushort;ptr;byte[128]'), $pData, $Length, $tString
    Local $aRet = DllCall("ntdll.dll", 'uint', 'NtQueryObject', 'ptr', $hObject, 'uint', 2, 'ptr', DllStructGetPtr($tPOTI), 'ulong', DllStructGetSize($tPOTI), 'ptr', 0)
    If @error Or $aRet[0] Then Return
    $pData = DllStructGetData($tPOTI, 3)
    If Not $pData Then Return
    $Length = DllCall("kernel32.dll", 'int', 'lstrlenW', 'ptr', $pData)
    If @error Or Not $Length[0] Then Return
    $Length = $Length[0]
    $tString = DllStructCreate('wchar[' & ($Length + 1) & ']', $pData)
    If @error Then Return
    Return (DllStructGetData($tString, 1) == "File")
EndFunc

Func __FileObjectPath($hObject)
    Static Local $tStruct = DllStructCreate("char[255];")
    Local $aDrive = DriveGetDrive("ALL"), $sPath
    Local $aDrivesInfo[UBound($aDrive) - 1][2]
    For $I = 0 To UBound($aDrivesInfo) - 1
        $aDrivesInfo[$I][0] = $aDrive[$I + 1]
        DllCall("kernel32.dll", "dword", "QueryDosDevice", "str", $aDrivesInfo[$I][0], "ptr", DllStructGetPtr($tStruct), "dword", 255)
        $aDrivesInfo[$I][1] = DllStructGetData($tStruct, 1)
    Next
    Local Static $tPOTI = DllStructCreate("ushort Length;ushort MaximumLength;ptr Buffer;wchar Reserved[260];"), $sDeviceStr, $vSolid = False
    DllCall("ntdll.dll", "ulong", "NtQueryObject", "ptr", $hObject, "int", 1, "ptr", DllStructGetPtr($tPOTI), "ulong", DllStructGetSize($tPOTI), "ulong*", "")
    $sDeviceStr = DllStructGetData(DllStructCreate("wchar[" & Ceiling(DllStructGetData($tPOTI, "Length") / 2) & "];", DllStructGetData($tPOTI, "buffer")), 1)
    For $y = 0 To UBound($aDrivesInfo) - 1
        If StringLeft($sDeviceStr, StringLen($aDrivesInfo[$y][1])) = $aDrivesInfo[$y][1] Then
            $sPath = StringUpper($aDrivesInfo[$y][0]) & StringTrimLeft($sDeviceStr, StringLen($aDrivesInfo[$y][1]))
        EndIf
    Next
    Return $sPath
EndFunc

Func _WinAPI_EnumProcessHandles($PID = 0, $iType = 0)
    If Not $PID Then $PID = @AutoItPID
    Local $tSHI, $tHandle, $pData, $Ret
    Local $Result[101][4] = [[0]]
    $tSHI = DllStructCreate('ulong;byte[4194304]')
    $Ret = DllCall('ntdll.dll', 'uint', 'ZwQuerySystemInformation', 'uint', 16, 'ptr', DllStructGetPtr($tSHI), 'ulong', DllStructGetSize($tSHI), 'ulong*', 0)
    If @error Then
        Return SetError(1, 0, 0)
    Else
        If $Ret[0] Then
            Return SetError(1, $Ret[0], 0)
        EndIf
    EndIf
    $pData = DllStructGetPtr($tSHI, 2)
    For $i = 1 To DllStructGetData($tSHI, 1)
        $tHandle = DllStructCreate('align 4;ulong;ubyte;ubyte;ushort;ptr;ulong', $pData + __Iif(@AutoItX64, 4 + ($i - 1) * 24, ($i - 1) * 16))
        If (DllStructGetData($tHandle, 1) = $PID) And ((Not $iType) Or ($iType = DllStructGetData($tHandle, 2))) Then
            __Inc($Result)
            $Result[$Result[0][0]][0] = Ptr(DllStructGetData($tHandle, 4))
            $Result[$Result[0][0]][1] = DllStructGetData($tHandle, 2)
            $Result[$Result[0][0]][2] = DllStructGetData($tHandle, 3)
            $Result[$Result[0][0]][3] = DllStructGetData($tHandle, 6)
        EndIf
    Next
    If Not $Result[0][0] Then
        Return SetError(1, 0, 0)
    EndIf
    __Inc($Result, -1)
    Return $Result
EndFunc   ;==>_WinAPI_EnumProcessHandles

Func __Inc(ByRef $aData, $iIncrement = 100)
    Select
        Case UBound($aData, 2)
            If $iIncrement < 0 Then
                ReDim $aData[$aData[0][0] + 1][UBound($aData, 2)]
            Else
                $aData[0][0] += 1
                If $aData[0][0] > UBound($aData) - 1 Then
                    ReDim $aData[$aData[0][0] + $iIncrement][UBound($aData, 2)]
                EndIf
            EndIf
        Case UBound($aData, 1)
            If $iIncrement < 0 Then
                ReDim $aData[$aData[0] + 1]
            Else
                $aData[0] += 1
                If $aData[0] > UBound($aData) - 1 Then
                    ReDim $aData[$aData[0] + $iIncrement]
                EndIf
            EndIf
        Case Else
            Return 0
    EndSelect
    Return 1
EndFunc   ;==>__Inc

Func __Iif($fTest, $iTrue, $iFalse)
    If $fTest Then
        Return $iTrue
    Else
        Return $iFalse
    EndIf
EndFunc   ;==>__Iif

Func _WinGetByPID($iPID, $iArray = 1) ; 0 Will Return 1 Base Array & 1 Will Return The First Window.
    Local $aError[1] = [0], $aWinList, $sReturn
    If IsString($iPID) Then
        $iPID = ProcessExists($iPID)
    EndIf
    $aWinList = WinList()
    For $A = 1 To $aWinList[0][0]
        If WinGetProcess($aWinList[$A][1]) = $iPID And BitAND(WinGetState($aWinList[$A][1]), 2) Then
            If $iArray Then
                Return $aWinList[$A][1]
            EndIf
            $sReturn &= $aWinList[$A][1] & Chr(1)
        EndIf
    Next
    If $sReturn Then
        Return StringSplit(StringTrimRight($sReturn, 1), Chr(1))
    EndIf
    Return SetError(1, 0, $aError)
EndFunc   ;==>_WinGetByPID

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Posted (edited)

Thanks Terenz

But this works like Process Explorer - shows you the open handles.

As I wrote before, it's good only 1 out of 4 times, aprox..

 

I think the solution will be to switch to another Image Editing program.

One that hopefully has the File Name and Path accessible to be taken by AutoIt.

(for example shown in some GUI control, etc).

Too bad we don't have a way to get to the Variable that MSPaint.EXE holds the File's FullPath in.

This is different than open handles, since the file may not have an open handle right now, yet the Variable that stores the file's path must exist all the time.

 

Can anyone recommend of a Simple Image Editing program?

Simple means few MB, hopefully Portable,

and allows editing BMP, PNG, JPG, with basic graphical operations..

Edited by Zohar
Posted

  On 8/17/2014 at 2:04 PM, Zohar said:

Can anyone recommend of a Simple Image Editing program?

Simple means few MB, hopefully Portable,

and allows editing BMP, PNG, JPG, with basic graphical operations..

 

Take a look to LazPaint, it's portable, just 9 MB and the most important thing, you will have the full path of the pic file in application title.

Cheers,

sahsanu

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
  • Recently Browsing   0 members

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