-
-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Open processes without command window
- Loading branch information
Showing
4 changed files
with
131 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
|
||
namespace EverythingToolbar.Helpers | ||
{ | ||
class ShellUtils | ||
{ | ||
[DllImport("shell32.dll", CharSet = CharSet.Auto)] | ||
static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo); | ||
|
||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] | ||
public struct SHELLEXECUTEINFO | ||
{ | ||
public int cbSize; | ||
public uint fMask; | ||
public IntPtr hwnd; | ||
[MarshalAs(UnmanagedType.LPTStr)] | ||
public string lpVerb; | ||
[MarshalAs(UnmanagedType.LPTStr)] | ||
public string lpFile; | ||
[MarshalAs(UnmanagedType.LPTStr)] | ||
public string lpParameters; | ||
[MarshalAs(UnmanagedType.LPTStr)] | ||
public string lpDirectory; | ||
public int nShow; | ||
public IntPtr hInstApp; | ||
public IntPtr lpIDList; | ||
[MarshalAs(UnmanagedType.LPTStr)] | ||
public string lpClass; | ||
public IntPtr hkeyClass; | ||
public uint dwHotKey; | ||
public IntPtr hIcon; | ||
public IntPtr hProcess; | ||
} | ||
|
||
public static void ShowFileProperties(string path) | ||
{ | ||
SHELLEXECUTEINFO info = new SHELLEXECUTEINFO(); | ||
info.cbSize = Marshal.SizeOf(info); | ||
info.lpVerb = "properties"; | ||
info.lpFile = path; | ||
info.nShow = 5; | ||
info.fMask = 12; | ||
ShellExecuteEx(ref info); | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] | ||
private struct STARTUPINFO | ||
{ | ||
public Int32 cb; | ||
public string lpReserved; | ||
public string lpDesktop; | ||
public string lpTitle; | ||
public Int32 dwX; | ||
public Int32 dwY; | ||
public Int32 dwXSize; | ||
public Int32 dwYSize; | ||
public Int32 dwXCountChars; | ||
public Int32 dwYCountChars; | ||
public Int32 dwFillAttribute; | ||
public Int32 dwFlags; | ||
public Int16 wShowWindow; | ||
public Int16 cbReserved2; | ||
public IntPtr lpReserved2; | ||
public IntPtr hStdInput; | ||
public IntPtr hStdOutput; | ||
public IntPtr hStdError; | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
private struct PROCESS_INFORMATION | ||
{ | ||
public IntPtr hProcess; | ||
public IntPtr hThread; | ||
public int dwProcessId; | ||
public int dwThreadId; | ||
} | ||
|
||
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] | ||
private static extern bool CreateProcess( | ||
string lpApplicationName, | ||
string lpCommandLine, | ||
IntPtr lpProcessAttributes, | ||
IntPtr lpThreadAttributes, | ||
bool bInheritHandles, | ||
uint dwCreationFlags, | ||
IntPtr lpEnvironment, | ||
string lpCurrentDirectory, | ||
[In] ref STARTUPINFO lpStartupInfo, | ||
out PROCESS_INFORMATION lpProcessInformation); | ||
|
||
public static void CreateProcessFromCommandLine(string commandLine) | ||
{ | ||
var si = new STARTUPINFO(); | ||
var pi = new PROCESS_INFORMATION(); | ||
|
||
CreateProcess( | ||
null, | ||
commandLine, | ||
IntPtr.Zero, | ||
IntPtr.Zero, | ||
false, | ||
0, | ||
IntPtr.Zero, | ||
null, | ||
ref si, | ||
out pi); | ||
} | ||
|
||
public static void OpenWithDialog(string path) | ||
{ | ||
var args = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "shell32.dll"); | ||
args += ",OpenAs_RunDLL " + path; | ||
Process.Start("rundll32.exe", args); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters