0

I have a folder with a hundred mouse cursor sets, each set has an .INF file that when right clicked and "Install" is clicked and pressing yes for running as admin the set gets added to the Mouse Properties in settings.

I now install them one by one.

int i = 0;
foreach (FileInfo fi in new DirectoryInfo(@"C:\Users\xyz\Dropbox\all2\BestCursors\").GetFiles("*.*", SearchOption.AllDirectories))
            {
                if (fi.Extension == ".inf")
                {

                    i++;

                    //InstallHinfSection(IntPtr.Zero, IntPtr.Zero, fi.FullName, 0);



                    //System.Diagnostics.Process.Start("cmd.exe", "drvload "+ fi.FullName.Replace(@"\\",@"\"));




                    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 " + fi.FullName.Replace(@"\\", @"\"); // where driverPath is path of .inf file
                    process.Start();
                    process.WaitForExit();
                    process.Dispose();
                }
            }
            MessageBox.Show(i.ToString());

And include subfolders too.

I want all the mouse sets inside that directory which is on the hard drive to be added to Mouse Properties in Windows 10 settings.

  • I found this but both ways in it didn't work for me: https://stackoverflow.com/questions/2032493/install-uninstall-an-inf-driver-programmatically-using-c-sharp-net – LeonardoThomas_1 Jul 06 '19 at 17:25
  • What code did you use to PInvoke `InstallHinfSection` (or `InstallHinfSectionW`)? What command did you issue? What is your `.inf`'s section header were the `Install` informations are definied? What does *didn't work for me* mean? Errors? Exceptions? Nothing happened? – Jimi Jul 06 '19 at 19:49
  • It runs correctly and installs some .inf files, for other correctly formatted .inf files it tells me: "Install Error: The parameter is incorrect". – LeonardoThomas_1 Jul 06 '19 at 20:00
  • *for other correctly formatted (...) Error*: re-evaluate this information, based on the previous phrase: *It runs correctly and installs some*. You didn't say which version of the Win32 Function you used and with which command. – Jimi Jul 06 '19 at 20:10
  • So, you didn't use the Win32 function. All right. See here: [INF DefaultInstall Section](https://learn.microsoft.com/en-us/windows-hardware/drivers/install/inf-defaultinstall-section) to verify whether your `.INF` files are formatted correctly. Also, try this other batch-style command: `RunDll32 advpack.dll,LaunchINFSection [Your .inf path],DefaultInstall`. Try to also set the [ProcessStartInfo.WorkingDirectory](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.workingdirectory) to the path of the `.inf` file you're installing (all of them??). – Jimi Jul 06 '19 at 20:34
  • I did the 3rd thing, the 1st thing: I know the .inf file is formatted properly because I can install with a right click in File Explorer... the 2nd thing: takes forever for WaitForExit. – LeonardoThomas_1 Jul 06 '19 at 22:11
  • If the *1st thing* is the API call, it won't work because that's not the way to supply the command. If *the 2nd* is `System.Diagnostics.Process.Start("cmd.exe", "drvload ...)`. That won't work for more than one reason. The 3rd option can work (except, why are you redirecting `stdIn` and `stdErr`, since those won't be used - and you don't use them. Also what's this `.Replace(@"\\", @"\")` about? It doesn't do anything + you can prefilter with `.GetFiles("*.inf", ...)`) if the INF file is correct. [About INF Files](https://docs.microsoft.com/en-us/windows/win32/setupapi/about-inf-files).. – Jimi Jul 06 '19 at 22:41
  • Check the `[Strings]` and `[Scheme.Reg]` sections' content (the actual file list and the registry section affected). The `[Version]` section (the only one section that is mandatory), should represent the current system. The `[DefaultInstall]` section enumerates the .INF section to consider when the installation is started. All path (Registry and Local drive) must be relative to the current System version requirements. See that you don't have overlapping theme's names and all paths referenced have a *physical* match. – Jimi Jul 06 '19 at 22:48
  • Sorry the last 2 comments are beyond my knowledge. – LeonardoThomas_1 Jul 07 '19 at 13:55
  • The first comment is realated to the code you wrote. The second comment is about the content of the `INF` files, which you just need to inspect, comparing it with the informations provided in the Docs (and the notes I wrote). – Jimi Jul 07 '19 at 21:55

0 Answers0