Skip to content

Commit

Permalink
hide the cmd window when running commands on device connection/discon…
Browse files Browse the repository at this point in the history
…nection
  • Loading branch information
michaldvorak79 committed Jan 26, 2021
1 parent 538df14 commit 5c5ebaa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions PnPDeviceChangeWatcher/PnPDeviceChangeWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,26 @@ private static void ProcessEvent(object sender, EventArrivedEventArgs e) {
bool newStatus = IsDevicePresent();

if (newStatus != connected) {
ProcessStartInfo info = new ProcessStartInfo("cmd.exe") {
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
Arguments = "/c "
};
if (newStatus) {
Console.WriteLine("\nDevice connected");
if (commandOnConnect != null) {
Console.WriteLine("Executing command: " + commandOnConnect);
Process.Start("cmd.exe", "/c " + commandOnConnect);
info.Arguments += commandOnConnect;
Process.Start(info);
} else {
Console.WriteLine("No command specified, doing nothing");
}
} else {
Console.WriteLine("\nDevice disconnected");
if (commandOnDisconnect != null) {
Console.WriteLine("Executing command: " + commandOnDisconnect);
Process.Start("cmd.exe", "/c " + commandOnDisconnect);
info.Arguments += commandOnDisconnect;
Process.Start(info);
} else {
Console.WriteLine("No command specified, doing nothing");
}
Expand Down
4 changes: 2 additions & 2 deletions PnPDeviceChangeWatcher/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyVersion("1.0.2.0")]
[assembly: AssemblyFileVersion("1.0.2.0")]

0 comments on commit 5c5ebaa

Please sign in to comment.