Jump to content

Case Problem


dew
 Share

Recommended Posts

My problem is to get all 'lnk' files assigned to either a "single user" or to "all users" (short list, long list). I have a radio button defining single or all user.

When I run the script, I am getting the same answer for both!

Could someone point out why the radiobuttons are not functioning correctly for me?

thanks ahead of time

;----------------------------------------------------------------------

;GUI

$hGUI = GuiCreate("Link Files Verification Test", 265, 325)

;GUI labels -

GuiCtrlCreateLabel("Select either ""Single User"" or ""All Users", 5, 15, 200, 35)

;GuiCtrlCreateLabel("Version beta" & @CRLF & "Copyrighted by David Wagner, 2009", 5, 295, 180, 50)

;----- radio buttons -----

$radio1 = GUICtrlCreateRadio("Single User", 10, 30, 90, 50)

$radio2 = GUICtrlCreateRadio("All Users", 10, 65, 90, 50)

;----- buttons to select what to do -----

$Button_1 = GUICtrlCreateButton("1. Generate the Lnk log files.", 5,125,195,25, $BS_LEFT)

$Button_2 = GUICtrlCreateButton("2. View the Successful Lnk files found.", 5,150,195,25, $BS_LEFT)

$Button_3 = GUICtrlCreateButton("3. Print the Successful Lnk files found.", 5,175,195,25, $BS_LEFT)

$Button_4 = GUICtrlCreateButton("4. View the Failed Lnk files not found.", 5,200,195,25, $BS_LEFT)

$Button_5 = GUICtrlCreateButton("5. Print the Failed Lnk files not found.", 5,225,195,25, $BS_LEFT)

; What to do when a button is pressed -

GUISetState() ; will display an dialog box with 5 button

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $Button_1 ;generate the log files

;Create the link's data files, add Tester name and date of the test ----------------------------------------

$SuccessLog = FileOpen("Successful Links.log", 2) ;Caution: Log will be erased at start!

$ErrorLog = FileOpen("Failed Links.log", 2) ;Caution: Log will be erased at start!

;Input Tester Name

$TesterName = InputBox("Tester Name", "Enter your name:", "", "", 250, 125,"-1","-1",15)

;Create log header -

;Success

FileWriteLine($SuccessLog, "Tester: " & $TesterName & @CRLF & "Test ran on: " & _Now() & @CRLF & @CRLF _

& "Successfully located the following linked files." & @CRLF & @CRLF)

;Failed

FileWriteLine($ErrorLog, "Tester: " & $TesterName & @CRLF & "Test ran on: " & _Now() & @CRLF & @CRLF _

& "Was unable to locate the following linked files. This part of the Link Test failed." & @CRLF _

& "Manually check that the linked path is correct." & @CRLF & @CRLF)

Case $msg = $radio1

_loopdir(@StartMenuDir) ;Find all files in the current users's startmenu

Case $msg - $radio2

_loopdir(@StartMenuCommonDir) ;Find all files in allusers's startmenu

Case $msg = $Button_2 ;open log file for viewing the successful linked files

ShellExecute("notepad.exe", "Successful Links.log", @ScriptDir, "open") ;open txt file (view / edit)

Case $msg = $Button_3 ;only print the log file

ShellExecute("Successful Links.log", "", @ScriptDir, "print", @SW_HIDE ) ;only print the file

Case $msg = $Button_4

MsgBox(0, 'Test', 'Button 4 was pressed') ; demonstrate Button 4 being pressed

Case $msg = $Button_5

MsgBox(0, 'Test', 'Button 5 was pressed') ; demonstrate Button 5 being pressed

EndSelect

WEnd

;--------------------------------------------------------------------------------------------------------------

Func _loopdir($dir)

$search = FileFindFirstFile($dir & "\*")

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

$fullfile = $dir & "\" & $file

If StringInStr(FileGetAttrib($fullfile), "D") Then _loopdir($fullfile) ;If its a subdirectory, check this too

If StringLower(StringRight($file, 3)) = "lnk" Then ;Check wheter it is a lnk based on file extension

$lnkinfo = FileGetShortcut($fullfile)

If Not FileExists($lnkinfo[0]) Then ;Check wheter target file exists

FileWriteLine($ErrorLog, $fullfile)

Else

FileWriteLine($SuccessLog, $fullfile)

EndIf

EndIf

WEnd

EndFunc

Link to comment
Share on other sites

#include <ButtonConstants.au3>
#include <Date.au3>
#include <GUIConstantsEX.au3>

Global $fCheck = 1
$hGUI = GUICreate("Link Files Verification Test", 265, 325)

;GUI labels -
GUICtrlCreateLabel("Select either ""Single User"" or ""All Users", 5, 15, 200, 35)
;GuiCtrlCreateLabel("Version beta" & @CRLF & "Copyrighted by David Wagner, 2009", 5, 295, 180, 50)

