Jump to content

Total Bum - Getting info from RunWait() / Run()


Recommended Posts

I must say i am total bum about this. Been playing with code a bit and all i could get was nothing ;p I saw MHz solution (UDF in scripts & scraps) but couldn't realy make any use of it due to lack of my skills ;p So please help me out on that one.. maybe i'll catch on and will never bother to ask about this again :mellow: What i need to get is output from RunWait($devcon & " remove =Unknown") .. if i will know output from it and it contains string No devices removed. then i will skip few other steps. Or few other variations.. i'm hopeing with some help i can start getting info by myself :) So pls be gentle.

FileInstall("c:\devcon.exe", @TempDir & "devcon.exe")
FileInstall("c:\setdevicepath.exe", @TempDir & "setdevicepath.exe")

Dim $devcon = @TempDir & "devcon.exe"
Dim $setdevicepath = @TempDir & "SetDevicePath.exe"
Dim $drivers = "D:\Drivers"


FindHardware($drivers)
RestoreDefault()

Func FindHardware($path_to_drivers)
    RunWait($setdevicepath & " " & $path_to_drivers)
    RunWait($devcon & " remove =Unknown")
    RunWait($devcon & " rescan")
EndFunc

Func RestoreDefault()
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "DevicePath", "REG_EXPAND_SZ", "%SystemRoot%\inf")
EndFunc

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

If your relating to me about the ExitCode from Run() post, then your code does not show any use of it. One problem that I immediately noticed is that you have missing backslashes in your paths. Good advise for debugging to to add suspect items into a MsgBox or ConsoleWrite to find out what the command looks like at runtime.

This is one of your paths:

MsgBox(0, 'Debug', @TempDir & "devcon.exe")

Notice the missing backslash when you run the MsgBox.

You just need to build your skills alittle more with basic debugging as I have shown to help you advanced yourself into some more advanced uses of AutoIt.

:)

Link to comment
Share on other sites

Tnx for the hint with backslash. And you'er also right on that ExitCode.. at the begining i thought it might be the thing i need but it isn't. What i need is some way to read whatever RunWait()/Run() says on screen when it starts the program. Devcon.exe should give some output to dos window.. i need to read it and make use of it. Still looking for a way to do it. I tried to do it this way.. but the msgbox is empty and when the program ends in status window i get actual response of that program.. i'm totally confused here.. :)

>Running AU3Check (1.54.1.1) params: from:C:\Program Files\AutoIt3\beta

+>AU3Check ended.rc:0

>Running:(3.1.1.113):C:\Program Files\AutoIt3\beta\autoit3.exe "I:\Project.AU3\test.au3"

devcon.exe Usage: devcon.exe [-r][-m:\\<machine>] <command> [<arg>...]

For more information type: devcon.exe help

+>AutoIT3.exe ended.rc:0

>Exit code: 0 Time: 2.310

$stdout = Run(@ComSpec & " /c c:\devcon.exe", '', @SW_HIDE, 2)
    Global $all
    While 1
        $data = StdoutRead($stdout)
        If @error Then ExitLoop
        If $data Then
            $all &= $data
        Else
            Sleep(10)
        EndIf
    WEnd
MsgBox(1, "DUPA", $all)
Edited by MadBoy

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

Your usage is fine.

You are only using Devcon without parameters, so all you get at a cmd prompt is the startup banner. You do not want that banner stuff, right :mellow: . The startup banner is not quite regarded as STDIO data. You need to set Devcon into use with asking for output on one or more of it's switches.

Try this.

$stdout = Run(@ComSpec & " /c c:\devcon.exe find *", '', @SW_HIDE, 2)
Global $all
While 1
    $data = StdoutRead($stdout)
    If @error Then ExitLoop
    If $data Then
        $all &= $data
    Else
        Sleep(10)
    EndIf
WEnd
MsgBox(1, "DUPA", $all)
I get a big MsgBox full of output.

:)

Edited by MHz
Link to comment
Share on other sites

Your usage is fine.

