Sign in to follow this  
Followers 0
RedneckTech

CmdLine[x] possibility

9 posts in this topic

Im working with the $CmdLine[x] variables and i must say bravo to whoever got them working. Was just wondering if there was a feature in there that would detect if any of the command switches passed to the exe would pass.

basically:

myscript.exe /par1 /par2 /par3

and

myscript.exe /par3 /par2 /par1

would both do the same thing. Just wondering if there is a If $CmdLine[any] = /par2 Then

That way no matter which position par2 is in the exe will stil perform the same. sorry if this is confusing. i can try to reword if necessary

Share this post


Link to post
Share on other sites



RedneckTech,

I think you are going to have to loop through the array yourself: ;)

For $i = 1 To $cmdline[0]
    ConsoleWrite($cmdline[$i] & @CRLF)
    If $cmdline[$i] = "par2" Then
        MsgBox(0, "Found", "Par2")
        ExitLoop
    EndIf
Next
If $i > $cmdline[0] Then
    MsgBox(0, "Error", "Not found")
EndIf

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

yuck. thanks though. Not a dire feature, i guess the users will just have to learn to do something the right way for once :blink:

That and its probably just a sign for me to make things simple for once. Thanks!

Share this post


Link to post
Share on other sites

You could do something like this:

If $cmdline[0] > 0 Then
     For $I = 1 To $cmdline[0]
          Switch $cmdline[$I]
               Case "/par1"
                    $Par1 = 1
               Case "/par2"
                    $Par2 = 1
               Case "/par3"
                    $Par3 = 1
          EndSwitch
     Next
EndIf
If $Par1 Then MsgBox(64, "", "/par1 found")
If $Par2 Then MsgBox(64, "", "/par2 found")
If $Par1 Then MsgBox(64, "", "/par3 found")

This way, you're setting a flag when it sees one of the parameters, and it won't matter in what order they're in on the command line.


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

Share this post


Link to post
Share on other sites

Don't forget to declare the $Par# variables outside the loop, or it will error out on If ^ (when not defined inside the loop)

$Par1 = 0

$Par2 = 0

$Par3 = 0


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

i like what you guys have up. currently have this going (not finished) its basically just a comprehensive AV control script for update/scan just to make my life easier

If $CmdLine[0] <> 0 Then
   If $CmdLine[2] = "/full" Then
      $Full = 1
      If $CmdLine[3] = "-scan" Then
         $update = 0
      Else
         MsgBox(0,"","ERROR: Incorrect Parameter Syntax" & @CRLF & "Please consult the readme for more information")
      EndIf
   ElseIf $CmdLine[2] = "-scan" Then
      $update = 0
   Else
      MsgBox(0,"","ERROR: Incorrect Parameter Syntax" & @CRLF & "Please consult the readme for more information")
   EndIf
   If $CmdLine[1] = "ALL" Then
         _SEP()
         _MSSE()
         _AVAST()
         _MBAM()
         _Counter()
   ElseIf $CmdLine[1] = "SEP" Then
      _SEP()
   ElseIf $CmdLine[1] = "MSSE" Then
      _MSSE()
   ElseIf $CmdLine[1] = "AVAST" Then
      _AVAST()
   ElseIf $CmdLine[1] = "MBAM" Then
      _MBAM()
   Else
      MsgBox(0,"","ERROR: Incorrect Parameter Syntax" & @CRLF & "Please consult the readme for more information")
   EndIf
ElseIf $CmdLine[0] > 3 Then
   MsgBox(0,"","ERROR: Incorrect Parameter Syntax" & @CRLF & "Please consult the readme for more information")
Else
   _SEP()
   _MSSE()
   _AVAST()
   _MBAM()
   _Counter()
EndIf

any others you think i should add (norton is being added right now) and what the lines (either silent or over cmd with autoexit) for update/scan(quick and full) would be greatly appreciated!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Don't forget to declare the $Par# variables outside the loop, or it will error out on If ^ (when not defined inside the loop)

It was an example of how to do something with the command line, but you're right I should have declared them before using them just in case someone wasn't aware of that.

EDIT: RedneckTech, I wouldn't parse the command line the way you're doing it unless you're sure that there's going to BE a $cmdline[2] or [3], otherwise you're going to crash the script with an array subscript error. The way I showed makes it a LOT easier to parse the command line, and a lot safer because you don't have to hope that every parameter is going to be used.

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

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

PS. Trend Micro has already told me that "there are no supported command lines for controlling our titanium product" and i havent been able to find any, so if you know them it would be GREATLY appreciated, especially because there are like 6 different versions of trend AV and they all function differently apparently. Makin my life a nightmare

Edited by RedneckTech

Share this post


Link to post
Share on other sites

[...] Just wondering if there is a If $CmdLine[any] = /par2 Then

That way no matter which position par2 is in the exe will stil perform the same. sorry if this is confusing. i can try to reword if necessary

Maybe this could be what you want

#include <Array.au3>
Dim $params = _ArrayToString($CmdLine, @TAB, 1)

If StringInStr($params,"/par2") Then
MsgBox(0, "BINGO", "Found '/par2'")
EndIf

If StringInStr($params,"/par1") Then
MsgBox(0, "BINGO", "Found '/par1'")
EndIf

If StringInStr($params,"/par3") Then
MsgBox(0, "BINGO", "Found '/par3'")
EndIf

A-Jay


Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Share this post


Link to post
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
Sign in to follow this  
Followers 0