Jump to content

read text from command line operation


Recommended Posts

Hi,

I am hoping that this post will fall under this area of the forum. I am trying to read the filter state line from the FBWF (File Base Write Filter) under WES (Windows Embedded Standard). I have written a utility that enables and disables the filter and do some other functions. HOwever, I am stock on being able to display the state of the filter once FBWFMRG.exe /displayconfig is run from the command line. I have looked at fileOpen and FileRead commands but if I understand it correctly, they work with text files. The result of the file once it is run is displayed on a line as "Filter State : enabled" or "disabled". Does anyone have any idea as to how I can get that information read and displayed on a gui or display a message box?

Thanks

Link to comment
Share on other sites

A short example:

#include <Constants.au3>

$DirCmd = Run(@ComSpec & " /c dir c:\", "C:\", @SW_HIDE, $STDOUT_CHILD+$STDERR_CHILD)
Local $ResponseText
While 1
    $ResponseText &= StdoutRead($DirCmd)
    If @error Then ExitLoop
Wend
MsgBox(0, "Dir c:\", $ResponseText)

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

A short example:

#include <Constants.au3>

$DirCmd = Run(@ComSpec & " /c dir c:\", "C:\", @SW_HIDE, $STDOUT_CHILD+$STDERR_CHILD)
Local $ResponseText
While 1
    $ResponseText &= StdoutRead($DirCmd)
    If @error Then ExitLoop
Wend
MsgBox(0, "Dir c:\", $ResponseText)

Hi enaiman,

First I want to thank you again for your previous help with my project. I am almost finished with the exception of this issue and a password protection. I understand what you have proposed, however, I have to check the filter state by looking for the string called "enable" or "disable" that occure twice in the process when the file is executed. I know what I have written will not work because the StringInstr statement is wrong. I also do not think I have everything else properly coded and I do not know how to apply what I have read from help files to the code. Do you have any suggestion.

Thanks

Mehrdad

#include <Constants.au3>

Dim $syspath = "c:\windows\system32\"
Dim $FBWF = "FBWFMGR.exe /displayconfig"

$DirCmd = RunWait(@ComSpec & " /c " & $syspath & $FBWF, @SW_HIDE, $STDOUT_CHILD+$STDERR_CHILD)

While 1
    If StringInStr("filter state : ", "enable", 2)
    MsgBox(0, "The Filter is ENABLED")
Else
    MsgBox(0, "The Filter is DISABLED")
EndIf
Wend
Link to comment
Share on other sites

It is funny >_<

You have got the first part of my example perfectly but ... next lines are a disaster :(

Here is how it should look:

#include <Constants.au3>

Dim $syspath = "c:\windows\system32\"
Dim $FBWF = "FBWFMGR.exe /displayconfig"

$DirCmd = RunWait(@ComSpec & " /c " & $syspath & $FBWF, @SW_HIDE, $STDOUT_CHILD+$STDERR_CHILD)

While 1
    $ResponseText &= StdoutRead($DirCmd)
    If @error Then ExitLoop
Wend
    
If StringInStr($ResponseText, "filter state : enable")
    MsgBox(0, "Enabled", "The Filter is ENABLED")
Else
    MsgBox(0, "Disabled", "The Filter is DISABLED")
EndIf

Mistakes:

- By getting rid of the part I've put in the While loop, you didn't get the returned text properly

- If StringInStr("filter state : ", "enable", 2) this is another big mistake => you were trying to find "enable" in "filter state : "

- what's the command syntax for MsgBox ??

You might want to replace "filter state : enable" from my example with the correct string you are looking for.

Also - read again StringInStr function :(

Your attempt is not bad at all - we all were beginers once and we all have made mistakes; what is important is the ability to learn from them.

Always - keep the AutoIt help open and look for every command you're not sure about. After 3 years, I still have the help file open and I use it very often.

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

It is funny >_<

You have got the first part of my example perfectly but ... next lines are a disaster :(

Here is how it should look:

#include <Constants.au3>

Dim $syspath = "c:\windows\system32\"
Dim $FBWF = "FBWFMGR.exe /displayconfig"

$DirCmd = RunWait(@ComSpec & " /c " & $syspath & $FBWF, @SW_HIDE, $STDOUT_CHILD+$STDERR_CHILD)

While 1
    $ResponseText &= StdoutRead($DirCmd)
    If @error Then ExitLoop
Wend
    
If StringInStr($ResponseText, "filter state : enable")
    MsgBox(0, "Enabled", "The Filter is ENABLED")
Else
    MsgBox(0, "Disabled", "The Filter is DISABLED")
EndIf

Mistakes:

- By getting rid of the part I've put in the While loop, you didn't get the returned text properly

- If StringInStr("filter state : ", "enable", 2) this is another big mistake => you were trying to find "enable" in "filter state : "

- what's the command syntax for MsgBox ??

You might want to replace "filter state : enable" from my example with the correct string you are looking for.

Also - read again StringInStr function :(

Your attempt is not bad at all - we all were beginers once and we all have made mistakes; what is important is the ability to learn from them.

Always - keep the AutoIt help open and look for every command you're not sure about. After 3 years, I still have the help file open and I use it very often.

Hi enaiman,

Thanks for your suggestions. You’re absolutely correct that I have made a lot of stupid mistakes. Although, I am still a beginner (very beginner) in using Autoit, with the help from people like yourself, I have learned more in the past two months than I thought possible. I could not even make sense of what any of the codes meant. I feel like I can somewhat understand how the code works even if I cannot put them together effectively yet. I fixed a few things that were missing from the code like declaring the variables. Once I run the application, I was getting the wrong state from the filter information. No matter what the filter state was, I was getting the Disabled state every time. I changed the “if” statements a bit and now when I run the program within the whole application, the button does not do anything. I am not sure why the If statement does not work the way it is now. I have attached the entire application as well as the screen output of the filter state display. I thank you in advance for your input.

Thanks

Mehrdad

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>


Opt('MustDeclareVars', 1)

Utility()

Func Utility()
    Local $filemenu, $fileitem, $logochange, $exititem, $passwordset, $permission
    Local $helpmenu, $helpitem, $runmenu, $runitem, $msg, $file, $DirCmd, $ResponseText
    Local $WPEnable, $WPDisable, $WPState, $Restart, $Finish, $font, $widthCell
    Local $runTaskMan, $runCMD, $runUVNC, $STDOUT_CHILD, $STDERR_CHILD
    Dim $syspath = "c:\windows\system32\"
    Dim $fbwf = "fbwfmgr.exe "
    dim $Clogo = "changelogo.bat"
    
    GUICreate("DVR Management", 150, 350, -1, -1, 0x16C00000)

    $filemenu = GUICtrlCreateMenu("&Tools")
    $passwordset = GUICtrlCreateMenuItem("Set Password", $filemenu)
    $logochange = GUICtrlCreateMenuItem("Change Logo", $filemenu)
    $permission = GUICtrlCreateMenuItem("Set Permissions", $filemenu)
    $exititem = GUICtrlCreateMenuItem("Exit", $filemenu)
    
    $helpmenu = GUICtrlCreateMenu("Help")
    $helpitem = GUICtrlCreateMenuItem("How To", $helpmenu)

    $runmenu = GUICtrlCreateMenu("Run", -1, 1)
    $runTaskMan = GUICtrlCreateMenuItem("Task Manager", $runmenu)
    $runCMD = GUICtrlCreateMenuItem("Command Prompt", $runmenu)
    $runUVNC = GUICtrlCreateMenuItem("Ultr@VNC", $runmenu)
    
    $widthCell = 25
    Opt("GUICoordMode", 2)
    
    $WPEnable = GUICtrlCreateButton("Enable Protection", 1 * $widthcell, 50, 100, 20)
    $WPDisable = GUICtrlCreateButton("Disable Protection", -1, 30, 100, 20)
    $WPState = GUICtrlCreateButton("Protection Status", -1, 30, 100, 20)
    $Restart = GUICtrlCreateButton("REBOOT", -1, 60, 100, 20)
    $Finish = GUICtrlCreateButton("Close", -1, 30, 100, 20)
    
    GUISetState()      

    While 1
        $msg = GUIGetMsg()
            Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
                Case $msg = $WPEnable   
                    RunWait(@ComSpec & " /C " & $syspath & $fbwf & " /enable")    ; Will Enable Write Protection
                    MsgBox(4096, "", "Please Click on REBOOT for protection to be Enabled!")

                Case $msg = $WPDisable
                    RunWait(@ComSpec & " /c " & $syspath & $fbwf & " /disable")    ; Will Disable Write Protection
                    MsgBox(4096, "", "Please Click on REBOOT for protection to be Disabled!")

                Case $msg = $WPState
                    $DirCmd = RunWait(@ComSpec & " /k " & $syspath & $fbwf & " /displayconfig", @SW_HIDE, $STDOUT_CHILD+$STDERR_CHILD)
                ;   $DirCmd = RunWait(@ComSpec & " /c " & $syspath & $fbwf & " /displayconfig", @SW_HIDE, $STDOUT_CHILD+$STDERR_CHILD)                  
                    While 1
                        $ResponseText &= StdoutRead($DirCmd)
                        If @error Then ExitLoop
                        Wend
    
                        If StringInStr($ResponseText, "filter state: enabled.") Then
                            MsgBox(0, "Enabled", "Write Protection is ENABLED")
                        ElseIf StringInStr($ResponseText, "filter state: disabled.") Then
                            MsgBox(0, "Disabled", "Write Protection is DISABLED")
                        EndIf

                Case $msg = $Restart
                    MsgBox(4096, "", "The DVR will Restart now!")
                    Shutdown(2)
                
                Case $msg = $Finish
                    MsgBox(4096, "", "Are you sure you want to Exit?")              
                    Exit
                    
                Case $msg = $runTaskMan
                    Run( "taskmgr", $syspath)
                    
                case $msg = $runCMD
                    RunWait(@ComSpec & " /k", @WindowsDir)  
                    
                Case $msg = $passwordset
                ;   Run( "SetPassword.exe", $syspath)
                    MsgBox(4096, "", "This starts the password setup program...")
                    
                case $msg = $logochange
                ;   RunWait(@ComSpec & " /c" & $syspath & $Clogo)
                    MsgBox(4096, "", "This starts the Change Logo program...")      
                    
                case $msg = $permission
                ;   Run( "Permissions.exe", $syspath)
                    MsgBox(4096, "", "This starts the permission setup program...")                             

                case $msg = $exititem
                    Exit
                
        EndSelect
    WEnd
EndFunc

File-based write filter configuration for the current session:

filter state: enabled.

overlay cache data compression state: enabled.

overlay cache pre-allocation: disabled.

.

.

.

File-based write filter configuration for the next session:

filter state: enabled.

overlay cache data compression state: enabled.

overlay cache pre-allocation: disabled.

Link to comment
Share on other sites

I'm not sure of the behaviour of /k (remain open) with Console operations; if you say that it doesn't work then maybe that's the way it is supposed to be.

I understand the reason of changing /c with/k; you wanted to debug your script. I would suggest using the /c form but - insert a messagebox right after WEnd (before "If") to display $ResponseText.

Have a look at what is returned - maybe it is not exactly "filter state: enabled.", maybe the return is wrong ..., maybe there are extra spaces ...

If the return is ok, it would be then just a matter of string manipulation and I believe you can do that yourself with a little bit of patience.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

I'm not sure of the behaviour of /k (remain open) with Console operations; if you say that it doesn't work then maybe that's the way it is supposed to be.

I understand the reason of changing /c with/k; you wanted to debug your script. I would suggest using the /c form but - insert a messagebox right after WEnd (before "If") to display $ResponseText.

Have a look at what is returned - maybe it is not exactly "filter state: enabled.", maybe the return is wrong ..., maybe there are extra spaces ...

If the return is ok, it would be then just a matter of string manipulation and I believe you can do that yourself with a little bit of patience.

Yes, I used the /k to see the console. However, it will not even load the console. The button just does not do anything. There is something wrong with the "@SW_HIDE, $STDOUT_CHILD+$STDERR_CHILD" at the end of the "Run" command. If I don't declare them, then they produce an error "Variable used without being declared", and when I do declare them at the top, then nothing comes up. Do they need to be declared? If yes, do I need to declare then somewhere other than where I have right now?

Link to comment
Share on other sites

In my previous post I've just told you to use /c and a messagebox - have you done that??

Yes. I did exactly as you instructed. I put a message box right after the WEND and before the next if statement. It shows the messagebox fine but will not run the Run command before it or display the text. I had already replaced the /k with /c. I even went back to your original suggested code (the very first code example) and placed it in place of the updated code. It did not run it either. I will play with it more this evening and post everything I have tried. I think it will not even hit the Run command (somehow skips over it) or it is not recognizing the path, even though it is the same path on the other two functioins and they run fine.

Link to comment
Share on other sites

I can't figure this out. It does not make sense. I have tried many different ways to display the information before reading the string and still will not work. I changed the code to just display the content of the FBWF and I get blank message box after a test message box I inserted after the WEND. I took your first sample code and replaced it in the function and all I get is my test message box and a blank message box, eventhough the example runs fine by itself after. here is the code again with the changes. I appriciate any suggestions.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Constants.au3>

Opt('MustDeclareVars', 1)

Utility()

Func Utility()
    Local $filemenu, $fileitem, $logochange, $exititem, $passwordset, $permission
    Local $helpmenu, $helpitem, $runmenu, $runitem, $msg, $file
    Local $WPEnable, $WPDisable, $WPState, $Restart, $Finish, $font, $widthCell
    Local $runTaskMan, $runCMD, $runUVNC, $STDOUT_CHILD, $STDERR_CHILD
    Dim $syspath = "c:\windows\system32\"
    Dim $Utilpath = "c:\program files\DCI Utility\"
    Dim $fbwf = "fbwfmgr.exe"
    Dim $fbwfSt = "fbwfmgr.exe /displayconfig"
    dim $Clogo = "changelogo.bat"
    
    GUICreate("DVR Management", 150, 350, -1, -1, 0x16C00000)

    $filemenu = GUICtrlCreateMenu("&Tools")
    $passwordset = GUICtrlCreateMenuItem("Set Password", $filemenu)
    $logochange = GUICtrlCreateMenuItem("Change Logo", $filemenu)
    $permission = GUICtrlCreateMenuItem("Set Permissions", $filemenu)
    $exititem = GUICtrlCreateMenuItem("Exit", $filemenu)
    
    $helpmenu = GUICtrlCreateMenu("Help")
    $helpitem = GUICtrlCreateMenuItem("How To", $helpmenu)

    $runmenu = GUICtrlCreateMenu("Run", -1, 1)
    $runTaskMan = GUICtrlCreateMenuItem("Task Manager", $runmenu)
    $runCMD = GUICtrlCreateMenuItem("Command Prompt", $runmenu)
    $runUVNC = GUICtrlCreateMenuItem("Ultr@VNC", $runmenu)
    
    $widthCell = 25
    Opt("GUICoordMode", 2)
    
    $WPEnable = GUICtrlCreateButton("Enable Protection", 1 * $widthcell, 50, 100, 20)
    $WPDisable = GUICtrlCreateButton("Disable Protection", -1, 30, 100, 20)
    $WPState = GUICtrlCreateButton("Protection Status", -1, 30, 100, 20)
    $Restart = GUICtrlCreateButton("REBOOT", -1, 60, 100, 20)
    $Finish = GUICtrlCreateButton("Close", -1, 30, 100, 20)
    
    GUISetState()      

    While 1
        $msg = GUIGetMsg()
            Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
                Case $msg = $WPEnable   
                    RunWait(@ComSpec & " /C " & $syspath & $fbwf & " /enable")    ; Will Enable Write Protection
                    MsgBox(4096, "", "Please Click on REBOOT for protection to be Enabled!")

                Case $msg = $WPDisable
                    RunWait(@ComSpec & " /c " & $syspath & $fbwf & " /disable")    ; Will Disable Write Protection
                    MsgBox(4096, "", "Please Click on REBOOT for protection to be Disabled!")

                Case $msg = $WPState
                    Local $DirCmd = Run(@ComSpec & " /c dir c:\", "C:\", @SW_HIDE, $STDOUT_CHILD+$STDERR_CHILD)

                    Local $ResponseText
                    While 1
                        $ResponseText &= StdoutRead($DirCmd)
                        If @error Then ExitLoop
                    Wend
                                        MsgBox (0, "", "test this function")
                    MsgBox(0, "Dir c:\", $ResponseText)


;~                  $DirCmd = RunWait(@ComSpec & " /c " & $syspath & $fbwfSt, @SW_HIDE, $STDOUT_CHILD+$STDERR_CHILD)            
;~                  
;~                  While 1
;~                      $ResponseText &= StdoutRead($DirCmd)
;~                      If @error Then ExitLoop
;~                  Wend
;~                      
;~                      MsgBox(0, "", $ResponseText)

;~                      If StringInStr($ResponseText, "filter state: enabled.") Then
;~                          MsgBox(0, "Enabled", "Write Protection is ENABLED")
;~                      ElseIf StringInStr($ResponseText, "filter state: disabled.") Then
;~                          MsgBox(0, "Disabled", "Write Protection is DISABLED")
;~                      EndIf

                Case $msg = $Restart
                    MsgBox(4096, "", "The DVR will Restart now!")
                    Shutdown(2)
                
                Case $msg = $Finish
                    MsgBox(4096, "", "Are you sure you want to Exit?")              
                    Exit
                    
                Case $msg = $runTaskMan
                    Run( "taskmgr", $syspath)
                    
                case $msg = $runCMD
                    RunWait(@ComSpec & " /k", @WindowsDir)  
                    
                Case $msg = $passwordset
                ;   Run( "SetPassword.exe", $Utilpath)
                    MsgBox(4096, "", "This starts the password setup program...")
                    
                case $msg = $logochange
                ;   RunWait(@ComSpec & " /c" & $Utilpath & $Clogo)
                    MsgBox(4096, "", "This starts the Change Logo program...")      
                    
                case $msg = $permission
                    Run( "Permissions.exe", $Utilpath)
                    MsgBox(4096, "", "This starts the permission setup program...")                             

                case $msg = $exititem
                    Exit
                
        EndSelect
    WEnd
EndFunc
Link to comment
Share on other sites

I got it working. It is working eventhough it does not make any sense. I had used Dim $fbwf = "fbwfmgr.exe" to declare the exe file and it works fine for the enable and disable functions, but the same did not work for the display function. So, I rewrote the steps completely in the Run command without using the declared value and it is working fine. I can't figure that one out. Thanks for all your help. If you don't mind, I definitly need help with the password protection portion from you or any other patient person. I have looked at many of the posts but could not find one that would work for me yet(unless I searched wrong). I will do the ground work first and ask for help later.

Thank

Mehrdad

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...