Jump to content

Possible to do?


Recommended Posts

Hi,

My name is Ryan and I work for a public library. We run many machines for public use and about the same amount for staff. We have to maintain them as 2 separate environments (workgroups) for funding purposes. We're on a novell network (no choice) with a mix of server types aix/linux/netware/windows but we don't run active directory and our windows machine is not a domain controller. So we have to make most things work through batch files and login scripts plus deep freeze. I am a noob to scripting/batch files/coding. My boss has a lot of knowledge but little time so I'm on my own when it comes to things he hasn't tried. He uses autoit a lot but I want to use it to get rid of tasks that I do. I appreciate the group and the help.

This is the functionality I want for a few of the apps I look to create.

I have built the GUI using KODA for one of them already.

Is it possibly to make an exe that you can have a menu populate menu items by looking into the contents of a folder?

Details:

I want to make an app that has a menu at top and a few buttons at bottom (gui is done except menu area).

The "menu" looks into a folder where I can add text files on the fly of lists of names/computer names or names/computer names and mac addresses

You first select the group from that menu(links to a text file of the same name in the "lists" folder)

then hit a button that says "wol" or "restart" or "shutdown" or "freeze" or "thaw" or "1 time admin login" or "log out"

That button will look to the list I've selected and apply that function as admin or system level

"1 time admin login" applied to a group of machines would save us a HUGE amount of time. My boss thinks we can do this with reg key swapping for autologon which we have running on all public machines.

This is the first app I want to do and I hope it's possible.

Thanks!

Link to comment
Share on other sites

Is it possibly to make an exe that you can have a menu populate menu items by looking into the contents of a folder?

First things first: welcome to the AutoIt forums!

Now the global answer to the above is: Yes, of course.

You can either add/delete menuitems as required or change the item at will.

Example is the Look menu and item, before and after hitting Magic Wand:

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

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $defaultstatus, $status, $filemenu, $fileitem, $helpmenu, $saveitem
    Local $infoitem, $exititem, $recentfilesmenu, $separator1, $viewmenu
    Local $viewstatusitem, $okbutton, $cancelbutton, $statuslabel, $msg, $file
    Local $changebutton, $varmenu, $varitem1

    GUICreate("My GUI menu", 300, 200)

    Global $defaultstatus = "Ready"
    Global $status

    $filemenu = GUICtrlCreateMenu("&File")
    $fileitem = GUICtrlCreateMenuItem("Open", $filemenu)
    GUICtrlSetState(-1, $GUI_DEFBUTTON)
    $helpmenu = GUICtrlCreateMenu("?")
    $saveitem = GUICtrlCreateMenuItem("Save", $filemenu)
    GUICtrlSetState(-1, $GUI_DISABLE)
    $infoitem = GUICtrlCreateMenuItem("Info", $helpmenu)
    $exititem = GUICtrlCreateMenuItem("Exit", $filemenu)
    $recentfilesmenu = GUICtrlCreateMenu("Recent Files", $filemenu, 1)

    $separator1 = GUICtrlCreateMenuItem("", $filemenu, 2)   ; create a separator line

    $varmenu = GUICtrlCreateMenu("Look", -1, 1)
    $varitem1 = GUICtrlCreateMenuItem("Nothing here", $varmenu)
    $viewmenu = GUICtrlCreateMenu("View", -1, 1)    ; is created before "?" menu
    $viewstatusitem = GUICtrlCreateMenuItem("Statusbar", $viewmenu)
    GUICtrlSetState(-1, $GUI_CHECKED)
    $okbutton = GUICtrlCreateButton("OK", 50, 130, 70, 20)
    GUICtrlSetState(-1, $GUI_FOCUS)
    $cancelbutton = GUICtrlCreateButton("Cancel", 180, 130, 70, 20)
    $changebutton = GUICtrlCreateButton("Magic wand", 100, 90, 100, 20)

    $statuslabel = GUICtrlCreateLabel($defaultstatus, 0, 165, 300, 16, BitOR($SS_SIMPLE, $SS_SUNKEN))

    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $fileitem
                $file = FileOpenDialog("Choose file...", @TempDir, "All (*.*)")
                If @error <> 1 Then GUICtrlCreateMenuItem($file, $recentfilesmenu)
            Case $viewstatusitem
                If BitAND(GUICtrlRead($viewstatusitem), $GUI_CHECKED) = $GUI_CHECKED Then
                    GUICtrlSetState($viewstatusitem, $GUI_UNCHECKED)
                    GUICtrlSetState($statuslabel, $GUI_HIDE)
                Else
                    GUICtrlSetState($viewstatusitem, $GUI_CHECKED)
                    GUICtrlSetState($statuslabel, $GUI_SHOW)
                EndIf
            Case $GUI_EVENT_CLOSE, $cancelbutton, $exititem
                ExitLoop
            Case $infoitem
                MsgBox(0, "Info", "Only a test...")
            Case $changebutton
                GUICtrlSetData($varmenu, "Watch")
                GUICtrlSetData($varitem1, "Something appeared")
            Local $varitem2 = GUICtrlCreateMenuItem("that you", $varmenu)
             Local $varitem3 = GUICtrlCreateMenuItem("can manage", $varmenu)
        EndSwitch
    WEnd
    GUIDelete()