You are only using Devcon without parameters, so all you get at a cmd prompt is the startup banner. You do not want that banner stuff, right :mellow: . The startup banner is not quite regarded as STDIO data. You need to set Devcon into use with asking for output on one or more of it's switches.

Ah nice :)) Looks much better now, i was just testing "any" output so i could work on that and was suprised with lack of output. Tnx Again!

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

I need help once again:) I have in my code line $output = StringSplit($output, @CRLF) which creates an array of all text showing on screen. That's cool. But now i need to do some use of it. I know that $output[0] will give me number of lines i have.. i also noticed that it usually gives me 2 empty lines at the end so if $output[0] is 5 .. last sentence is in line 3. And i'm especially interested in that last string.. if it's: " 5 device(s) removed." or "No devices removed.". I couldn't realy make it to work. Need help on that. Eventually i will need to output some more info from $output array but atm i can't see good solution. Please me help me on that :)

FileInstall("c:\devcon.exe", @TempDir & "\devcon.exe")
FileInstall("c:\setdevicepath.exe", @TempDir & "\setdevicepath.exe")

Global $output
Dim $devcon = @TempDir & "\devcon.exe"
Dim $setdevicepath = @TempDir & "\SetDevicePath.exe"
Dim $drivers = "D:\Drivers"


FindHardware($drivers)

Func FindHardware($path_to_drivers); 
    RunWait($setdevicepath & " " & $path_to_drivers)
    $DevconRemoveOutput = Run(@ComSpec & " /c c:\devcon.exe remove =Monitor", '', @SW_HIDE, 2)
    While 1
        $DevconRemoveData = StdoutRead($DevconRemoveOutput)
        If @error Then ExitLoop
        If $DevconRemoveData Then
            $output &= $DevconRemoveData
        Else
            Sleep(10)
        EndIf
    WEnd
    $output = StringSplit($output, @CRLF)
    $dupa = StringInStr ( $output[3], "device(s) removed.")
    MsgBox(1, "DUPA3", $dupa)
    
    If $output[1] = "No devices removed." Then 
       ;MsgBox(1, "DUPA1", $output[1] & " " & $output[0] & " " & $output[2] & " " & $output[3] & " " & $output[4] & " " & $output[5])
    Else
   ; MsgBox(1, "DUPA2", $output[1] & " " & $output[0] & " " & $output[2] & " " & $output[3] & " " & $output[4] & " " & $output[5])
    $DevconRescanOutput = Run(@ComSpec & " /c c:\devcon.exe rescan", '', @SW_HIDE, 2)
    EndIf
EndFunc

Func RestoreDefault()
    RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "DevicePath", "REG_EXPAND_SZ", "%SystemRoot%\inf")
EndFunc

My little company: Evotec (PL version: Evotec)

Link to comment
Share on other sites

Do read the Docs for StringSplit and the use of it's optional parameter. It is a commonly used string function and should be known for it's abilities.

Let me show it in a similar working concept. Hopefully this example may show you more clearly of what you may need to do.

; Run Devcon to find some hardware specs

$stdout = Run(@ComSpec & " /c c:\devcon.exe find *", '', @SW_HIDE, 2)


; Get the StdOut information

Global $all
While 1
    $data = StdoutRead($stdout)
    If @error Then ExitLoop
    If $data Then
        $all &= $data
    Else
        Sleep(10)
    EndIf
WEnd


; Remove whitespace from either end of the data. Includes end of line characters

$all = StringStripWS($all, 3)


; Split the data into array elements for each line. Important: 3rd parameter of StringSplit used !!!
; Note: @CRLF is 2 chars.

$split = StringSplit($all, @CRLF, 1)
If @error Then
    MsgBox(0, 'Experienced problems spliting this', $split[1])
    Exit
EndIf


; Loop through the array and locate CDROM and show each instance in a MsgBox

For $i = 1 To $split[0]
    If StringInStr($split[$i], 'CDROM') Then
        If MsgBox(1, "DUPA", $split[$i]) = 2 Then ExitLoop
    EndIf
Next


; Show last element

MsgBox(0, 'Last element', $split[$split[0]])
Edited by MHz
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...