安装 C# 游标安装程序 (.inf) 文件

huangapple go评论105阅读模式
英文:

C# install Cursor installer (.inf) file

问题

I have a cursor installer file (installer.inf). Is it possible to install the cursor using C#?

我有一个光标安装程序文件(installer.inf)。是否可以使用C#安装光标?

I already tried the following code but it doesn't work and nothing happens when getting executed:

我已经尝试了以下代码,但它不起作用,执行时什么也不发生:

  1. [DllImport("Setupapi.dll", EntryPoint = "InstallHinfSection", CallingConvention = CallingConvention.StdCall)]
  2. public static extern void InstallHinfSection([In] IntPtr hwnd, [In] IntPtr ModuleHandle, [In, MarshalAs(UnmanagedType.LPWStr)] string CmdLineBuffer, int nCmdShow);
  3. public static void InstallCursor(string installerFilePath)
  4. {
  5. InstallHinfSection(IntPtr.Zero, IntPtr.Zero, installerFilePath, 0);
  6. }

By cursor installer, I mean the following file that is present when installing a new cursor on Windows:

通过光标安装程序,我指的是在Windows上安装新光标时存在的以下文件:

安装 C# 游标安装程序 (.inf) 文件

Here, the installer.inf file looks like this:

这里,installer.inf文件如下所示:

  1. [Version]
  2. signature="$CHICAGO$"
  3. [DefaultInstall]
  4. CopyFiles = Scheme.Cur, Scheme.Txt
  5. AddReg = Scheme.Reg
  6. [DestinationDirs]
  7. Scheme.Cur = 10,"%CUR_DIR%"
  8. Scheme.Txt = 10,"%CUR_DIR%"
  9. [Scheme.Reg]
  10. HKCU,"Control Panel\Cursors\Schemes","%SCHEME_NAME%",,"%10%\%CUR_DIR%\%pointer%,%10%\%CUR_DIR%\%help%,%10%\%CUR_DIR%\%work%,%10%\%CUR_DIR%\%busy%,%10%\%CUR_DIR%\%Cross%,%10%\%CUR_DIR%\%Text%,%10%\%CUR_DIR%\%Hand%,%10%\%CUR_DIR%\%Unavailiable%,%10%\%CUR_DIR%\%Vert%,%10%\%CUR_DIR%\%Horz%,%10%\%CUR_DIR%\%Dgn1%,%10%\%CUR_DIR%\%Dgn2%,%10%\%CUR_DIR%\%move%,%10%\%CUR_DIR%\%alternate%,%10%\%CUR_DIR%\%link%"
  11. [Scheme.Cur]
  12. "Normal Select.cur"
  13. "Help Select.ani"
  14. "Work in Background.ani"
  15. "Wait.ani"
  16. "Precision Select.cur"
  17. "Text Select.cur"
  18. "Handwriting.cur"
  19. "Unavailable.ani"
  20. "Vertical Resize.ani"
  21. "Horizontal Resize.ani"
  22. "Diagonal Resize 1.ani"
  23. "Diagonal Resize 2.ani"
  24. "Move.ani"
  25. "Alternate Select.cur"
  26. "Link Select.cur"
  27. [Strings]
  28. CUR_DIR = "Cursors\pkuwyc\GANT_Blue_Colorful_24x24"
  29. SCHEME_NAME = "Gant Blue"
  30. pointer = "Normal Select.cur"
  31. help = "Help Select.ani"
  32. work = "Work in Background.ani"
  33. busy = "Wait.ani"
  34. cross = "Precision Select.cur"
  35. text = "Text Select.cur"
  36. hand = "Handwriting.cur"
  37. unavailiable = "Unavailable.ani"
  38. vert = "Vertical Resize.ani"
  39. horz = "Horizontal Resize.ani"
  40. dgn1 = "Diagonal Resize 1.ani"
  41. dgn2 = "Diagonal Resize 2.ani"
  42. move = "Move.ani"
  43. alternate = "Alternate Select.cur"
  44. link = "Link Select.cur"

I don't understand too much of driver installers, but as it is a .inf file it should work like a driver installer right? Or could it be that Windows does some special stuff again.

我不太了解驱动程序安装程序,但由于它是一个.inf文件,它应该像驱动程序安装程序一样工作,对吗?或者是Windows又做了一些特殊的事情。

英文:

I have a cursor installer file (installer.inf). Is it possible to install the cursor using C#?

I already tried the following code but it doesn't work and nothing happens when getting executed:

  1. [DllImport("Setupapi.dll", EntryPoint = "InstallHinfSection", CallingConvention = CallingConvention.StdCall)]
  2. public static extern void InstallHinfSection([In] IntPtr hwnd, [In] IntPtr ModuleHandle, [In, MarshalAs(UnmanagedType.LPWStr)] string CmdLineBuffer, int nCmdShow);
  3. public static void InstallCursor(string installerFilePath)
  4. {
  5. InstallHinfSection(IntPtr.Zero, IntPtr.Zero, installerFilePath, 0);
  6. }

