Skip to content

Commit 60415a5

Browse files
authored
Create vanderstack-docker-server.cs
1 parent 158c409 commit 60415a5

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

vanderstack-docker-server.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Drawing;
4+
using System.Windows.Forms;
5+
6+
class Program
7+
{
8+
static void Main()
9+
{
10+
string vmName = "vanderstack-docker-server";
11+
12+
// Automatically start the VM on app launch
13+
StartVM(vmName);
14+
15+
// Create the system tray icon
16+
NotifyIcon trayIcon = new NotifyIcon
17+
{
18+
Icon = SystemIcons.Application,
19+
Text = "Docker VM",
20+
Visible = true
21+
};
22+
23+
// Create the context menu for the tray
24+
ContextMenu trayMenu = new ContextMenu();
25+
trayMenu.MenuItems.Add("Start VM", (sender, e) => StartVM(vmName));
26+
trayMenu.MenuItems.Add("Stop VM", (sender, e) => StopVM(vmName));
27+
trayMenu.MenuItems.Add("Exit", (sender, e) => Application.Exit());
28+
29+
trayIcon.ContextMenu = trayMenu;
30+
31+
// Run the application loop
32+
Application.Run();
33+
trayIcon.Dispose();
34+
}
35+
36+
static void StartVM(string vmName)
37+
{
38+
try
39+
{
40+
Process.Start("VBoxManage", $"startvm \"{vmName}\" --type headless");
41+
MessageBox.Show($"VM '{vmName}' started successfully!", "VM Control", MessageBoxButtons.OK, MessageBoxIcon.Information);
42+
}
43+
catch (Exception ex)
44+
{
45+
MessageBox.Show($"Failed to start VM: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
46+
}
47+
}
48+
49+
static void StopVM(string vmName)
50+
{
51+
try
52+
{
53+
Process.Start("VBoxManage", $"controlvm \"{vmName}\" poweroff");
54+
MessageBox.Show($"VM '{vmName}' stopped successfully!", "VM Control", MessageBoxButtons.OK, MessageBoxIcon.Information);
55+
}
56+
catch (Exception ex)
57+
{
58+
MessageBox.Show($"Failed to stop VM: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)