以标准用户(C ++)打开默认浏览器 [英] Open default browser as standard user (C++)

查看:642
本文介绍了以标准用户(C ++)打开默认浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用ShellExecute打开在用户的浏览器中打开一个URL,但在Win7和Vista中运行有点麻烦,因为程序运行提升为服务。

I'm currently using ShellExecute "open" to open a URL in the user's browser, but running into a bit of trouble in Win7 and Vista because the program runs elevated as a service.

当ShellExecute打开浏览器时,它似乎读取本地管理配置文件,而不是用户的。例如,如果键盘上的用户将Firefox作为默认浏览器,它可能会打开IE(这是管理员的默认设置)。

When ShellExecute opens the browser, it seems to read the "Local Admin" profile instead of the user's. So for example, if the user at the keyboard has Firefox as his default browser, it may open IE (which is the admin's default).

我知道 动词可以用来提升,但是你怎么做呢?是否有办法在服务的标准用户桌面上的默认浏览器中打开网址?

I know that the "runas" verb can be used to elevate, but how do you do it the other way around? Is there a way to open a URL in the default browser on a standard user's desktop from a service?

推荐答案

ShellExecute将执行程序在同一个会话的上下文中,并且与正在运行的进程具有相同的用户。

ShellExecute will execute the program in the context of the same session and same user as the process you are running.

如果您想使用其他工作阶段或使用者凭证,可以使用 CreateProcessAsUser Win32 API。

If you'd like to use a different session or user token you can use the CreateProcessAsUser Win32 API.

有几种方法可以获取用户令牌,例如您可以调用Win32 API:

There are several ways to obtain a user token, for example you can call the Win32 API:

  • LogonUser if you know the username and password
  • WTSQueryUserToken for any given session ID.
  • OpenProcessToken if you have another process handle

这篇关于以标准用户(C ++)打开默认浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