Feedback

ShellExecute

Sprache: C#

ShellExecute war und ist eine Eierlegende Wollmilchsau hier eine Beispielaufrufe. Email versenden, Programme öffnen oder Dateien öffnen.
using System.Runtime.InteropServices;

// public class ........ {
// Api Deklarieren
[DllImport("shell32.dll", EntryPoint = "ShellExecute")]
public static extern long ShellExecute(int hwnd, string cmd, string file, string param1, string param2, int swmode);

/// swmode 0=sw_hide, 5=SW Show
/// Weitere siehe Windows API
public static string TestRun()
{
	// email öffnen
	ShellExecute (0, "mailto", "tester@testdomain.de", "", "", 5)

	// Notepad starten
	ShellExecute (0, "open", "notepad", "", "", 5)

	// Bild oder Datei offnen mit Pfad 
	ShellExecute (0, "open", "C:WINDOWSZapotec.bmp", "", "", 5)
}

// }

using System.Runtime.InteropServices;

// public class ........ {
// Api Deklarieren
[DllImport("shell32.dll", EntryPoint = "ShellExecute")]
public static extern long ShellExecute(int hwnd, string cmd, string file, string param1, string param2, int swmode);

/// swmode 0=sw_hide, 5=SW Show
/// Weitere siehe Windows API
public static string TestRun()
{
	// email öffnen
	ShellExecute (0, "mailto", "tester@testdomain.de", "", "", 5)

	// Notepad starten
	ShellExecute (0, "open", "notepad", "", "", 5)

	// Bild oder Datei offnen mit Pfad 
	ShellExecute (0, "open", "C:WINDOWSZapotec.bmp", "", "", 5)
}

// }

1 Kommentar

  1. Neben der Anwendung mit „mailto“ und „open“ existiert in der Regel auch eine „print“ und manchmal auch eine „new“
    // Druckt auf dem Standard Drucker
    ShellExecute (0, „print“, „C:WINDOWSZapotec.bmp“, „“, „“, 5)
    // Erstellt eine neues Word Dokument
    ShellExecute (0, „new“, „C:WINDOWSZapotec.doc“, „“, „“, 5)

    Ausserdem können eigene Server und eigene Methoden definiert werden indem diese in den Dateitypen definiert sind.