Jump to content

Recommended Posts

Posted

I've read help file for couple of days now covering the topic of passing arguments to the executable as well as searched here and i still dont get it.

What do i need to add to the script so that once argument is passed, a specific function gets executed ?

Here is my code.

I tried activating my function placing

If $CmdLine[1] = "/Run" Then StartMonitoring()

in the script before everything else is created, but that ends with array related error. And if i compile the script, it crashes.
Can someone help me out here ?

thanks !

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <Array.au3>

If $CmdLine[1] = "/Run" Then StartMonitoring()

Global $File = @ScriptDir & "\Safe.txt"
Global $GUI = GUICreate ("UPA",200,440)


GUICtrlCreateGroup ("Names of processes",5,5,200,590)
$ListView = _GUICtrlListView_Create ($GUI,"Process Name",10,20,190,300)
$ListviewHandle = GUICtrlGetHandle ($ListView)
_GUICtrlListView_SetColumnWidth ($ListView,0,170)
$SaveAsSafe = GUICtrlCreateButton ("Mark displayed processes as Safe",0,320,200,40)
$StartMonitoring = GUICtrlCreateButton ("Start Process Monitoring",0,360,200,40)
$EnableStartup = GUICtrlCreateButton ("Enable Monitoring on Startup",0,420,200,20)
If RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run","UnknownProcessAlarm") = @ScriptFullPath Then GUICtrlSetData ($EnableStartup,"Disable Monitoring on Startup")

GUISetState (@SW_SHOW,$GUI)
_GetProcesses()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
    If $msg = $SaveAsSafe Then
        $ProcessList = ProcessList() ;get total number of all processes and their names and PID's
        $NumberOfProcesses = $ProcessList[0][0]
        For $i=1 to $NumberOfProcesses
            $Name = '"'&$ProcessList[$i][0]&'"' ;quoted so that its not confused
            If StringInStr (FileRead ($File),$Name) = 0 Then
                FileWrite ($File,@CRLF & $Name)
            EndIf
        Next
    EndIf
    If $msg = $StartMonitoring Then
        GUISetState (@SW_HIDE,$GUI)
        StartMonitoring()
    EndIf
    if $msg = $EnableStartup Then
        If RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run","UnknownProcessAlarm") = "" Then
            RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "UnknownProcessAlarm","REG_SZ",@ScriptFullPath)
            GUICtrlSetData ($EnableStartup,"Disable Monitoring on Startup")
        Else
            RegDelete ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run","UnknownProcessAlarm")
            GUICtrlSetData ($EnableStartup,"Enable Monitoring on Startup")
        EndIf
    EndIf
WEnd

Func _GetProcesses()
    $ProcessList = ProcessList() ;get total number of all processes and their names and PID's
    $NumberOfProcesses = $ProcessList[0][0]
    For $i=1 to $NumberOfProcesses
         _GUICtrlListView_AddItem ($ListView,$ProcessList[$i][0])
    Next
EndFunc

Func StartMonitoring()
    While 1
        $ProcessList = ProcessList()
        $NumberOfProcesses = $ProcessList[0][0]
        $SafeProcesses = FileRead ($File)
        For $i=1 to $NumberOfProcesses
            $Name = $ProcessList[$i][0]
            $Path = "Not yet implemented" ;$ProcessList[$i][0]
            If StringInStr ($SafeProcesses ,$Name) = 0 Then ;new process detected
                $NewGUI = GUICreate ("Unknown processes",200,200,-1,-1,$GUI_SS_DEFAULT_GUI,$WS_EX_TOPMOST,$GUI)
                GUISetState (@SW_SHOW,$NewGUI)
                GUICtrlCreateLabel ("Found unknown process",0,10,'','',$SS_CENTER)

                GUICtrlCreateLabel ("Name: ",10,43,30,20,$SS_RIGHT)
                    $UnknownProcessName = GUICtrlCreateInput ($Name,40,40,150,20)
                GUICtrlCreateLabel ("Path: ",10,63,30,20,$SS_RIGHT)
                    $UnknownProcessName = GUICtrlCreateInput ($Path,40,60,150,20)
                $Stop = GUICtrlCreateButton ("Terniminate this process",10,80,180,20)
                $MarkSafe = GUICtrlCreateButton ("Mark as SAFE",10,100,180,20)
                While 1
                    $msg = GUIGetMsg()
                    If $msg = $GUI_EVENT_CLOSE Then Exit
                    If $msg = $Stop Then
                        ProcessClose ($Name)
                        ProcessWaitClose ($Name)
                        GUIDelete ($NewGUI)
                        ExitLoop
                    EndIf
                    If $msg = $MarkSafe Then
                        FileWrite ($File,@CRLF & '"'&$Name&'"')
                        GUIDelete ($NewGUI)
                        ExitLoop
                    EndIf

                WEnd
            EndIf
        Next
    WEnd
Endfunc

 

  • Developers
Posted (edited)

This will avoid that error in case no parameter was provided:

For $x = 1 To $CMDLINE[0]
    ; 
    If $CMDLINE[$x] = "/Run" Then StartMonitoring()
    ;
Next

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

If you want to test parameters while running in the Scite editor, hit Shift+F8 to enter your parameters.

image.png.c233c37c27c8e76697ffcc8eb2ef9efc.png

Posted (edited)
8 minutes ago, antmangonnahappen said:

$CMDLINE not case sensitive correct ?

Case sensitivity depends on how you do your comparisons.  It doesn't have anything to do with what is passed as a parameter. 

If you want to do case-sensitive comparisons, then you can use the StringCompare function or the "==" operator.

Edited by TheXman
Posted

In the topic "Running Scripts", no, i dont see it.

I agree there should be an example such as that.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted
17 hours ago, careca said:

In the topic "Running Scripts", no, i dont see it.

I agree there should be an example such as that.

I think that would create errors if the arguments must be passed in order depending on action.

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
  • Recently Browsing   0 members

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