简体   繁体   English

C#管理员权限问题

[英]C# admin rights issues

I trying to make a program which connect to a game ("quick connect"). 我试图制作一个连接游戏的程序(“快速连接”)。

When i start the application as an administrator and connect to the game, it have weird issues (eg shortkeys doesn't respond for the ingame keys and the game doesn't load some model files), but when i start without admin rights it works fine, however i need the admin rights for other purposes (file operations). 当我以管理员身份启动应用程序并连接到游戏时,它出现了一些奇怪的问题(例如,快捷键无法响应游戏中的键,并且游戏无法加载某些模型文件),但是当我在没有管理员权限的情况下启动时,它可以正常工作很好,但是我需要出于其他目的(文件操作)的管理员权限。

I tried to rerun the program with the runas commandline command, the app had no admin rights, but the game still doesn't work right. 我尝试使用runas命令行命令重新运行该程序,该应用没有管理员权限,但游戏仍然无法正常运行。

// OnClick event
ProcessStartInfo proc = new ProcessStartInfo("cmd.exe", "/c runas /trustlevel:0x20000 \"myapp.exe rerun\"");
proc.WorkingDirectory = Application.StartupPath;
proc.CreateNoWindow = true;
proc.UseShellExecute = false;
Process.Start(proc);

// Program.cs
if(!admin && args[0].Equals("rerun"))
{
    ProcessStartInfo proc = new ProcessStartInfo("cmd.exe", "/c game.exe ipAndPortToConnect");
    proc.WorkingDirectory = Application.StartupPath;
    proc.CreateNoWindow = true;
    proc.UseShellExecute = false;
    Process.Start(proc);
}

I tried many combinations but none of them worked. 我尝试了许多组合,但没有一个起作用。

I can't figure out what the hell causing it... 我不知道到底是什么原因造成的...

If you check the Task Manager, you'll see the game still runs as a different user, namely Administrator. 如果您选中“任务管理器”,您将看到游戏仍然以其他用户身份运行,即管理员。 This most likely means the game saves some information in the user profile, for example under AppSettings (like hotkeys in configuration files), or game modifications that are stored in AppData, which could cause the issues you mentioned. 这很可能意味着游戏在用户配置文件中保存了一些信息,例如在AppSettings下(例如配置文件中的热键),或在AppData中存储的游戏修改,这可能会引起您提到的问题。

The user who 'reruns' your program is still the elevated user, albeit with less permissions, and that user launches the game. “重新运行”程序的用户仍然是高级用户,尽管权限较少,并且该用户启动了游戏。 You cannot "unimpersonate" a process properly to the point the OS thinks it runs as the logged in user, so you'll have to do something else. 您无法正确地“唯一化”一个进程,使操作系统认为它以登录用户身份运行,因此您必须做其他事情。

You can either see if you can move the user-specific resources to a path relative to the game, not the user, or start the process by any other means but directly from yours, for example using a Scheduled Task. 您可以查看是否可以将特定于用户的资源移动到相对于游戏而不是用户的路径,或者可以通过其他任何方式直接从您的方式(例如,使用“计划任务”)启动该过程。

But why didn't you update your existing question ? 但是,为什么不更新现有问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM