diff --git a/class_test.go b/class_test.go deleted file mode 100644 index 96a0bdf..0000000 --- a/class_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package devcon_test - -import ( - "fmt" - - "github.com/mikerourke/go-devcon" -) - -func ExampleDevCon_Classes() { - dc := devcon.New(`\path\to\devcon.exe`) - - classes, _ := dc.Classes() - - fmt.Printf("Name: %s, Description: %s", classes[0].Name, classes[0].Description) - // Output: Name: WCEUSBS, Description: Windows CE USB Devices -} - -func ExampleDevCon_ClassFilter_query() { - dc := devcon.New(`\path\to\devcon.exe`) - - result, _ := dc.ClassFilter("DiskDrive", devcon.ClassFilterUpper) - - fmt.Printf("Filters: %q, Was changed: %v, Requires reboot: %v", - result.Filters, result.WasChanged, result.RequiresReboot) - // Output: Filters: ["PartMgr" "Disklog"], Was changed: false, Requires reboot: false -} - -func ExampleDevCon_ClassFilter_update() { - dc := devcon.New(`\path\to\devcon.exe`) - - result, _ := dc.ClassFilter("DiskDrive", devcon.ClassFilterUpper, "+Disklog") - - fmt.Printf("Filters: %q, Was changed: %v, Requires reboot: %v", - result.Filters, result.WasChanged, result.RequiresReboot) - // Output: Filters: ["PartMgr" "Disklog"], Was changed: true, Requires reboot: true -} - -func ExampleDevCon_ListClass() { - dc := devcon.New(`\path\to\devcon.exe`) - - classes, _ := dc.ListClass("ports", "keyboard") - - fmt.Printf("Class: 'ports', First Device ID: %s\n", classes["ports"][0].ID) - fmt.Printf("Class: 'keyboard', First Device Name: %s\n", classes["ports"][0].Name) - // Output: - // - // Class: 'ports', First Device ID: "ACPI\\PNP0400\\1" - // Class: 'keyboard', First Device Name: "Standard 101/102-Key or Microsoft Natural PS/2 Keyboard" -} diff --git a/devcon.go b/devcon.go index 88c4724..63dc28e 100644 --- a/devcon.go +++ b/devcon.go @@ -125,8 +125,7 @@ func (dc *DevCon) run(command command, args ...string) ([]string, error) { dc.RemotePath = "" if dc.ExeFilePath == "" { - return readTestDataFile(command) - // return nil, errors.New("invalid devcon.exe path specified") + return nil, errors.New("invalid devcon.exe path specified") } if _, err := os.Stat(dc.ExeFilePath); os.IsNotExist(err) { @@ -174,16 +173,3 @@ func (dc *DevCon) logResults(lines []string) { fmt.Println(line) } } - -func readTestDataFile(command command) ([]string, error) { - fileName := fmt.Sprintf("%s.txt", command.String()) - - path := filepath.Join("testdata", fileName) - - bytes, err := ioutil.ReadFile(path) - if err != nil { - return nil, fmt.Errorf("error reading test data file: %w", err) - } - - return splitLines(string(bytes)), nil -} diff --git a/devcon_test.go b/devcon_test.go new file mode 100644 index 0000000..018789a --- /dev/null +++ b/devcon_test.go @@ -0,0 +1,38 @@ +package devcon_test + +import ( + "fmt" + "strings" + + "github.com/mikerourke/go-devcon" +) + +func Example_install() { + dc := devcon.New(`C:\windows\devcon.exe`) + + devs, err := dc.Find("*VEN_8086*") + if err != nil { + fmt.Println(err) + + return + } + + var matchingDev devcon.Device + + for _, dev := range devs { + if strings.Contains(dev.Name, "PRO") { + matchingDev = dev + break + } + } + + if matchingDev.ID != "" { + err = dc.Install(`C:\drivers\PRO1000\WIN32\E1000325.INF`, matchingDev.ID) + if err != nil { + fmt.Printf("error installing: %s", err) + } else { + fmt.Println("Successfully installed") + + } + } +} diff --git a/device_test.go b/device_test.go deleted file mode 100644 index 25e5a58..0000000 --- a/device_test.go +++ /dev/null @@ -1,91 +0,0 @@ -package devcon_test - -import ( - "fmt" - - "github.com/mikerourke/go-devcon" -) - -func ExampleDevCon_Disable_specific() { - dc := devcon.New(`\path\to\devcon.exe`) - - _ = dc.WithConditionalReboot().Disable(`@USB\ROOT_HUB\4&2A40B465&0`) -} - -func ExampleDevCon_Disable_pattern() { - dc := devcon.New(`\path\to\devcon.exe`) - - _ = dc.Disable("USB*") -} - -func ExampleDevCon_Enable_specific() { - dc := devcon.New(`\path\to\devcon.exe`) - - _ = dc.Enable(`'*PNP0000`) -} - -func ExampleDevCon_Enable_class() { - dc := devcon.New(`\path\to\devcon.exe`) - - _ = dc.WithConditionalReboot().Enable("=Printer") -} - -func ExampleDevCon_Find_everything() { - dc := devcon.New(`\path\to\devcon.exe`) - - devs, _ := dc.Find("*") - for _, dev := range devs { - fmt.Printf("ID: %s, Name: %s\n", dev.ID, dev.Name) - } - // Output: - // ID: ACPI\ACPI0010\2&DABA3FF&0, Name: Generic Bus - // ID: ACPI\FIXEDBUTTON\2&DABA3FF&0, Name: ACPI Fixed Feature Button - // ... -} - -func ExampleDevCon_Find_pattern() { - dc := devcon.New(`\path\to\devcon.exe`) - - devs, _ := dc.Find(`@root\legacy*`) - for _, dev := range devs { - fmt.Printf("ID: %s, Name: %s\n", dev.ID, dev.Name) - } - // Output: - // ID: ROOT\LEGACY_AFD\0000, Name: AFD Networking Support Environment - // ID: ROOT\LEGACY_BEEP\0000, Name: Beep - // ... -} - -func ExampleDevCon_FindAll() { - dc := devcon.New(`\path\to\devcon.exe`) - - devs, _ := dc.FindAll("=net") - for _, dev := range devs { - fmt.Printf("ID: %s, Name: %s\n", dev.ID, dev.Name) - } - // Output: - // ID: ROOT\MS_L2TPMINIPORT\0000, Name: WAN Miniport (L2TP) - // ID: ROOT\MS_NDISWANIP\0000, Name: WAN Miniport (IP) - // ... -} - -func ExampleDevCon_Install() { - dc := devcon.New(`\path\to\devcon.exe`) - - _ = dc.Install(`c:\windows\inf\keyboard.inf`, "*PNP030b") -} - -func ExampleDevCon_Remove() { - dc := devcon.New(`\path\to\devcon.exe`) - - _ = dc.WithConditionalReboot().Remove(`@usb\*`) -} - -func ExampleDevCon_Restart() { - dc := devcon.New(`\path\to\devcon.exe`) - - statuses, _ := dc.Restart("=net", `@'ROOT\*MSLOOP\0000`) - - fmt.Printf("ID: %s, Restarted: %v\n", statuses[0].ID, statuses[0].WasRestarted) - // Output: ID: ROOT\*MSLOOP\0000, Restarted: true -} diff --git a/driver_test.go b/driver_test.go deleted file mode 100644 index 5a77c32..0000000 --- a/driver_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package devcon_test - -import ( - "fmt" - - "github.com/mikerourke/go-devcon" -) - -func ExampleDevCon_DriverFiles() { - dc := devcon.New(`\path\to\devcon.exe`) - - dfs, _ := dc.DriverFiles(`ACPI\PNP0303\4&1D401FB5&0`) - - df := dfs[3] - - fmt.Printf("ID: %s, INF file: %s, INF section: %s\n", - df.Device.ID, df.INFFile, df.INFSection) - fmt.Printf("Files: %q", df.Files) - // Output: - // ID: ACPI\PNP0303\4&1D401FB5&0, INF file: c:\windows\inf\keyboard.inf, INF section: STANDARD_Inst - // Files: ["C:\\WINDOWS\\system32\\DRIVERS\\i8042prt.sys" "C:\\WINDOWS\\system32\\DRIVERS\\kbdclass.sys"] -} - -func ExampleDevCon_DriverNodes() { - dc := devcon.New(`\path\to\devcon.exe`) - - dns, _ := dc.DriverNodes("*") - - fmt.Printf("ID: %s, Node description: %s\n", - dns[0].Device.ID, dns[0].Nodes[0].Description) - // Output: ID: ACPI\ACPI0010\2&DABA3FF&0, Node description: Generic Bus -} diff --git a/hwids_test.go b/hwids_test.go deleted file mode 100644 index 4f3410a..0000000 --- a/hwids_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package devcon_test - -import ( - "fmt" - - "github.com/mikerourke/go-devcon" -) - -func ExampleDevCon_HwIDs_local() { - dc := devcon.New(`\path\to\devcon.exe`) - - hwids, _ := dc.HwIDs("*") - - for _, hwid := range hwids { - fmt.Printf("Device ID: %s, Hardware IDs: %s\n", hwid.Device.ID, hwid.HardwareIDs) - } - // Output: - // Device ID: ACPI\ACPI0010\2&DABA3FF&0, Hardware IDs: [ACPI\ACPI0010 *ACPI0010] - // Device ID: ACPI\FIXEDBUTTON\2&DABA3FF&0, Hardware IDs: [ACPI\FixedButton *FixedButton] - // ... -} - -func ExampleDevCon_HwIDs_remote() { - dc := devcon.New(`\path\to\devcon.exe`) - - hwids, _ := dc.WithRemoteComputer(`\\server01`).HwIDs("*floppy*") - - for _, hwid := range hwids { - fmt.Printf("Device ID: %s, Hardware IDs: %s\n", hwid.Device.ID, hwid.HardwareIDs) - } - // Output: - // Device ID: ACPI\ACPI0010\2&DABA3FF&0, Hardware IDs: [ACPI\ACPI0010 *ACPI0010] - // Device ID: ACPI\FIXEDBUTTON\2&DABA3FF&0, Hardware IDs: [ACPI\FixedButton *FixedButton] - // ... -} diff --git a/oem_test.go b/oem_test.go deleted file mode 100644 index 5bfc71b..0000000 --- a/oem_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package devcon_test - -import ( - "fmt" - - "github.com/mikerourke/go-devcon" -) - -func ExampleDevCon_DPEnum() { - dc := devcon.New(`\path\to\devcon.exe`) - - pkgs, _ := dc.DPEnum() - - fmt.Printf("Name: %s, Provider: %s, Class: %s", - pkgs[0].Name, pkgs[0].Provider, pkgs[0].Class) - // Output: Name: oem2.inf, Provider: Microsoft, Class: unknown -}