以下是使用C#代码实现在管理员帐户运行,在其他用户界面弹出信息窗口的示例:

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

class Program
{
    // 导入Windows API函数
    [DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

    [DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

    [DllImport("user32.dll")]
    static extern IntPtr GetShellWindow();

    static void Main()
    {
        // 检查当前用户是否为管理员
        if (!IsAdmin())
        {
            Console.WriteLine("请以管理员身份运行程序!");
            Console.ReadKey();
            return;
        }

        // 获取其他用户的Shell窗口句柄
        IntPtr shellWindow = GetShellWindow();

        // 查找消息窗口句柄
        IntPtr messageWindow = FindWindow(null, "消息窗口标题");

        // 如果找到消息窗口,则发送消息弹出窗口
        if (messageWindow != IntPtr.Zero)
        {
            const uint WM_SYSCOMMAND = 0x0112;
            const uint SC_RESTORE = 0xF120;

            SendMessage(messageWindow, WM_SYSCOMMAND, (IntPtr)SC_RESTORE, IntPtr.Zero);
        }
    }

    static bool IsAdmin()
    {
        using (var identity = System.Security.Principal.WindowsIdentity.GetCurrent())
        {
            var principal = new System.Security.Principal.WindowsPrincipal(identity);
            return principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator);
        }
    }
}

请将代码中的"消息窗口标题"替换为要弹出的消息窗口的标题。在管理员账户下运行此代码,它将查找指定标题的消息窗口并发送还原窗口的消息,使其弹出到其他用户的桌面上

你是C#高级程序员请写出代码实现在管理员帐户运行正点时间在其它用户界面弹出信息窗口

原文地址: http://www.cveoy.top/t/topic/ilEK 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录