EndFunc ;==>Example

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

wicked1wanders,

From what I can see, the example above does not do what you're asking.

This example shows you several things:

  • Resizing arrays to expand for dynamic content (ReDim)
  • Selecting a folder
  • Listing all files in a folder into an array
  • Using GUIOnEventMode
  • Creating dynamic menu items based on the files array
  • Reacting upon each dynamic item using @GUI_CtrlID
I hope this example is enough to get you started with.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Opt("GUIOnEventMode", 1)

Dim $sFolder, $aMnuItems, $mnuItem[1]

$sFolder = FileSelectFolder("Select folder", @ScriptDir)

$aMnuItems = _FileListToArray($sFolder)

ReDim $mnuItem[$aMnuItems[0] + 1] ; Resize the amount of menu items to make room for the controls

$hGUI = GUICreate("", 331, 221)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")

$mnuItems = GUICtrlCreateMenu("Folder")
For $i = 1 To $aMnuItems[0]
    $mnuItem[$i] = GUICtrlCreateMenuItem($aMnuItems[$i], $mnuItems)
    GUICtrlSetOnEvent($mnuItem[$i], "ClickItem")
Next

GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func ClickItem()
    For $j = 0 To UBound($mnuItem) -1
        If @GUI_CtrlId = $mnuItem[$j] Then
            MsgBox(0, "", $aMnuItems[$j])
        EndIf
    Next
EndFunc

Func Close()
    Exit
EndFunc

James

Link to comment
Share on other sites

Maybe to clarify a little better I want the menu items to change triggered by me saving a txt document to that "lists" folder. So If there're 3 txt files in the lists folder named 1.txt 2.txt and 3.txt those will appear in the menu as menu items. But if I add 1 txt file by just saving it from notepad to the folder I want it to change in my program's menu items next time it's run without me changing my program. So it will appear as menu item 4 without me editing menu items. I guess that would be a "dynamic" change? I use to have a boss obsessed with saying "dynamic"...arrg heh. I haven't been able to test your examples yet but I'll try tonight.

Thanks again!

Ryan

wicked1wanders,

From what I can see, the example above does not do what you're asking.

This example shows you several things:

  • Resizing arrays to expand for dynamic content (ReDim)
  • Selecting a folder
  • Listing all files in a folder into an array
  • Using GUIOnEventMode
  • Creating dynamic menu items based on the files array
  • Reacting upon each dynamic item using @GUI_CtrlID
I hope this example is enough to get you started with.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Opt("GUIOnEventMode", 1)

Dim $sFolder, $aMnuItems, $mnuItem[1]

$sFolder = FileSelectFolder("Select folder", @ScriptDir)

$aMnuItems = _FileListToArray($sFolder)

ReDim $mnuItem[$aMnuItems[0] + 1] ; Resize the amount of menu items to make room for the controls

$hGUI = GUICreate("", 331, 221)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")

$mnuItems = GUICtrlCreateMenu("Folder")
For $i = 1 To $aMnuItems[0]
    $mnuItem[$i] = GUICtrlCreateMenuItem($aMnuItems[$i], $mnuItems)
    GUICtrlSetOnEvent($mnuItem[$i], "ClickItem")
Next

GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func ClickItem()
    For $j = 0 To UBound($mnuItem) -1
        If @GUI_CtrlId = $mnuItem[$j] Then
            MsgBox(0, "", $aMnuItems[$j])
        EndIf
    Next
EndFunc

Func Close()
    Exit
EndFunc

James

Link to comment
Share on other sites

Maybe to clarify a little better I want the menu items to change triggered by me saving a txt document to that "lists" folder. So If there're 3 txt files in the lists folder named 1.txt 2.txt and 3.txt those will appear in the menu as menu items.

That's exactly what it does Posted Image

The only thing it doesn't do is add files if they are created after the GUI is loaded. This is pretty simple to add through the use of AdlibRegister() or AdlibEnable() in older versions of AutoIt.

James

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