Jump to content

Coding NOOB, need help


Recommended Posts

I've never written code from scratch before, so a lot of the assumtions of existing knowledge in the tutorials are leaving me a bit stranded.

Basically I've got a couple projects I want to do and both seem fairly simple, but I cant for the life of me find a comprehensive list of commands and modifiers or syntax to help me get it done.

Here's what I want to do:

1. Build an auto installer script for a few programs, preferably with a basic GUI. Later I plan on implementing options for auto-update or other such contrivances, but a simple "Go" button is the goal for now.

2. Build an automatic scan script for several security tools I use on a regular basis.

I've already built a couple of batch files that work with some of these program's built-in scripting so I'd like to use those batches as support files to avoid errors. I've already used Koda to build the basic GUI. My problem now is figuring out how to link the click of that "Go" button to launching a batch or macro.

Halp?

Edited by pyr0ball
Link to comment
Share on other sites

You can read the state of the button using GUICtrlRead

or

Search the help for GUICtrlCreateButton

It gives you an example in the sample script on how to execute an action if the button is pressed.

Edited by kor
Link to comment
Share on other sites

okipokey, the help file have me a better idea of the link between button and command, but now I've run into another issue. I want to use relative locations rather than absolute locations (i.e. ".\currentfolder\subfolder" versus "X:\currentfolder\subfolder") but I'm getting a syntax error on ".\"

here's what I've got so far:

WEnd$msg = $GUI_EVENT_CLOSE#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=c:\users\pyr0ball\dropbox\autoit\mainwindow.kxf
$MainWindow = GUICreate("TNN AutoInstaller", 252, 230, 192, 124)
$InstallStart = GUICtrlCreateButton("InstallStart", 64, 152, 115, 33)
$Progress = GUICtrlCreateProgress(8, 200, 230, 17)
$TNNLogo = GUICtrlCreatePic(".\SupportFiles\bluegreyLogo3.jpg", 10, 8, 228, 135)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $msg = $InstallStart
   Run('cmd ".\SupportFiles\spybot.bat" ')
EndSwitch
WEnd
Edited by pyr0ball
Link to comment
Share on other sites

An example of one of mine

While 1
    Local $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ButtonEnable
         ; The thing you want to call for that button
        Case $ButtonDisable
         ; The thing you want to call for that button
    EndSwitch
WEnd

Once the loop is looking for the button press you only need specify like Case $This is my new button name, to add other ones

edit

and with the installers you will prob find as you progress you can do everything that cmd can do and a lot more with autoit

Run('cmd ".SupportFilesspybot.bat" ')

This can probably be done like this but have a play around

ShellExecuteWait( @ScriptDir & "SupportFilesspybot.bat")
Edited by Chimaera
Link to comment
Share on other sites

okipokey, I checked thru the help file, but I'm a bit at a loss to find anything like a cmd emulator or at least how to word the commands so that they react with the same "arguments" I'd use in cmd. Is there a page I could look for with the right info? Is it simply the ShellExecute series of commands? (I havnt gotten around to reading thru the whole section on that yet

--Edit

Figured out that searching for "cmd" or "command" was basically useless in finding the info I needed :)

looks like the Shell Execute commands are the meat and potatoes I'm after! Thanks a ton for pointing me that way ;)

Edited by pyr0ball
Link to comment
Share on other sites

Shellexecute uses the preset type in windows so it works out what to use

If you want to access cmd itself then look up @ComSpec eg usage below from something im working on

RunWait(@ComSpec & " /c " & 'netsh wlan disconnect interface="wifiname"',@SW_SHOW)

Glad i could help ;)

Edited by Chimaera
Link to comment
Share on other sites

ok running into a syntax error on WEnd as I try to compile my first prototype. Hopefully it's something simple?

