SuperDataMen 2019-01-09 16:51 采纳率: 0%
浏览 1010

C#windows服务 弹出一个ui窗体程序无法获取管理员权限

我现在有window服务运行中弹出ui窗体程序的需求,网上来找了代码,运行之后虽然能弹出ui窗体,但是因为没有管理员模式,无法启动端口监听,明明我服务创建的是系统管理员
代码如下

try
            {
                string appStartPath = runCommand;
                IntPtr userTokenHandle = IntPtr.Zero;
                ApiDefinitions.WTSQueryUserToken(ApiDefinitions.WTSGetActiveConsoleSessionId(), ref userTokenHandle);

                ApiDefinitions.PROCESS_INFORMATION procInfo = new ApiDefinitions.PROCESS_INFORMATION();
                ApiDefinitions.STARTUPINFO startInfo = new ApiDefinitions.STARTUPINFO();
                startInfo.cb = (uint)Marshal.SizeOf(startInfo);

                ApiDefinitions.CreateProcessAsUser(
                    userTokenHandle,
                    appStartPath,
                    "",
                    IntPtr.Zero,
                    IntPtr.Zero,
                    false,
                    0,
                    IntPtr.Zero,
                    null,
                    ref startInfo,
                    out procInfo);

                if (userTokenHandle != IntPtr.Zero)
                    ApiDefinitions.CloseHandle(userTokenHandle);

                int _currentAquariusProcessId = (int)procInfo.dwProcessId;
                currentAquariusProcessId = _currentAquariusProcessId;
                error = "";
                return true;
            }
            catch (Exception e)
            {
                error = e.Message;
            }
            return false;

报错信息

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 变数的长度不一样”。是什么原因呢?如何修改?
    • ¥15 matlab作业不会写
    • ¥15 vue2(标签-chrome|关键词-浏览器兼容)
    • ¥15 python网络流自动生成系统 医学领域
    • ¥15 sql查询仓库里都有什么
    • ¥15 代码的修改,添加和运行完善
    • ¥15 krpano-场景分组和自定义地图分组
    • ¥15 lammps Gpu加速出错
    • ¥15 关于PLUS模型中kapaa值的问题
    • ¥15 关于博途V17进行仿真时无法建立连接问题