;----- radio buttons -----
$radio1 = GUICtrlCreateRadio("Single User", 10, 30, 90, 50)
GUICtrlSetState(-1, $GUI_CHECKED)
$radio2 = GUICtrlCreateRadio("All Users", 10, 65, 90, 50)

;----- buttons to select what to do -----
$Button_1 = GUICtrlCreateButton("1. Generate the Lnk log files.", 5, 125, 195, 25, $BS_LEFT)
$Button_2 = GUICtrlCreateButton("2. View the Successful Lnk files found.", 5, 150, 195, 25, $BS_LEFT)
$Button_3 = GUICtrlCreateButton("3. Print the Successful Lnk files found.", 5, 175, 195, 25, $BS_LEFT)
$Button_4 = GUICtrlCreateButton("4. View the Failed Lnk files not found.", 5, 200, 195, 25, $BS_LEFT)
$Button_5 = GUICtrlCreateButton("5. Print the Failed Lnk files not found.", 5, 225, 195, 25, $BS_LEFT)

;Create the link's data files, add Tester name and date of the test ----------------------------------------
$SuccessLog = FileOpen("Successful Links.log", 2) ;Caution: Log will be erased at start!
$ErrorLog = FileOpen("Failed Links.log", 2) ;Caution: Log will be erased at start!
; What to do when a button is pressed -
GUISetState() ; will display an dialog box with 5 button

While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop

        Case $msg = $Button_1 ;generate the log files
            If $fCheck = 1 Then
                _loopdir(@StartMenuDir) ;Find all files in the current users's startmenu
            Else
                _loopdir(@StartMenuCommonDir) ;Find all files in allusers's startmenu
            EndIf
                
            ;Input Tester Name
            $TesterName = InputBox("Tester Name", "Enter your name:", "", "", 250, 125, "-1", "-1", 15)

            ;Create log header -
            ;Success
            FileWriteLine($SuccessLog, "Tester: " & $TesterName & @CRLF & "Test ran on: " & _Now() & @CRLF & @CRLF _
                     & "Successfully located the following linked files." & @CRLF & @CRLF)

            ;Failed
            FileWriteLine($ErrorLog, "Tester: " & $TesterName & @CRLF & "Test ran on: " & _Now() & @CRLF & @CRLF _
                     & "Was unable to locate the following linked files. This part of the Link Test failed." & @CRLF _
                     & "Manually check that the linked path is correct." & @CRLF & @CRLF)

        Case $msg = $radio1
            If GUICtrlGetState($radio1) = $GUI_CHECKED Then $fCheck = 1

        Case $msg - $radio2
            If GUICtrlGetState($radio2) = $GUI_CHECKED Then $fCheck = 2

        Case $msg = $Button_2 ;open log file for viewing the successful linked files
            ShellExecute("notepad.exe", "Successful Links.log", @ScriptDir, "open") ;open txt file (view / edit)

        Case $msg = $Button_3 ;only print the log file
            ShellExecute("Successful Links.log", "", @ScriptDir, "print", @SW_HIDE) ;only print the file

        Case $msg = $Button_4
            MsgBox(0, 'Test', 'Button 4 was pressed') ; demonstrate Button 4 being pressed

        Case $msg = $Button_5
            MsgBox(0, 'Test', 'Button 5 was pressed') ; demonstrate Button 5 being pressed

    EndSelect

WEnd

FileClose($ErrorLog)
FileClose($SuccessLog)


;--------------------------------------------------------------------------------------------------------------
Func _loopdir($dir)
    $search = FileFindFirstFile($dir & "\*")

    While 1
        $file = FileFindNextFile($search)
        If @error Then ExitLoop

        $fullfile = $dir & "\" & $file

        If StringInStr(FileGetAttrib($fullfile), "D") Then _loopdir($fullfile) ;If its a subdirectory, check this too

        If StringLower(StringRight($file, 3)) = "lnk" Then ;Check wheter it is a lnk based on file extension
            $lnkinfo = FileGetShortcut($fullfile)
            If Not FileExists($lnkinfo[0]) Then ;Check wheter target file exists
                FileWriteLine($ErrorLog, $fullfile)
            Else
                FileWriteLine($SuccessLog, $fullfile)
            EndIf
        EndIf
    WEnd
EndFunc   ;==>_loopdir

I don't know if this is what you want but your GUI can't react fast because it's constantly calling the _loopdir function over and over for each event the radio is raising. Please next wrap your code inside autoit tags for AutoIt code.

Link to comment
Share on other sites

#include <ButtonConstants.au3>
#include <Date.au3>
#include <GUIConstantsEX.au3>

Global $fCheck = 1
$hGUI = GUICreate("Link Files Verification Test", 265, 325)

;GUI labels -
GUICtrlCreateLabel("Select either ""Single User"" or ""All Users", 5, 15, 200, 35)
;GuiCtrlCreateLabel("Version beta" & @CRLF & "Copyrighted by David Wagner, 2009", 5, 295, 180, 50)