WEnd$msg = $GUI_EVENT_CLOSE#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=c:userspyr0balldropboxautoitmainwindow.kxf
$MainWindow = GUICreate("TNN AutoInstaller", 252, 230, 192, 124)
$InstallStart = GUICtrlCreateButton("InstallStart", 64, 152, 115, 33)
$Progress = GUICtrlCreateProgress(8, 200, 230, 17)
$TNNLogo = GUICtrlCreatePic(".SupportFilesbluegreyLogo3.jpg", 10, 8, 228, 135)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $InstallStart
   ShellExecuteWait( @ScriptDir "spybotsd162.exe" [, "/verysilent /suppressmsgboxes /norestart /dir=C:Program FilesSpybotSearchDestroy /components=main,language, SDWinSec, SDShredder, SDDelFile /tasks=desktopicon, launchsdhelper /log=spsdlog.txt" [, [, "open" [,@SW_HIDE]]]] )
   ShellExecuteWait( @ScriptDir "ccleaner.exe" [, "/s /d=C:Program FilesCCleaner" [, [, "open" [,@SW_HIDE]]]] )
   ShellExecuteWait( @ScriptDir "dfsetup.exe" [, "/s /d=C:Program FilesDefraggler" [, [, "open" [,@SW_HIDE]]]] )
   ShellExecuteWait( @ScriptDir "mbam-setup.exe" [, "/VERYSILENT /NORESTART /SUPPRESSMSGBOXES /NOCANCEL" [, [, "open" [,@SW_HIDE]]]] )
   ShellExecuteWait( @ScriptDir "avastsetup.exe" [, "/verysilent /noreboot /nosounds" [, [, "open" [,@SW_HIDE]]]] )
   ShellExecuteWait( @ScriptDir "SUPERAntiSpyware.exe" [, [, [, "open" [,@SW_HIDE]]]] )
   #region --- AutoIt Macro Generator V 0.21 beta ---
   Opt("WinTitleMatchMode", 4)
   WinWait("SUPERAntiSpyware Free Edition Setup","Read below for the special off")
   ControlClick("SUPERAntiSpyware Free Edition Setup","Read below for the special off","Button8")
   ControlClick("SUPERAntiSpyware Free Edition Setup","Read below for the special off","Button8")
   ControlClick("SUPERAntiSpyware Free Edition Setup","Read below for the special off","Button8")
   ControlClick("SUPERAntiSpyware Free Edition Setup","Read below for the special off","Button8")
   ControlCommand("SUPERAntiSpyware Free Edition Setup","Read below for the special off","Button2","UnCheck","")
   ControlClick("SUPERAntiSpyware Free Edition Setup","Read below for the special off","#327703")
   ControlCommand("SUPERAntiSpyware Free Edition Setup","Read below for the special off","Button3","UnCheck","")
   #endregion --- End ---
   ShellExecuteWait( @ScriptDir "spywareblastersetup.exe" [, [, [, "open" [,@SW_HIDE]]]] )
   #region --- AutoIt Macro Generator V 0.21 beta ---
   Opt("WinTitleMatchMode", 4)
   WinWait("Setup - SpywareBlaster","This will install SpywareBlast")
   ControlClick("Setup - SpywareBlaster","This will install SpywareBlast","TNewButton1")
   WinWait("Setup - SpywareBlaster","Please read the following impo")
   ControlClick("Setup - SpywareBlaster","Please read the following impo","TNewRadioButton1")
   ControlClick("Setup - SpywareBlaster","Please read the following impo","TNewButton2")
   WinWait("Setup - SpywareBlaster","Where should SpywareBlaster be")
   ControlClick("Setup - SpywareBlaster","Where should SpywareBlaster be","TNewButton3")
   WinWait("Setup - SpywareBlaster","Which additional tasks should ")
   ControlClick("Setup - SpywareBlaster","Which additional tasks should ","TNewCheckListBox1")
   ControlClick("Setup - SpywareBlaster","Which additional tasks should ","TNewButton3")
   WinWait("Setup - SpywareBlaster","Setup is now ready to begin in")
   ControlClick("Setup - SpywareBlaster","Setup is now ready to begin in","TNewButton3")
   WinWait("Setup - SpywareBlaster","Setup has finished installing ")
   ControlClick("Setup - SpywareBlaster","Setup has finished installing ","TNewButton3")
   WinWait("SpywareBlaster Tutorial","Frame1")
   ControlClick("SpywareBlaster Tutorial","Frame1","ThunderRT6UserControlDC1")
   ControlClick("SpywareBlaster Tutorial","Frame1","ThunderRT6UserControlDC7")
   ControlClick("SpywareBlaster Tutorial","Frame1","ThunderRT6UserControlDC4")
   ControlClick("SpywareBlaster Tutorial","Frame1","ThunderRT6UserControlDC2")
   WinWait("SpywareBlaster","")
   ControlClick("SpywareBlaster","","ThunderRT6Frame1")
   WinWait("SpywareBlaster","Form1")
   ControlClick("SpywareBlaster","Form1","ThunderRT6UserControlDC1")
   ControlClick("SpywareBlaster","Form1","ThunderRT6UserControlDC8")
   WinWait("SpywareBlaster","SideToolbar")
   ControlClick("SpywareBlaster","SideToolbar","ThunderRT6UserControlDC1")
   WinWait("SpywareBlaster","")
   ControlClick("SpywareBlaster","","ThunderRT6Frame1")
   #endregion --- End ---
