Jan*_*cci 4 c# administrator showwindow windows-8
我正在编写一个显示/隐藏某个目标应用程序窗口的程序.我之前正在测试它并发现一些奇怪的东西.如果我以管理员身份运行目标应用程序(右键单击 - >属性,"兼容性"选项卡,"以管理员身份运行此程序")它不起作用.
为了演示我编写了一个名为"TargetApplication"的简单GUI应用程序,然后我编写了以下代码来测试显示/隐藏此应用程序:
class Program
{
static void Main(string[] args)
{
IntPtr windowPtr = FindWindow(null, "TargetApplication");
ShowWindow(windowPtr, 0); // 0 = Hide
Console.WriteLine("The window is now hidden. Press Enter to restore");
Console.ReadLine();
ShowWindow(windowPtr, 9); // 9 = Restore
Console.WriteLine("The window is now restored. Press Enter to exit.");
Console.ReadLine();
}
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
}
Run Code Online (Sandbox Code Playgroud)
如果我启动没有管理员权限的窗口应用程序它不起作用.
有人会介意为我测试这个吗?我在这里为这两个应用程序上传了.exe文件:
您所要做的就是下载它们并运行TestApplication.exe然后运行TestShowWindow.exe.您会发现通过将TestApplication.exe更改为以管理员身份运行会导致ShowWindow不再起作用.
当然,如果你不相信下载我的东西,你总是可以编译我的代码并在Windows中的任何目标应用程序上测试它,你可以改变其兼容性模式.
PS我不确定它是否有所作为,但我正在运行Windows 8 Pro.64位.
| 归档时间: |
|
| 查看次数: |
5491 次 |
| 最近记录: |