;----- radio buttons -----
$radio1 = GUICtrlCreateRadio("Single User", 10, 30, 90, 50)
GUICtrlSetState(-1, $GUI_CHECKED)
$radio2 = GUICtrlCreateRadio("All Users", 10, 65, 90, 50)

;----- buttons to select what to do -----
$Button_1 = GUICtrlCreateButton("1. Generate the Lnk log files.", 5, 125, 195, 25, $BS_LEFT)
$Button_2 = GUICtrlCreateButton("2. View the Successful Lnk files found.", 5, 150, 195, 25, $BS_LEFT)
$Button_3 = GUICtrlCreateButton("3. Print the Successful Lnk files found.", 5, 175, 195, 25, $BS_LEFT)
$Button_4 = GUICtrlCreateButton("4. View the Failed Lnk files not found.", 5, 200, 195, 25, $BS_LEFT)
$Button_5 = GUICtrlCreateButton("5. Print the Failed Lnk files not found.", 5, 225, 195, 25, $BS_LEFT)

;Create the link's data files, add Tester name and date of the test ----------------------------------------
$SuccessLog = FileOpen("Successful Links.log", 2) ;Caution: Log will be erased at start!
$ErrorLog = FileOpen("Failed Links.log", 2) ;Caution: Log will be erased at start!
; What to do when a button is pressed -
GUISetState() ; will display an dialog box with 5 button

While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop

        Case $msg = $Button_1 ;generate the log files
            If $fCheck = 1 Then
                _loopdir(@StartMenuDir) ;Find all files in the current users's startmenu
            Else
                _loopdir(@StartMenuCommonDir) ;Find all files in allusers's startmenu
            EndIf
                
            ;Input Tester Name
            $TesterName = InputBox("Tester Name", "Enter your name:", "", "", 250, 125, "-1", "-1", 15)

            ;Create log header -
            ;Success
            FileWriteLine($SuccessLog, "Tester: " & $TesterName & @CRLF & "Test ran on: " & _Now() & @CRLF & @CRLF _
                     & "Successfully located the following linked files." & @CRLF & @CRLF)

            ;Failed
            FileWriteLine($ErrorLog, "Tester: " & $TesterName & @CRLF & "Test ran on: " & _Now() & @CRLF & @CRLF _
                     & "Was unable to locate the following linked files. This part of the Link Test failed." & @CRLF _
                     & "Manually check that the linked path is correct." & @CRLF & @CRLF)

        Case $msg = $radio1
            If GUICtrlGetState($radio1) = $GUI_CHECKED Then $fCheck = 1

        Case $msg - $radio2
            If GUICtrlGetState($radio2) = $GUI_CHECKED Then $fCheck = 2

        Case $msg = $Button_2 ;open log file for viewing the successful linked files
            ShellExecute("notepad.exe", "Successful Links.log", @ScriptDir, "open") ;open txt file (view / edit)

        Case $msg = $Button_3 ;only print the log file
            ShellExecute("Successful Links.log", "", @ScriptDir, "print", @SW_HIDE) ;only print the file

        Case $msg = $Button_4
            MsgBox(0, 'Test', 'Button 4 was pressed') ; demonstrate Button 4 being pressed

        Case $msg = $Button_5
            MsgBox(0, 'Test', 'Button 5 was pressed') ; demonstrate Button 5 being pressed

    EndSelect

WEnd

FileClose($ErrorLog)
FileClose($SuccessLog)


;--------------------------------------------------------------------------------------------------------------
Func _loopdir($dir)
    $search = FileFindFirstFile($dir & "\*")

    While 1
        $file = FileFindNextFile($search)
        If @error Then ExitLoop

        $fullfile = $dir & "\" & $file

        If StringInStr(FileGetAttrib($fullfile), "D") Then _loopdir($fullfile) ;If its a subdirectory, check this too

        If StringLower(StringRight($file, 3)) = "lnk" Then ;Check wheter it is a lnk based on file extension
            $lnkinfo = FileGetShortcut($fullfile)
            If Not FileExists($lnkinfo[0]) Then ;Check wheter target file exists
                FileWriteLine($ErrorLog, $fullfile)
            Else
                FileWriteLine($SuccessLog, $fullfile)
            EndIf
        EndIf
    WEnd
EndFunc   ;==>_loopdir

I don't know if this is what you want but your GUI can't react fast because it's constantly calling the _loopdir function over and over for each event the radio is raising. Please next wrap your code inside autoit tags for AutoIt code.

Authenticity,

Thank you, it is a step in the right direction. My problem now is when I clicked button2, notepad does not open the file. I believe that I have to do a "fileclose" first before notepad can open the log file (button 2).

I did noticed you set single user as default (checked). The other thing I noticed is that my "header" for the logged file is at the bottom instead of the top (minor detail here).

Again, thank you for the suggestion of putting the code inside of 'autoit tags', will do that from now on.

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