Click to See Complete Forum and Search --> : ShellExecute and "properties" verb


Lothar Haensler
August 5th, 1999, 07:03 AM
I found a "solution" for my property dialog question.
Shellexecute offers a verb "properties" that is supposed to display the properties dialog of a file or folder.

When I call it from VB I always get an error SE_ERR_NOASSOC which means that there is no file associated with the given extension, which is plain wrong.

I tried it with all extensions I can think of.


Dim lResult as Long
lResult = ShellExecute(me.hwnd, "properties", "c:\winnt\system32\shell32.dll", vbNullString, vbNullString, 1)
MsgBox lResult




Any hints?

August 5th, 1999, 12:16 PM
It might be possible with the other version of ShellExecute , ShellExecuteEx.
Yuo need to pass it a record structure called SHELLEXECUTEINFO.I have some code in C so perhaps you can translate it for VB.In C :

void ShowFileProperties(LPCTSTR szPathName)
{

SHELLEXECUTEINFO sei;
ZeroMemory(&sei, sizeof(SHELLEXECUTEINFO));
sei.cbSize = sizeof(SHELLEXECUTEINFO);
sei.lpFile = szPathName //Name of File
sei.nShow = SW_SHOW //To show properties dialog
sei.fMask = SEE_MASK_INVOKEIDLIST;
sei.lpVerb = _TEXT("properties");
ShellExecuteEx(&sei);
}

Hope this helps
}

August 5th, 1999, 12:19 PM
Instead of passing the me.hwnd parameter for the handle it might work better if you Pass NULL or vbNull instead.

Lothar Haensler
August 6th, 1999, 02:23 AM
Thank you very much!
It worked.
It's a shame that you posted your code as Anonymous.
I wanted to rate it as "excellent".

In case anyone else need the VB code.
It looks like this:

private Const SW_SHOW = 5
private Const SEE_MASK_INVOKEIDLIST = &HC
private Type SHELLEXECUTEINFO
cbSize as Long
fMask as Long
hwnd as Long
lpVerb as string
lpFile as string
lpParameters as string
lpDirectory as string
nShow as Long
hInstApp as Long
' optional fields
lpIDList as Long
lpClass as string
hkeyClass as Long
dwHotKey as Long
hIcon as Long
hProcess as Long
End Type
private Declare Function ShellExecuteEx Lib "shell32.dll" (byref s as SHELLEXECUTEINFO) as Long

private Sub Command1_Click()
Dim s as SHELLEXECUTEINFO
s.cbSize = LenB(s)
s.lpFile = "c:\winnt\system32\shell32.dll"
s.nShow = SW_SHOW
s.fMask = SEE_MASK_INVOKEIDLIST
s.lpVerb = "properties"
ShellExecuteEx s

End Sub

Chris Eastwood
August 6th, 1999, 03:18 AM
Well, I rated your post as excellent as it was in VB and I couldn't rate his !

Do you want this posted on the site ? - It's very useful - I'll change it so that you can pass any filename in if you wish.



Chris Eastwood

CodeGuru - the website for developers
http://www.codeguru.com/vb

Lothar Haensler
August 6th, 1999, 03:20 AM
>Do you want this posted on the site ?
>I'll change it so that you can pass any filename in if you wish.

Go ahead!

priyar
May 10th, 2000, 09:07 AM
Hi,
Your code was very usefull.How do I get the properties for the current file.for eg, if the user clicks on File->properties, I want the properties Dialog box to be displayed for the current File and is there any way to automatically fill in the Title,comments in the properties Dialog box.

Please help.I am desperately looking for a solution.
Thank you
Priya