Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, October 22, 2009 11:03 PM
Hey guys,
I'm trying to call the Win32 API ShellExecute from my C# application. I'm aware that i need to use [DllImport("Shell32.dll")] though I'm not sure how to go about doing so. Help please?
(It's a Windows Forms application if that is of any help.)
- TheNobody
All replies (4)
Friday, October 23, 2009 2:47 PM âś…Answered
Yes but i need to use the "SW_HIDE" parameter which isn't supported (at least from what i saw). I got it working anyway.
[DllImport("Shell32.dll")]
public static extern int ShellExecuteA(IntPtr hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirecotry, int nShowCmd);
Thursday, October 22, 2009 11:16 PM | 2 votes
Let's start with: why? Process.Start() already calls ShellExecute() by default unless you use ProcessStartInfo.UseShellExecute = false. Fwiw, you find the required declarations at pinvoke.net
Hans Passant.
Friday, October 23, 2009 3:42 PM | 1 vote
Sure it is, ProcessStartInfo.WindowStyle = ProcessWindowStyle.Hidden. Well, I tried.
Hans Passant.
Friday, October 23, 2009 4:08 PM
You'll get into trouble if you use:
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
and also must have:
process.StartInfo.UserName = [UserName];