I have a folder with directories with mouse cursors, each directory has a .inf file that installs the cursor set that is in that directory and adds it to C:\Windows\Cursors, I want a file that when the user runs it as admin it runs all the .inf files so one doesn't have to go on them one by one please.
The file can be written by C# or another language, I will try to understand the other language's code.
The code below runs the files as installing them but asks for admin for each one separately.
What I have tried:
using System;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace RunAllCursorsInf
{
static class Program
{
[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++;
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 + "\"";
process.Start();
process.WaitForExit();
process.Dispose();
}
[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);
}
}
This code, with making the program run as admin, works but shows a small window of installation and sometimes opens the window of the clasic Mouse Settings in some inf files that request that.