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");

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM