WinAPI C - 来自 REDMON_USER 和 REDMON_SESSIONID 的 RunAsUser
我安装了 PostScript 打印机驱动程序并设置了 REDMON (redmonnt.dll),用于将 postscript 输出重定向到我的程序。在我相当简单的 c 程序中,我从 STDIN 捕获数据,并且能够成功地将其保存到 .ps 文件中。该文件看起来不错。
但是,我想启动 gsview.exe 来查看该文件。如果我调用 ShellExecute,它在 Windows 7 中会因权限问题而失败。看来我的程序是在不同的用户帐户(LOCAL SERVICE)下调用的。因此,我正在寻找一种在特定用户名(启动打印作业的用户)下运行 gsview.exe 的方法,该用户名也可以在名为 REDMON_USER 的变量以及 SESSIONID 中供程序使用。
问:在给定用户名和会话 ID 的情况下,启动程序所需的最少 WinAPI 调用是多少?
任何 C/C++、.NET 代码示例都会非常有帮助。
编辑:我想要完成的事情与 redrunee (来自 redmonee)非常相似。我不想使用 redrunee,因为它会打开一个控制台窗口一小会儿。
笔记: 1) 该程序由打印机服务以[LOCAL SERVICE]帐户调用。 2)第一个参数Username(REDMON_USER),实际上指向当前正在查看屏幕的用户
I installed a PostScript printer driver and have setup REDMON (redmonnt.dll) for redirecting postscript output to my program. In my rather simple c program I capture the data from STDIN and I am able to successfully save it into a .ps file. The file looks OK.
However, I want to start gsview.exe for viewing the file. If I call ShellExecute it fails in Windows 7 because of permission issues. It seems that my program is called under a different user account (LOCAL SERVICE). So I am looking for a way to run gsview.exe under a specific username (the user who initiated the print job) which is available to the program in a variable called REDMON_USER along with the SESSIONID as well.
Q: What are the minimum WinAPI calls required to start a program given a username and a sessionid?
Any code examples in C/C++, .NET would be very helpful.
EDIT: What I am trying accomplish is something very similar to redrunee (from redmonee). I don't want to use redrunee because it opens about a console window for a brief moment.
Note:
1) The program is called by the printer service as [LOCAL SERVICE] account.
2) The first parameter Username (REDMON_USER), in effect, points to the user currently looking at the screen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 CreateProcessAsUser。
另请参阅
CreateProcessWithLogonW
和CreateProcess
。它们是从 CreateProcessAsUser
EDIT 链接的,以回复 OP 的评论。
请遵循此线程。
我在这里逐字复制此内容,以防原始链接停止工作:
谢谢您efratian。
附言。呵呵,Windows编程的乐趣,好久没做了。现在我记得为什么了。唯一接近甚至更差的记录是 OpenSSH 编程。
Look at CreateProcessAsUser.
Also look at
CreateProcessWithLogonW
andCreateProcess
.They are linked from the CreateProcessAsUser
EDIT In reply to comments by OP.
Follow advice from this thread.
I am copying this here verbatim, in case the original link stops working:
Thank you efratian.
PS. Oh joy of Windows programming, did not do it for quite a while. Now I remember why. The only thing that is close or even worse documented is OpenSSH programming.
文档描述了“以用户身份运行”功能,这似乎正是你想要的:
The documentation describes the "Run as User" feature, which seems to be exactly what you want: