相关疑难解决方法(0)

来自C#的Windows模拟

作为LocalSystem运行的C#程序如何临时模拟另一个用户的登录标识?粗略地说,我有一个Windows服务,我想作为LocalSystem运行,但有时模仿用户XYZ(当使用Windows集成安全性连接到数据库时).

最重要的是:有没有办法在不知道其他用户密码的情况下做到这一点?

注意:如果密码是强制性的,则建议安全地存储密码(c#和/或vbscript).

c# windows impersonation

30
推荐指数
3
解决办法
6万
查看次数

注册表项 getvalue 未获取最新值

我试图通过HKCU\Keyboard Layout\Preload\1从我的应用程序中读取来获取当前用户最后使用的键盘布局。每次在控制面板中更改默认键盘时,我都可以看到上述位置的值发生变化(我可以通过打开 RegEdit 来看到这一点)。但由于某种原因,我的应用程序仍然读取旧值,而不考虑我可以在 RegEdit 上看到的最新刷新。

string KeyboardLayoutRegKey = "Keyboard Layout\\Preload";
pLastUsedKeyboard = RegistryAccessor.CurrentUser.OpenSubKey(KeyboardLayoutRegKey).GetValue("1").ToString(),
Run Code Online (Sandbox Code Playgroud)

当我将值从美国英语更改为法语时,注册表中的十六进制值从 409 更改为 40c,我可以在 RegEdit 中看到这一点,但我的应用程序仍然将其读取为 409,直到我重新启动?为什么要这样做?我的应用程序针对的是 AnyCPU。

编辑

/// <summary>
/// Provides access to the registry. 
/// </summary>
public class RegistryAccessor : IRegistryAccessor
{
    /// <summary>
    /// Contains information about the current user preferences. This field reads the Windows registry base key HKEY_CURRENT_USER.
    /// </summary>
    public IRegistryKey CurrentUser
    {
        get
        {
            return new RegistryKeyWrapper(Registry.CurrentUser);
        }
    }

    /// <summary>
    /// Contains the configuration data …
Run Code Online (Sandbox Code Playgroud)

c#

5
推荐指数
1
解决办法
930
查看次数

标签 统计

c# ×2

impersonation ×1

windows ×1