Jump to content

Recommended Posts

Posted

Hi I want to wirte an AutoIT skript in witch I can set an Passwort if i send an cmd comand.

I have writen some skript where i safe an Passwort form an GUI to an ini. My problem is, that i dosn´t now how to use cmd in AutoIT.

I want to wirte: Test.au3  -s testPass   ;//-s for set Passwort testPass in the ini data

(IniWrite($sFilePath, "Pass", "Passwort", ?))

I want to wirte: Test.au3  -r    ;//-r for read the Passwort (testPass)

 

Posted

Its not very secure way to keep your password, would recommend using encryption, here is a basic example of what you want to do, just compile the file as an exe and you can use -s or -r.

#NoTrayIcon
Local $sGetPwd = Null, $sSetPwd = Null
Local $g_sFilename = @ScriptDir & "\Filename.ini"

If $CmdLine[0] >= 1 Then
    $sSetPwd = _CmdGetValue("s") <> Null ? _CmdGetValue("s") : Null
    $bGetPwd = _CmdLine_Exists("r")
EndIf

If $sSetPwd <> Null Then IniWrite($g_sFilename, "Pass", "Password", $sSetPwd)
If $bGetPwd Then MsgBox(4096, "Password", IniRead($g_sFilename, "Pass", "Password", Null))

Func _CmdGetValue($sCmdLine, $vResult = Null)
    For $i = 1 To $CmdLine[0]
        If $CmdLine[$i] = "/" & $sCmdLine Or $CmdLine[$i] = "-" & $sCmdLine Or $CmdLine[$i] = "--" & $sCmdLine Then
            If $CmdLine[0] >= $i + 1 Then
                If StringLeft($CmdLine[$i + 1], 1) = "/" Or StringLeft($CmdLine[$i + 1], 1) = "-" Or StringLeft($CmdLine[$i + 1], 2) = "--" Then
                    Return $vResult
                Else
                    Return $CmdLine[$i + 1]
                EndIf
            EndIf
        EndIf
    Next
    Return $vResult
EndFunc

Func _CmdLine_Exists($sCmdLine)
   For $i = 1 To $CmdLine[0]
      If $CmdLine[$i] = "/" & $sCmdLine Or $CmdLine[$i] = "-" & $sCmdLine Or $CmdLine[$i] = "--" & $sCmdLine Then
         Return True
      EndIf
   Next
   Return False
EndFunc

 

Posted

@Marius-Ligon

In the Help file, look at the section under "Using AutoIt", called "Command Line Parameters.  You will see how to get access parameters passed to your script.  ($CmdLine array and $CmdLineRaw).

Posted
1 minute ago, Marius-Ligon said:

I want to now what did i write in cmd for a key to start something in the AutoIT skript?

Sorry, I don't understand your question.  Can you ask it in a different or more detailed way?

Posted (edited)

If you are asking how can you test it in the editor, then if you are using the full scite editor, you can hit Shift+F8 to enter parameters that you want to pass to your script.  If you have compiled your script, the you would pass parameters to it the way you would with any other console application.  How you process the command line is up to you.

image.png.3a4061e04074dcd92ec5d27413b1b432.png

If you want to run the .au3 file from the command line instead of a complled .exe, then go to the same section of the help file that I referenced earlier.  It shows you the syntax for running .au3 scripts.

Edited by TheXman
Posted

@TheXman

Have you an example for me ?

Quote

#NoTrayIcon
Local $sGetPwd = Null, $sSetPwd = Null
Local $g_sFilename = @ScriptDir & "\Filename.ini"

If $CmdLine[0] >= 1 Then
    $sSetPwd = _CmdGetValue("s") <> Null ? _CmdGetValue("s") : Null
    $bGetPwd = _CmdLine_Exists("r")
EndIf

If $sSetPwd <> Null Then IniWrite($g_sFilename, "Pass", "Password", $sSetPwd)
If $bGetPwd Then MsgBox(4096, "Password", IniRead($g_sFilename, "Pass", "Password", Null))

Func _CmdGetValue($sCmdLine, $vResult = Null)
    For $i = 1 To $CmdLine[0]
        If $CmdLine[$i] = "/" & $sCmdLine Or $CmdLine[$i] = "-" & $sCmdLine Or $CmdLine[$i] = "--" & $sCmdLine Then
            If $CmdLine[0] >= $i + 1 Then
                If StringLeft($CmdLine[$i + 1], 1) = "/" Or StringLeft($CmdLine[$i + 1], 1) = "-" Or StringLeft($CmdLine[$i + 1], 2) = "--" Then
                    Return $vResult
                Else
                    Return $CmdLine[$i + 1]
                EndIf
            EndIf
        EndIf
    Next
    Return $vResult
EndFunc

Func _CmdLine_Exists($sCmdLine)
   For $i = 1 To $CmdLine[0]
      If $CmdLine[$i] = "/" & $sCmdLine Or $CmdLine[$i] = "-" & $sCmdLine Or $CmdLine[$i] = "--" & $sCmdLine Then
         Return True
      EndIf
   Next
   Return False
EndFunc

 That dosn´t work 

Posted
9 minutes ago, Marius-Ligon said:

That dosn´t work 

 

Posted
3 hours ago, Marius-Ligon said:

I want to wirte: Test.au3  -s testPass   ;//-s for set Passwort testPass in the ini data

(IniWrite($sFilePath, "Pass", "Passwort", ?))

I want to wirte: Test.au3  -r    ;//-r for read the Passwort (testPass)

If StringInStr($cmdlineRaw, "-s") Then
    $Result = StringRight($cmdlineRaw, StringLen($cmdlineRaw)-StringInStr($cmdlineRaw, '-s')-2)
    IniWrite(@ScriptDir&'\1.ini', "Pass", "Password", $Result)
    Exit
ElseIf StringInStr($cmdlineRaw, "-r") Then
    $IniR = IniRead(@ScriptDir&'\1.ini', "Pass", "Password", '')
    ConsoleWrite($IniR&@CRLF)
    Exit
EndIf

 

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

To be fair, the help file doesn't say why the -2 is used in the specific line of code you made.

@Marius-Ligon  Perhaps you can try it with and without the -2 and see the difference for yourself?

Posted (edited)
11 hours ago, Marius-Ligon said:

@careca

Why did you need that -2 ?

In your defense, if you dont have much experience in this language, this might be confusing even after checking the help file.

So the stringright returns a number of characters from the right hand side of a string.

first parameter is the original string, the second is the count.

So in the count part we have the stringlen (lenght) of the original string minus the position of '-s', given by the stringinstr, minus 2 because we dont want to retrieve the '-s' or any bit of it.

So if you remove the -2 you get the 'S', a space, and the portion of the string you want.

Edited by careca
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

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
×
×
  • Create New...