none
read driver from c# applicxation RRS feed

  • Question

  • Hello everyone,

    I try to create an application to get some info from windows like serial, bios info and read the driver from device manager

    For bios and serial number I  used this class ProcessStartInfo  (bios and serial are working using wmic)

    for instance

     private void bt_bios_Click(object sender, EventArgs e)
            {
                System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo("CMD.EXE", "/K wmic bios get smbiosbiosversion");

                info.Verb = "open";

                System.Diagnostics.Process.Start(info);
            }

     for pnputil,  I wrote down

    , it doesn't work

    where is my error?

     private void bt_controller_Click(object sender, EventArgs e)
            {
                System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo("CMD.EXE", "/K pnputil -e");

                info.Verb = "open";

                System.Diagnostics.Process.Start(info);
            }

    I will appreciate any help

    thanks

    Jose





    Thursday, May 10, 2018 8:59 PM

All replies

  • Your code works fine for me.  The error doesn't make much sense, because pnputil.exe is located in the same directory as cmd.exe, which it was obviously able to find.  If you do "dir \windows\system32\pnputil.exe", does it find the file?

    If you run "PATH" instead of "pnputil -e", do you see \windows\system32 in the path list?


    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    Thursday, May 10, 2018 9:13 PM
  • Is it possible you are running this on a shared school computer, where "pnputil" has been removed to prevent damage?

    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    Thursday, May 10, 2018 9:14 PM
  • It is a classic problem : Wow redirection.

    Add first :

    bool bWow64 = false;
    IsWow64Process(Process.GetCurrentProcess().Handle, out bWow64);
    if (bWow64)
    {
        IntPtr OldValue = IntPtr.Zero;
        bool bRet = Wow64DisableWow64FsRedirection(out OldValue);
    }

    with :

    [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
            private static extern bool IsWow64Process(IntPtr hProcess, out bool Wow64Process);
    
    [DllImport("Kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
            private static extern bool Wow64DisableWow64FsRedirection(out IntPtr OldValue);

    • Proposed as answer by valat Friday, May 11, 2018 6:39 AM
    Thursday, May 10, 2018 9:23 PM
  • If you were to use the same user id for all your questions instead of creating a new user for each question then I would spend more time to help.

    Are you familiar with WMI and the System.Management Namespace? You should be able to get everything or nearly everything with those.



    Sam Hobbs
    SimpleSamples.Info

    Friday, May 11, 2018 3:35 AM
  • Yes.  I was thinking that his "CMD.EXE" would always load a 64-bit process, but you are right.  If he has a 32-bit process, this will load syswow64\cmd, and he will get a 32-bit command shell.

    So, to the original poster, you are apparently forcing your process to a 32-bit architecture.  That's the root of the problem.  If you allow your solution to compile for AnyCPU, it will run as a 64-bit process on a 64-bit system, and your problem will go away.


    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    Friday, May 11, 2018 10:05 PM