EndSwitch
WEnd
Link to comment
Share on other sites

ok i figured it was either the opening argument or the closing one, but how exactly is it the problem? not sure how to modify it?

Edit---

So I'm guessing I thought I overwrote a line at the top or something and didnt get that WEnd line out before the #include section came in. Anyhoo, now I'm coming up with syntax errors on every one of my ShellExecuteWait lines.

I wanna figure out why those are having issues as well for the sake of learning the code, but I can run batches from the same lines or use the run() strings instead and see how they work. I'd rather use all the code in AutoIt rather than grab the batches now I've had some time to tinker with it, mainly cus it will be a lot easier to update when future versions of software releases

Edited by pyr0ball
Link to comment
Share on other sites

^~~yessir, I ditzed with it til I figured that out. Running the script now, but it's having other syntax issues unless I link it to the batch files. When I do that, the batch command windows open and close almost instantly without doing anything.

Neither of these scripts are working but for different reasons. the first, because the batch commands aren't executing properly when launched by the script, and the second because theres some kind of syntax problem. FYI I also tried to add in a log function to figure out why itwas failing, but it doesnt seem to do anything, not even break the script ;)

Edit--- I should probably mention that running the batches independently of the script works perfectly

Batch:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <EventLog.au3>
#Region ### START Koda GUI section ### Form=c:userspyr0balldropboxautoitmainwindow.kxf
$MainWindow = GUICreate("TNN AutoInstaller", 252, 230, 192, 124)
$InstallStart = GUICtrlCreateButton("InstallStart", 64, 152, 115, 33)
$Progress = GUICtrlCreateProgress(8, 200, 230, 17)
$TNNLogo = GUICtrlCreatePic(".SupportFilesbluegreyLogo3.jpg", 10, 8, 228, 135)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_Main()
Func _Main()
    Local $hEventLog
$hEventLog = _EventLog__Open("", "$InstallStart")
    _EventLog__Backup($hEventLog, "C:SupportFilesEventLog.bak")
While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
   Case $GUI_EVENT_CLOSE
    Exit
   Case $InstallStart
;~  Install Spybot Silently, no reboot, no update
    ShellExecuteWait(@ScriptDir & "SupportFilesspybot.bat")
;~  Install CCleaner Silently
    ShellExecuteWait(@ScriptDir & "SupportFilesccleaner.bat")
;~  Install Defraggler Silently
    ShellExecuteWait(@ScriptDir & "SupportFilesdefraggler.bat")
;~  Installe Malwarebytes Silently
    ShellExecuteWait(@ScriptDir & "SupportFilesmbam.bat")
;~  Install Avast Silently, no sounds enabled, no reboot
    ShellExecuteWait(@ScriptDir & "SupportFilesavast.bat")
;~  Opens Superantispyware Dialogue Window for macro install
    RunWait( @ComSpec & " /c " & "SupportFilesSUPERAntiSpyware.exe")
   EndSwitch
    _EventLog__Close($hEventLog)
WEnd
EndFunc   ;==>_Main

