Skip to content

Commit df47ad0

Browse files
authored
Create virtual-box-tray.cs
1 parent 118bd84 commit df47ad0

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

virtual-box-tray.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
NotifyIcon trayIcon = new NotifyIcon
11+
{
12+
Icon = SystemIcons.Application,
13+
Text = "VirtualBox VM Control",
14+
Visible = true
15+
};
16+
17+
ContextMenu trayMenu = new ContextMenu();
18+
trayMenu.MenuItems.Add("Start VM", StartVM);
19+
trayMenu.MenuItems.Add("Stop VM", StopVM);
20+
trayMenu.MenuItems.Add("Exit", (sender, e) => Application.Exit());
21+
22+
trayIcon.ContextMenu = trayMenu;
23+
24+
Application.Run();
25+
trayIcon.Dispose();
26+
}
27+
28+
static void StartVM(object sender, EventArgs e)
29+
{
30+
Process.Start("VBoxManage", "startvm \"Your_VM_Name\" --type headless");
31+
}
32+
33+
static void StopVM(object sender, EventArgs e)
34+
{
35+
Process.Start("VBoxManage", "controlvm \"Your_VM_Name\" poweroff");
36+
}
37+
}

0 commit comments

Comments
 (0)