Jump to content

Open a file's properties window


Recommended Posts

I did some searching on the forums but often times pages could not load (maybe the site simply does not like this subject?)

I found very few responses and tried them all

Func _ShowFileProperties($sFile, $sVerb = "properties", $hWnd = 0)
    ; function by Rasim
    ; http://www.autoitscript.com/forum/index.php?showtopic=78236&view=findpost&p=565547

    Local Const $SEE_MASK_INVOKEIDLIST = 0xC
    ; Local Const $SEE_MASK_NOCLOSEPROCESS = 0x40
    ; Local Const $SEE_MASK_FLAG_NO_UI = 0x400

    Local $PropBuff, $FileBuff, $SHELLEXECUTEINFO

    $PropBuff = DllStructCreate("char[256]")
    DllStructSetData($PropBuff, 1, $sVerb)

    $FileBuff = DllStructCreate("char[256]")
    DllStructSetData($FileBuff, 1, $sFile)

    $SHELLEXECUTEINFO = DllStructCreate("int cbSize;long fMask;hwnd hWnd;ptr lpVerb;ptr lpFile;ptr lpParameters;ptr lpDirectory;" & _
            "int nShow;int hInstApp;ptr lpIDList;ptr lpClass;hwnd hkeyClass;int dwHotKey;hwnd hIcon;" & _
            "hwnd hProcess")

    DllStructSetData($SHELLEXECUTEINFO, "cbSize", DllStructGetSize($SHELLEXECUTEINFO))
    DllStructSetData($SHELLEXECUTEINFO, "fMask", $SEE_MASK_INVOKEIDLIST)
    DllStructSetData($SHELLEXECUTEINFO, "hwnd", $hWnd)
    DllStructSetData($SHELLEXECUTEINFO, "lpVerb", DllStructGetPtr($PropBuff, 1))
    DllStructSetData($SHELLEXECUTEINFO, "lpFile", DllStructGetPtr($FileBuff, 1))

    $aRet = DllCall("shell32.dll", "int", "ShellExecuteEx", "ptr", DllStructGetPtr($SHELLEXECUTEINFO))
    If $aRet[0] = 0 Then Return SetError(2, 0, 0)

    Return $aRet[0]
EndFunc   ;==>_ShowFileProperties

This code works fine in XP which is great because the more OS I can support with my script, the better

However every option I found and tried has simply done nothing on windows 7 (64bit)

I have a gui that has paths to exe files stored.

I want to be able to select a path and click a button to open that exe's properties window. Everything is all ready except the command to open the properties window ;)

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

If ShellExecute doesn't work for you, there are two alternatives:

One using COM objects:

$sPath = @SystemDir&"\user32.dll"
$oshellApp = ObjCreate("shell.application")
$oshellApp.namespace(0).parsename($sPath).invokeverb("Properties")
Sleep(2000)     ; The Properties page will display and disappear if your program exits (it somehow attaches to this process)

One using SHObjectProperties:

Global Const $SHOP_PRINTERNAME=1    ; $sObjName = printer friendly name
Global Const $SHOP_FILEPATH=2       ; $sObjName = full pathname to file
Global Const $SHOP_VOLUMEGUID=4     ; $sObjName = Drive Path ("C:\") or Volume GUID ("\\?\Volume\{2eca078d-5cbc-43d3-aff8-7e8511f60d0e}\)")

Func _FilePropertiesDialog($sObjName,$sPropPage="",$iObjType=0x02,$hWnd=0)
    Local $sPropPageType="ptr"
    If IsString($sPropPage) And $sPropPage<>"" Then
        $sPropPageType="wstr"
    Else
        $sPropPage=0
    EndIf
    Local $aRet=DllCall("shell32.dll","bool","SHObjectProperties","hwnd",$hWnd,"dword",$iObjType,"wstr",$sObjName,$sPropPageType,$sPropPage)
    If @error Then Return SetError(2,@error,False)
    If Not $aRet[0] Then Return SetError(3,0,False)
    Return True
