ShellExecute problems

  • Thread starter Thread starter the openFace
  • Start date Start date
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
 
/* 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();
}
}
}
 
Back
Top