ShellExecuteWait:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=c:userspyr0balldropboxautoitmainwindow.kxf
$MainWindow = GUICreate("TNN AutoInstaller", 252, 230, 192, 124)
$InstallStart = GUICtrlCreateButton("InstallStart", 64, 152, 115, 33)
$Progress = GUICtrlCreateProgress(8, 200, 230, 17)
$TNNLogo = GUICtrlCreatePic("C:Userspyr0ballDropboxTNNNerd's Security SuiteSupportFilesbluegreyLogo3.jpg", 10, 8, 228, 135)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $InstallStart
            ShellExecuteWait( @ScriptDir & "spybotsd162.exe" [, "/verysilent /suppressmsgboxes /norestart /dir=C:Program FilesSpybotSearchDestroy /components=main,language, SDWinSec, SDShredder, SDDelFile /tasks=desktopicon, launchsdhelper /log=spsdlog.txt" [, [, "open" [,@SW_HIDE]]]] )
            ShellExecuteWait( @ScriptDir & "ccleaner.exe" [, "/S /D=C:Program FilesCCleaner" [, [, "open" [,@SW_HIDE]]]] )
            ShellExecuteWait( @ScriptDir & "dfsetup.exe" [, "/S /D=C:Program FilesDefraggler" [, [, "open" [,@SW_HIDE]]]] )
            ShellExecuteWait( @ScriptDir & "mbam-setup.exe" [, "/VERYSILENT /NORESTART /SUPPRESSMSGBOXES /NOCANCEL" [, [, "open" [,@SW_HIDE]]]] )
            ShellExecuteWait( @ScriptDir & "avastsetup.exe" [, "/verysilent /noreboot /nosounds" [, [, "open" [,@SW_HIDE]]]] )
            ShellExecuteWait( @ScriptDir & "SUPERAntiSpyware.exe" [, [, [, "open" [,@SW_HIDE]]]] )

    EndSwitch
WEnd
Edited by pyr0ball
Link to comment
Share on other sites

The first one probably isn't working because you have quotes around your variable names, and you're not using them correctly regardless. You need to use GUICtrlRead to get the contents of the controls, not the variable assigned to it.

The second one doesn't work because you are putting in the "[" and "]" around the parameters, those are only there in the help file to tell you that they're optional, you CAN NOT put them into the function.

EDIT: Just noticed you're trying to open the event log using the _EventLog_Open command, and you're referencing a button control in the function call, not exactly sure you have read the help file. Suggestion: Read the help file for every command you're going to use, you need to know how they work before you can use them.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Brew I actually read the whole section on that particular function but it doesnt explicitly explain how to tell the function what to log or how to incorporate it into an existing code string. I was taking it as if it was kinda like php or html and I was making a wrapper out of it. I knew what I was doing most likely was wrong but I left it there because it didnt break anything ;)

"[]" <~~ noob moment, pure and simple. It doesnt say that anywhere i can see int he help file so thanks for explaining.

Lastly, the GUICtrlRead function... everyone said "use it" but again, total noob here. I havnt the foggiest idea how! If I can see an example that has direct correlation to my project or something similar maybe that would help but the example in the help file does me exactly no good.

Edit --- after knocking my head against the desk for a while I'm kinda getting the idea that the GUICtrlRead function is what I'll be using to show progress on the progress bar right? o.O

Not sure how to incorporate it to show the progress of each successive install.... I think if I implement it the way the help file shows it will reset and show the progress bar resetting after each installation right?

Example()
Func Example()
    Local $menu1, $n1, $n2, $msg, $menustate, $menutext
    GUICreate("My GUICtrlRead") ; will create a dialog box that when displayed is centered
    $menu1 = GUICtrlCreateMenu("File")
    $n1 = GUICtrlCreateList("", 10, 10, -1, 100)
    GUICtrlSetData(-1, "item1|item2|item3", "item2")
    $n2 = GUICtrlCreateButton("Read", 10, 110, 50)
    GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button
    GUISetState() ; will display an empty dialog box
    ; Run the GUI until the dialog is closed
    Do
        $msg = GUIGetMsg()
        If $msg = $n2 Then
            MsgBox(0, "Selected listbox entry", GUICtrlRead($n1)) ; display the selected listbox entry
            $menustate = GUICtrlRead($menu1) ; return the state of the menu item
            $menutext = GUICtrlRead($menu1, 1) ; return the text of the menu item
            MsgBox(0, "State and text of the menuitem", "state:" & $menustate & @LF & "text:" & $menutext)
        EndIf
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example
Edited by pyr0ball
Link to comment
Share on other sites

Woo!!! tested out the script prototype and so far everything is running exactly the way It's meant to other than the progress bar! Building the scanning function should be easier than this is ;)

Anyhoo here's the updated code for you to see. All the installers are working as expected (quirks I need to iron out with the switches and arguments, but that has nothing to do with this script)

Link to comment
Share on other sites

  • 2 weeks later...

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