EndFunc
_FilePropertiesDialog("C:\","",4)   ; Drive/Volume Properties - this special case does not return until closed by the User
_FilePropertiesDialog("Microsoft XPS Document Writer","",1) ; Printers
ConsoleWrite("@error="&@error&", @extended="&@extended&@CRLF)
Sleep(2000)     ; The Properties page will display and disappear if your program exits (it somehow attaches to this process)
_FilePropertiesDialog(@ComSpec,"Version",2) ; File
ConsoleWrite("@error="&@error&", @extended="&@extended&@CRLF)
Sleep(2000)     ; The Properties page will display and disappear if your program exits (it somehow attaches to this process)

Note how both options will close once the program is closed - this is why you should do what you need to do with the dialog boxes, and then close them. The odd case is drives, from which it doesn't return until closed by the user.

A nice thing about the second option is that you can select which Property tab displays (I gave 'Version' as an example, but you can leave it as "" to display the default tab).

Anyway, hope it helps

Link to comment
Share on other sites

I will definately try them, Thanks!

I tried the shellexecute and when it didn't work searched on the forums to find out that it is flawed and the "properties" value is wrong. Would have made everything so much easier.

*edit*

the first example you have a comment saying "it attaches itself to this proccess" are you refering to the autoit script that calls the object or the exe you are viewing the properties window of?

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

I meant the AutoIt script's Process (whether it is a compiled script or running through autoit3). You'll see if you run the code as it is - the dialogs just disappear on script exit.

Link to comment
Share on other sites

I figured but it looked similar to one I tried before (found through search) and either it opened and closed the window so fast I couldn't tell, or nothing happened at all (I didn't see any sign that anything happened)

Anyways, I will try it, hope it works and report results.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

Actually, I've successfully gotten this to work with my own ShellExecuteEx function on Windows 7 (modified from MrCreatoR's post on ShellExecuteEx [warning: the original is not Unicode or x64 safe]).

The Properties dialog actually has the same problem as the other methods I mentioned, so that's not really a shortcoming of any method I suppose - just the way Windows works.

I believe AutoIt's ShellExecute is simply missing the 'SEE_MASK_INVOKEIDLIST' flag bits (0x0C). Once they fix that in a future version, we won't need all these workarounds.

*edit: by shortcoming, I meant - it closes when the script does

Edited by Ascend4nt
Link to comment
Share on other sites

If ShellExecute doesn't work for you, there are two alternatives:

One using COM objects:

$sPath = @SystemDir&"\user32.dll"
$oshellApp = ObjCreate("shell.application")
$oshellApp.namespace(0).parsename($sPath).invokeverb("Properties")
Sleep(2000)     ; The Properties page will display and disappear if your program exits (it somehow attaches to this process)

This one seems to have worked just fine ;)

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...

This one does the job for me, but has the same issues as the examples posted before, the properties window only exists as long as the script is running...

$sFile = "C:\WINDOWS\Tasks\Adobe Flash Player Updater.job"

ConsoleWrite(FileExists($sFile) & @CRLF)
ConsoleWrite(_ShowFileProperties($sFile) & @CRLF)

Sleep(5000)


Func _ShowFileProperties($sFile, $sVerb = "properties", $hWnd = 0)
; function by Rasim
; http://www.autoitscript.com/forum/index.php?showtopic=78236&view=findpost&p=565547
; http://stackoverflow.com/questions/12508100/shellexecuteinfo-unicode-support

Local Const $SEE_MASK_INVOKEIDLIST = 0xC
Local Const $SEE_MASK_NOCLOSEPROCESS = 0x40
Local Const $SEE_MASK_FLAG_NO_UI = 0x400

Local $PropBuff, $FileBuff, $SHELLEXECUTEINFO

$PropBuff = DllStructCreate("wchar[256]")
DllStructSetData($PropBuff, 1, $sVerb)

$FileBuff = DllStructCreate("wchar[4096]")
DllStructSetData($FileBuff, 1, $sFile)

$SHELLEXECUTEINFO = DllStructCreate("int cbSize;long fMask;hwnd hWnd;ptr lpVerb;ptr lpFile;ptr lpParameters;ptr lpDirectory;" & _
"int nShow;int hInstApp;ptr lpIDList;ptr lpClass;hwnd hkeyClass;int dwHotKey;hwnd hIcon;" & _
"hwnd hProcess")

DllStructSetData($SHELLEXECUTEINFO, "cbSize", DllStructGetSize($SHELLEXECUTEINFO))
DllStructSetData($SHELLEXECUTEINFO, "fMask", $SEE_MASK_INVOKEIDLIST)
DllStructSetData($SHELLEXECUTEINFO, "hwnd", $hWnd)
DllStructSetData($SHELLEXECUTEINFO, "lpVerb", DllStructGetPtr($PropBuff, 1))
DllStructSetData($SHELLEXECUTEINFO, "lpFile", DllStructGetPtr($FileBuff, 1))

$aRet = DllCall("shell32.dll", "int", "ShellExecuteExW", "ptr", DllStructGetPtr($SHELLEXECUTEINFO))
If $aRet[0] = 0 Then Return SetError(2, 0, 0)

Return $aRet[0]
EndFunc   ;==>_ShowFileProperties
Link to comment
Share on other sites

See windows shortcut keys....................Alt+Enter to get properties of selected item.............windows key + pause to get system property. Edited by adnanbaloch

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

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