By cursor installer, I mean the following file that is present when installing a new cursor on Windows:

安装 C# 游标安装程序 (.inf) 文件

Here, the installer.inf file looks like this:

  1. [Version]
  2. signature="$CHICAGO$"
  3. [DefaultInstall]
  4. CopyFiles = Scheme.Cur, Scheme.Txt
  5. AddReg = Scheme.Reg
  6. [DestinationDirs]
  7. Scheme.Cur = 10,"%CUR_DIR%"
  8. Scheme.Txt = 10,"%CUR_DIR%"
  9. [Scheme.Reg]
  10. HKCU,"Control Panel\Cursors\Schemes","%SCHEME_NAME%",,"%10%\%CUR_DIR%\%pointer%,%10%\%CUR_DIR%\%help%,%10%\%CUR_DIR%\%work%,%10%\%CUR_DIR%\%busy%,%10%\%CUR_DIR%\%Cross%,%10%\%CUR_DIR%\%Text%,%10%\%CUR_DIR%\%Hand%,%10%\%CUR_DIR%\%Unavailiable%,%10%\%CUR_DIR%\%Vert%,%10%\%CUR_DIR%\%Horz%,%10%\%CUR_DIR%\%Dgn1%,%10%\%CUR_DIR%\%Dgn2%,%10%\%CUR_DIR%\%move%,%10%\%CUR_DIR%\%alternate%,%10%\%CUR_DIR%\%link%"
  11. [Scheme.Cur]
  12. "Normal Select.cur"
  13. "Help Select.ani"
  14. "Work in Background.ani"
  15. "Wait.ani"
  16. "Precision Select.cur"
  17. "Text Select.cur"
  18. "Handwriting.cur"
  19. "Unavailable.ani"
  20. "Vertical Resize.ani"
  21. "Horizontal Resize.ani"
  22. "Diagonal Resize 1.ani"
  23. "Diagonal Resize 2.ani"
  24. "Move.ani"
  25. "Alternate Select.cur"
  26. "Link Select.cur"
  27. [Strings]
  28. CUR_DIR = "Cursors\pkuwyc\GANT_Blue_Colorful_24x24"
  29. SCHEME_NAME = "Gant Blue"
  30. pointer = "Normal Select.cur"
  31. help = "Help Select.ani"
  32. work = "Work in Background.ani"
  33. busy = "Wait.ani"
  34. cross = "Precision Select.cur"
  35. text = "Text Select.cur"
  36. hand = "Handwriting.cur"
  37. unavailiable = "Unavailable.ani"
  38. vert = "Vertical Resize.ani"
  39. horz = "Horizontal Resize.ani"
  40. dgn1 = "Diagonal Resize 1.ani"
  41. dgn2 = "Diagonal Resize 2.ani"
  42. move = "Move.ani"
  43. alternate = "Alternate Select.cur"
  44. link = "Link Select.cur"

I don't understand too much of driver installers, but as it is a .inf file it should work like a driver installer right? Or could it be that Windows does some special stuff again.

答案1

得分: 0

以下的代码成功安装了光标:

  1. public void InstallCursor(string installerFilePath)
  2. {
  3. string command = @"C:\WINDOWS\System32\rundll32.exe";
  4. string arguments = "setupapi,InstallHinfSection DefaultInstall 132 " + installerFilePath;
  5. ProcessStartInfo startInfo = new ProcessStartInfo
  6. {
  7. FileName = "cmd.exe",
  8. Arguments = $"/c \"{command} {arguments}\"",
  9. Verb = "runas",
  10. UseShellExecute = true,
  11. CreateNoWindow = true,
  12. WindowStyle = ProcessWindowStyle.Hidden
  13. };
  14. Process process = new Process
  15. {
  16. StartInfo = startInfo
  17. };
  18. process.Start();
  19. process.WaitForExit();
  20. }

请注意,无论您打开的 cmd 还是打开它的应用程序,都需要以管理员权限运行,以安装 .inf 文件。

英文:

The following Code did successfully install the Cursor:

  1. public void InstallCursor(string installerFilePath)
  2. {
  3. string command = @"C:\WINDOWS\System32\rundll32.exe";
  4. string arguments = "setupapi,InstallHinfSection DefaultInstall 132 " + installerFilePath;
  5. ProcessStartInfo startInfo = new ProcessStartInfo
  6. {
  7. FileName = "cmd.exe",
  8. Arguments = $"/c \"{command} {arguments}\"",
  9. Verb = "runas",
  10. UseShellExecute = true,
  11. CreateNoWindow = true,
  12. WindowStyle = ProcessWindowStyle.Hidden
  13. };
  14. Process process = new Process
  15. {
  16. StartInfo = startInfo
  17. };
  18. process.Start();
  19. process.WaitForExit();
  20. }

Note that either the cmd you open or your Application that opens it, need to be run with Administrator priveleges to install the .inf file

huangapple
  • 本文由 发表于 2023年6月12日 13:50:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76453908.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定