我想创建一个隐藏的表单来操纵一些 windows 进程
I want to create a hidden form that manipulates some windows processes
我想创建一个始终打开的隐藏应用程序,我希望此应用程序检测是否打开了具有特定文本的进程以打开另一个应用程序并将其始终置于顶部。
例如:
private void Form1_Load(object sender, EventArgs e)
{
Hide();
if (Process.text == "DFT Report Generator")//if the process text is this text for example
{
Process.Start("someapp.exe");//start someapp
someapp.TopMost = true; //set the someapp to be always on top
}
else
{
}
}
我怎样才能做到这一点?
这是我使用的方法。 processName 是您尝试查找的进程的名称,newPrecessPath 是您惯用的进程路径 运行
如果你不想隐藏你的主要使用 this.Hide()
您可以在计时器中使用此方法来尝试每隔 x 秒查找 运行ning 进程。
private void LookProcess(string processName, string newProcessPath)
{
foreach (var process in Process.GetProcesses())
{
if (process.ProcessName == processName)
{
ProcessStartInfo prcinf = new ProcessStartInfo();
prcinf.WindowStyle = ProcessWindowStyle.Maximized;
prcinf.FileName = newProcessPath;
Process.Start(prcinfprc);
}
}
}
- 创建一个在后台运行的 window less forms 应用程序。粗略的想法是创建一个 Windows Forms 应用程序并禁用视觉属性。
Program.cs
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//Application.EnableVisualStyles();
//Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
Form.cs
public partial class Form1 : Form
{
public Form1()
{
//InitializeComponent();
}
#region Silent mode
private static Form1 _instance;
/// <summary>
/// Prevent window getting visible
/// </summary>
/// <param name="value"></param>
protected override void SetVisibleCore(bool value)
{
// Prevent window getting visible
CreateHandle();
_instance = this;
//do not show the window
value = false;
base.SetVisibleCore(value);
}
#endregion
}
在特定时间间隔触发计时器,浏览 运行 进程并实现您想要执行的操作。
Timer _timer;
public Form1()
{
//InitializeComponent();
_timer = new Timer();
_timer.Interval = 1000; //ms
_timer.Elapsed += _timer_Elapsed;
}
private void _timer_Elapsed(object sender, ElapsedEventArgs e)
{
foreach (var process in Process.GetProcesses())
{
//compare and perform tasks
}
}
使用正确的工具完成工作。
使用 windows 服务项目模板创建 windows 服务。
我想创建一个始终打开的隐藏应用程序,我希望此应用程序检测是否打开了具有特定文本的进程以打开另一个应用程序并将其始终置于顶部。 例如:
private void Form1_Load(object sender, EventArgs e)
{
Hide();
if (Process.text == "DFT Report Generator")//if the process text is this text for example
{
Process.Start("someapp.exe");//start someapp
someapp.TopMost = true; //set the someapp to be always on top
}
else
{
}
}
我怎样才能做到这一点?
这是我使用的方法。 processName 是您尝试查找的进程的名称,newPrecessPath 是您惯用的进程路径 运行 如果你不想隐藏你的主要使用 this.Hide() 您可以在计时器中使用此方法来尝试每隔 x 秒查找 运行ning 进程。
private void LookProcess(string processName, string newProcessPath)
{
foreach (var process in Process.GetProcesses())
{
if (process.ProcessName == processName)
{
ProcessStartInfo prcinf = new ProcessStartInfo();
prcinf.WindowStyle = ProcessWindowStyle.Maximized;
prcinf.FileName = newProcessPath;
Process.Start(prcinfprc);
}
}
}
- 创建一个在后台运行的 window less forms 应用程序。粗略的想法是创建一个 Windows Forms 应用程序并禁用视觉属性。
Program.cs
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//Application.EnableVisualStyles();
//Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
Form.cs
public partial class Form1 : Form
{
public Form1()
{
//InitializeComponent();
}
#region Silent mode
private static Form1 _instance;
/// <summary>
/// Prevent window getting visible
/// </summary>
/// <param name="value"></param>
protected override void SetVisibleCore(bool value)
{
// Prevent window getting visible
CreateHandle();
_instance = this;
//do not show the window
value = false;
base.SetVisibleCore(value);
}
#endregion
}
在特定时间间隔触发计时器,浏览 运行 进程并实现您想要执行的操作。
Timer _timer; public Form1() { //InitializeComponent(); _timer = new Timer(); _timer.Interval = 1000; //ms _timer.Elapsed += _timer_Elapsed; } private void _timer_Elapsed(object sender, ElapsedEventArgs e) { foreach (var process in Process.GetProcesses()) { //compare and perform tasks } }
使用正确的工具完成工作。
使用 windows 服务项目模板创建 windows 服务。