【解決方法】ディレクトリとそのすべてのサブディレクトリにある拡張子 .inf を持つすべてのファイルをインストールするファイルを作成する方法は?


マウス カーソルのあるディレクトリを含むフォルダーがあり、各ディレクトリには、そのディレクトリにあるカーソル セットをインストールして C:\Windows\Cursors に追加する .inf ファイルがあります。ユーザーが管理者として実行したときにファイルが必要です。すべての .inf ファイルを実行するので、1 つずつ実行する必要はありません。

このファイルは C# または他の言語で記述できます。他の言語のコードを理解しようとします。

以下のコードは、ファイルをインストールしながら実行しますが、それぞれの管理者に個別に要求します。

私が試したこと:

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

namespace RunAllCursorsInf
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            string path = AppDomain.CurrentDomain.BaseDirectory;
            DirectoryInfo di = new DirectoryInfo(@"G:\OneDrive\all2\BestCursors\BestCursors");


            int i = 0;
            foreach (FileInfo fi in di.GetFiles("*.inf",SearchOption.AllDirectories))
            {
                i++;
                //InstallHinfSection(IntPtr.Zero, IntPtr.Zero, fi.FullName, 0);// I need to run each inf file here
                //Process.Start(fi.FullName);


                driverInstall(fi.FullName);
            }
            MessageBox.Show(i.ToString());
        }

        static void driverInstall(string s)
        {
            var process = new Process();
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;
            process.StartInfo.FileName = "cmd.exe";

            process.StartInfo.Arguments = "/c C:\\Windows\\System32\\InfDefaultInstall.exe " + "\"" + s + "\""; // where driverPath is path of .inf file
            process.Start();
            process.WaitForExit();
            process.Dispose();
            //MessageBox.Show(@"Driver has been installed");
        }

        [DllImport("Setupapi.dll", EntryPoint = "InstallHinfSection", CallingConvention = CallingConvention.StdCall,CharSet = CharSet.Unicode)]
        public static extern void InstallHinfSection(
    [In] IntPtr hwnd,
    [In] IntPtr ModuleHandle,
    [In, MarshalAs(UnmanagedType.LPWStr)] string CmdLineBuffer,
    int nCmdShow);

    }
}

このコードは、プログラムを管理者として実行すると機能しますが、インストールの小さなウィンドウが表示され、それを要求する一部の inf ファイルで古典的なマウス設定のウィンドウが開くことがあります。

解決策 1

解決策 2

私はこれを行うことに慣れていないので、次の Google 検索を使用しました。 c# 拡張子が.infのファイルをすべてインストールするファイルの作り方[^] 最初の結果は、探しているもののようです。 C# に *.inf ファイルをインストールするには??[^] それは述べています:

rundll32.exe を使用して inf ファイルを登録できます。

そのページに詳細があります。

コメント

タイトルとURLをコピーしました