steam限制离线登录

  steam联网启动后不少软件会强制更新才能启动。有时不需要更新、不想更新或者网络不稳,而有时又忘了断网再启动steam,故做此工具。

流程:

  

图标:  

C#代码如下,其它语言类似。//  steam路径写死了

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;

namespace SteamOffLine
{
    class Program
    {
        [DllImport("wininet.dll", EntryPoint = "InternetGetConnectedState")]
        public extern static bool InternetGetConnectedState(out int conState, int reder);

        static void Main(string[] args)
        {
            int n = 0;
            if (InternetGetConnectedState(out n, 0))
            {
                MessageBox.Show("Network is available!\nWon't run it.");
            }
            else
            {
                switch (MessageBox.Show("Network is unavailable!\n    Run it ???","",MessageBoxButton.OKCancel))
                {
                    case MessageBoxResult.None:
                        break;
                    case MessageBoxResult.OK:
                        Execute(@"start F:\ST\steam.exe");
                        break;
                    case MessageBoxResult.Cancel:
                        break;
                    case MessageBoxResult.Yes:
                        break;
                    case MessageBoxResult.No:
                        break;
                    default:
                        break;
                }
            }
        }

        /// <summary>
        /// 执行DOS命令,返回DOS命令的输出
        /// </summary>
        /// <param name="dosCommand">dos命令</param>
        /// <param name="milliseconds">等待命令执行的时间(单位:毫秒),
        /// 如果设定为0,则无限等待</param>
        /// <returns>返回DOS命令的输出</returns>
        public static bool Execute(string command)
        {
            //string output = ""; //输出字符串
            if (command != null && !command.Equals(""))
            {
                Process process = new Process();//创建进程对象
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.FileName = "cmd.exe";//设定需要执行的命令
                startInfo.Arguments = "/C " + command;//“/C”表示执行完命令后马上退出
                //startInfo.Arguments = command;//“/C”表示执行完命令后马上退出
                startInfo.UseShellExecute = false;//不使用系统外壳程序启动
                startInfo.RedirectStandardInput = false;//不重定向输入
                startInfo.RedirectStandardOutput = true; //重定向输出
                startInfo.CreateNoWindow = true;//不创建窗口
                process.StartInfo = startInfo;
                try
                {
                    if (process.Start())//开始进程
                    {
                        //output = process.StandardOutput.ReadToEnd();//读取进程的输出
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return false;
                }
                finally
                {
                    if (process != null)
                        process.Close();
                }
            }
            //Console.WriteLine(output);
            return false;
        }
    }
}

 

C\C++启动steam直接

system("start F:\ST\steam.exe");

 

posted @ 2021-05-24 11:42  Drake19  阅读(591)  评论(0编辑  收藏  举报