ShellExecute problems

T

the openFace

I am attempting to use the shell to display the properties page for a file,
yet I haven't been able to get it working. I made a class to call
ShellExecute through shown below:

class Win32Shell {
// omitted stuff
public const UInt32 SE_ERR_NOASSOC = 31;
// omitted


[DllImport("shell32.dll")]
public static extern Int32 ShellExecute(Int32 hwnd,
string lpOperation,
string lpFile,
string lpParameters,
string lpDirectory,
Int32 nShowCmd);
}


and later I call it with

Win32Shell.ShellExecute(0, "properties", fileName, dir, null, 1);

but all it does is return 31 qhich is defined in MSDN as "There is no
application associated with the given file name extension." I don't see why
this should be returned at all since the properties page is used for all
files on the system. Other calls, such as "open" using my ShellExecute
method work, so I can't figure this out.

Thanks for any help.
-the openFACE
 
G

Gabriele G. Ponti

/* Found somewhere on a previous newsgroup post */

using System;
using System.Runtime.InteropServices;

namespace ShellExecuteTest
{
class ShellExecuteClass
{

public const int SEE_MASK_INVOKEIDLIST = 0xC;

[ StructLayout(LayoutKind.Explicit) ]
public struct DUMMYUNIONNAME
{
[ FieldOffset( 0 ) ]
public IntPtr hIcon;
[ FieldOffset( 0 ) ]
public IntPtr hMonitor;
}

[ StructLayout(LayoutKind.Sequential) ]
public struct SHELLEXECUTEINFO
{
public int cbSize;
public int fMask;
public IntPtr hwnd;
public string lpVerb;
public string lpFile;
public string lpParameters;
public string lpDirectory;
public int nShow;
public IntPtr hInstApp;
public int lpIDList;
public string lpClass;
public int hkeyClass;
public int dwHotKey;
public DUMMYUNIONNAME dun;
public IntPtr hProcess;
}

[ DllImport("shell32.dll") ]
public static extern bool ShellExecuteEx( ref SHELLEXECUTEINFO si );

[ STAThread ]
static void Main( string[] args )
{
SHELLEXECUTEINFO sei = new SHELLEXECUTEINFO();
sei.cbSize = Marshal.SizeOf( typeof( SHELLEXECUTEINFO ) );
sei.lpFile = "C:";
sei.lpVerb = "properties";
sei.fMask = SEE_MASK_INVOKEIDLIST;
ShellExecuteEx( ref sei );

System.Console.ReadLine();
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top