栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用Windows服务中的凭据启动进程

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用Windows服务中的凭据启动进程

使用ProcessStartInfo启动新进程时,该进程在与启动进程相同的窗口站和桌面中启动。如果您使用不同的凭据,则用户通常将没有足够的权限在该桌面上运行。初始化错误失败是由于user32.dll尝试在新进程中进行初始化而无法进行的。

要解决此问题,您必须首先检索与Window Station和桌面相关联的安全描述符,并为用户添加适当的权限到DACL,然后在新的凭据下启动进程。

编辑:关于如何执行此操作和示例代码的详细说明在这里有点长了,所以我整理了一篇代码文章。

        //The following security adjustments are necessary to give the new         //process sufficient permission to run in the service's window station        //and desktop. This uses classes from the AsproLock library also from         //Asprosys.        IntPtr hWinSta = GetProcessWindowStation();        WindowStationSecurity ws = new WindowStationSecurity(hWinSta,          System.Security.AccessControl.AccessControlSections.Access);        ws.AddAccessRule(new WindowStationAccessRule("LaunchProcessUser", WindowStationRights.AllAccess, System.Security.AccessControl.AccessControlType.Allow));        ws.AcceptChanges();        IntPtr hDesk = GetThreadDesktop(GetCurrentThreadId());        DesktopSecurity ds = new DesktopSecurity(hDesk, System.Security.AccessControl.AccessControlSections.Access);        ds.AddAccessRule(new DesktopAccessRule("LaunchProcessUser", DesktopRights.AllAccess, System.Security.AccessControl.AccessControlType.Allow));        ds.AcceptChanges();        EventLog.WriteEntry("Launching application.", EventLogEntryType.Information);        using (Process process = Process.Start(psi))        {        }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/506740.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号