Getting the path to the game through the registry + launching the process in the final folder of the path by pressing the button C # + WPF

huangapple go评论71阅读模式
英文:

Getting the path to the game through the registry + launching the process in the final folder of the path by pressing the button C # + WPF

问题

以下是您要翻译的内容:

尝试从注册表的一个部分(SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 4000)读取游戏的安装路径(InstallLocation),然后将其写入另一个部分(SOFTWARE\WpfApp)的密钥(NewInstallPath),然后在游戏的安装路径中找到游戏的可执行文件,并运行它。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;

namespace wpfApp
{

    /// <summary>
    /// 与 MainWindow.xaml 互动的逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            using var localMachineRegistry = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
            using var gmodAppRegistry = localMachineRegistry.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 4000", false);
            string readInstallPath = gmodAppRegistry.GetValue("InstallLocation").ToString();
    
            RegistryKey InstallPath = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\WpfApp", SetValue("NewInstallPath", readInstallPath)); //启动器分区路径
        }
    }

}

我已经为您翻译好了代码部分,没有翻译其他内容。

英文:

Trying to read the installation path of the game (InstallLocation) from one section in the registry (SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 4000), write it to another section (SOFTWARE\WpfApp) in key (NewInstallPath), and then find the exe file with the game in the installation path of the game, and run

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;

namespace wpfApp
{

    /// \&lt;summary\&gt;
    /// Interaction logic for MainWindow.xaml
    /// \&lt;/summary\&gt;
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            using var localMachineRegistry = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
            using var gmodAppRegistry = localMachineRegistry.OpenSubKey(@&quot;SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 4000&quot;, false);
            string readInstallPath = gmodAppRegistry.GetValue(&quot;InstallLocation&quot;).ToString();
    
            RegistryKey InstallPath = Registry.LocalMachine.CreateSubKey(@&quot;SOFTWARE\WpfApp&quot;, SetValue(&quot;NewInstallPath&quot;, readInstallPath)); //launcher partition path
        }
    }

}

As soon as I did not try to implement it, but even according to the documentation it comes out crooked. That value is recorded, but the game does not start, then nothing is recorded at all and does not start.

答案1

得分: 0

代码部分不翻译,以下是翻译好的部分:

"The way you're intended to run steam games is through steam itself."
你应该通过Steam本身来运行Steam游戏。

"Steam automatically updates the app etc."
Steam会自动更新应用等。

"There is a rungameid command line parameter which allows you to run a game ( somewhat ) directly."
有一个rungameid命令行参数,允许你相对直接地运行游戏。

"And... eventually as my login credentials install etc etc were stale..."
然后...最终,当我的登录凭据等变得陈旧时...

"Steam may be in C:\Program Files instead."
Steam可能在C:\Program Files目录中。

"The nice-ish aspect of this is that you just need to check where steam is and know your game app id."
这个好处是你只需要检查Steam的安装位置并知道你的游戏应用程序ID。

"You can also run a game that isn't currently installed this way. There will of course be quite a delay as steam goes and gets everything for you."
你也可以通过这种方式运行尚未安装的游戏。当然,这会有相当长的延迟,因为Steam会为你获取一切。

"I think some games are not so straight forward that they 'just' have the one exe. Some have launchers (ours does)."
我认为有些游戏并不像“只有一个可执行文件”那么简单。一些游戏有启动器(我们的游戏就有)。

英文:

The way you're intended to run steam games is through steam itself.

Steam automatically updates the app etc.

There is a rungameid command line parameter which allows you to run a game ( somewhat ) directly.

 &quot;C:\Program Files (x86)\Steam\steam&quot; steam://rungameid/281990

And... eventually as my login credentials install etc etc were stale...

Getting the path to the game through the registry + launching the process in the final folder of the path by pressing the button C # + WPF

Steam may be in C:\Program Files instead.

The nice-ish aspect of this is that you just need to check where steam is and know your game app id.

You can also run a game that isn't currently installed this way. There will of course be quite a delay as steam goes and gets everything for you.

I think some games are not so straight forward that they "just" have the one exe. Some have launchers ( ours does ).

huangapple
  • 本文由 发表于 2023年2月10日 04:27:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75404088.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定