Sign in to follow this  
Followers 0
careca

Use a variable in the parameters of shellexecute?

7 posts in this topic

Hi, i need to control the value in the parameter of shell execute function, because i want to add an edit box so i can change the value to my liking.

This a script to change the value of the computer volume by a small fraction with the pgup and pgdn hotkeys.

This executes an exe called nircmd, the syntax is "nircmd.exe changesysvolume 250" adds 250 to volume from 0 - 65535

Any solution is welcome :D

GUICreate ("Volume Control", 150, 150, 0, 0)
Local $setvol = 0
Local $volup = 1500
Local $voldn = -1500
GUISetState()

HotKeySet ("{PGUP}", "voluphk")
HotKeySet ("{PGDN}", "voldnhk")

GUICtrlCreateEdit ("", "30", "30", "80", "18")

Func voluphk()
ShellExecute ("nircmd.exe", "changesysvolume $volup", "C:\nircmd")
_WinAPI_Beep(1500, 200)
EndFunc

Func voldnhk()
ShellExecute ("nircmd.exe", "changesysvolume $voldn", "C:\nircmd")
_WinAPI_Beep(1250, 200)
EndFunc

Do
ToolTip("")
Until $setvol = 1

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

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

 

Share this post


Link to post
Share on other sites



Changed the code and now the code works, so the question now is how can i set a number i wanti it to increase or decrease in a editbox?

Local $volup = "changesysvolume 1500"
Local $voldn = "changesysvolume -1500"
GUISetState()

HotKeySet ("{PGUP}", "voluphk")
HotKeySet ("{PGDN}", "voldnhk")

GUICtrlCreateEdit ("", "30", "30", "80", "18")

Func voluphk()
ShellExecute ("nircmd.exe", $volup, "C:\nircmd")
_WinAPI_Beep(1500, 200)
EndFunc

Func voldnhk()
ShellExecute ("nircmd.exe", $voldn, "C:\nircmd")
_WinAPI_Beep(1250, 200)
EndFunc

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

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

 

Share this post


Link to post
Share on other sites

$edit = GUICtrlCreateEdit ("", "30", "30", "80", "18")

$result = GuiCtrlRead($edit) the edit box

then Int($result)

although you'll want to add some StringRegExp to make sure that only numbers are entered...


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks man

EDIT: ok, got it

Global $setvol, $editup, $editdn
Local $volup = "changesysvolume 1500"
Local $voldn = "changesysvolume -1500"
HotKeySet ("{PGUP}", "voluphk")
HotKeySet ("{PGDN}", "voldnhk")
$setvol = GUICreate ("Volume Control", 170, 100, 0, 0)

$editup = GUICtrlCreateInput ("changesysvolume 100", 10, 20, 150, 18)
Int ($volup)

$editdn = GUICtrlCreateInput ("changesysvolume -100", 10, 40, 150, 18)
Int ($voldn)

GUISetState()
Func voluphk()
$volup = GUICtrlRead ($editup)
ShellExecute ("nircmd.exe", $volup, "C:\nircmd")
_WinAPI_Beep (1500, 200)
EndFunc

Func voldnhk()
$voldn = GUICtrlRead ($editdn)
ShellExecute ("nircmd.exe", $voldn, "C:\nircmd")
_WinAPI_Beep (1250, 200)
EndFunc

like this when i press the hotkey it reads the value on the editbox and writes it, works fine! :D

Now for that tricky function

StringRegExp from what i could see, is like a filter of some sort,

but its kinda complicated, and i must do more reading,

can you give a heads up?

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

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

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

What I usually do when I want to make sure an edit box only displays what I want is, I'll put the check inside my while loop for gui msgs.

here is an example of what I mean

While 1
  $msg = GUIGetMsg();check for messages from the gui
  $newnam = GUICtrlRead($nam);read the input box
  $len = StringLen($newnam);get the length of the text in the input box
  If $len > 13 Then;if the text is more than 13 characters
   GUICtrlSetData($nam, StringLeft($newnam, 13));cut the text to only 13 characters
  EndIf

then the gui msg checks followed by the closing Wend...

*edit for more*

basically, each loop checking for Gui messeges, it reads the input, if it doesn't match the criteria, then fix it.

Because it loops so fast, it's ionstantanious.

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks, i was working with that bit, but i think it doesnt seem to apply to this case, i mean, if i cut down the string, then i wont recognize the parameter.

I was thinking it would be better to just add "changesysvolume " to the left of whatever the editbox string is... say i write on the editbox 1000.

Then use some function to add "changesysvolume" to the left of this, then use it.

Can be possibly simpler and easier on me. hehe :D

What do u say? can i use something like:

GUICtrlSetData ($editup, StringLeft ($volup, changesysvolume))

?

EDIT: Btw, while i was trying your bit, my second editbox disapeared.. :S

================================================================

EDIT: Any way this could work?

Local $vol = "changesysvolume "
HotKeySet ("{PGUP}", "voluphk")
$setvol = GUICreate ("Volume Control", 170, 100, 0, 0)
GUISetState()

$editup = GUICtrlCreateInput ("100", 10, 20, 150, 18)

Func voluphk()
$volup = GUICtrlRead ($vol + $editup)
ShellExecute ("nircmd.exe", $volup, "C:\nircmd")

Adding previously set

$vol = "changesysvolume "

with the editbox

$editup

($vol + $editup)

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

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

 

Share this post


Link to post
Share on other sites

Ok finally did it! Goes like this:

#requireadmin
#Include <WinAPI.au3>
#include <GuiButton.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiComboBoxEx.au3>
#include <GuiImageList.au3>
#include <GuiConstantsEx.au3>
#include <GuiEdit.au3>
Opt ("TrayIconDebug", 1)
Opt ("TrayAutoPause", 0)
Opt ("TrayOnEventMode", 1)
Opt ("WinWaitDelay", 100)
Opt ("ExpandEnvStrings", 1)
Opt ("MouseCoordMode", 2)
Opt ("WinDetectHiddenText", 1)
Opt ('MustDeclareVars', 1)
Opt ('GUIEventOptions', 0)

TraySetIcon ("volume.ico")

Global $setvol, $editup, $editdn, $vol, $sysvolup, $sysvoldn, $volup, $voldn
HotKeySet ("{PGUP}", "voluphk")
HotKeySet ("{PGDN}", "voldnhk")
$vol = "changesysvolume "
$setvol = GUICreate ("Volume Control", 180, 75, 0, 0)
GUISetState()

GUICtrlCreateLabel ("Volume Up Value", 15, 20, 110, 18)
$editup = GUICtrlCreateInput ("150", 115, 20, 40, 18)
GUICtrlCreateLabel ("Volume Dn Value", 15, 40, 110, 18)
$editdn = GUICtrlCreateInput ("-150", 115, 40, 40, 18)

Func voluphk()
$volup = GUICtrlRead ($editup)
$sysvolup = ($vol & $volup)
ShellExecute ("nircmd.exe", $sysvolup, "C:\nircmd")
_WinAPI_Beep (1500, 200)
EndFunc

Func voldnhk()
$voldn = GUICtrlRead ($editdn)
$sysvoldn = ($vol & $voldn)
ShellExecute ("nircmd.exe", $sysvoldn, "C:\nircmd")
_WinAPI_Beep (1250, 200)
EndFunc

Do
ToolTip ("")
Until $setvol = 1

It works like this, set a string to a variable

$vol = "changesysvolume "

Create an editbox

$editup = GUICtrlCreateInput ("150", 115, 20, 40, 18)

have an hotkey executing a function, and in the function,

read editbox

$volup = GUICtrlRead ($editup)

then add the "stringed" variable with the value you have in the editbox

$sysvolup = ($vol & $volup)

and execute the exe with the parameter and the value added.

ShellExecute ("nircmd.exe", $sysvolup, "C:\nircmd")

Awesome!

Thanks for the help guys!

Keep it up.


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

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

 

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

  • Similar Content

    • Miloud
      By Miloud
      How to get the result of the command?
      My code :
      Local $iRc = ShellExecute ( "G:\ffmpeg\bin\ffmpeg.exe" , "-version" , "G:\ffmpeg\bin\") ProcessWaitClose($iRc) $Message = StdoutRead($iRc)
    • breakbadsp
      By breakbadsp
      I want to run a python script from autoit. 
      I know we can do this with shellexecute or run , but this python script takes 3 cmd line arguments.
      How to pass them from autoit script?
      I tried many ways.
      Following solution also not working 
      e.g. 
      RunWait( 'fullpath\Python.exe Scriptpath\ReadLog.py  -f "file.log" -k "key" -e "errMsg" ') Found solution:
      RunWait( 'fullpath\Python.exe ReadLog.py -f "file.log" -k "key" -e "errMsg" ', 'Working_directory_path')  
      PFB description:
      https://stackoverflow.com/questions/45757834/how-to-pass-command-line-arguments-to-a-python-script-anyscript-while-executin
       
    • Mag91
      By Mag91
      Hey Community,
      cause im too new in the Auto it world i will try it with the your help. hopefully.
      I woud like to know how i can handle my Problem.
      ----
      I have a Excel Data with 362 random numbers.
      For Example:
      1166642335374 1172899897343
      .....
      this numbers are a part of the filepath ...example
      D:\Projekte\1166_64233_5374
      as u can see its the first number of the Excel data. After the first 4 numbers it shoud make a "_" than another 5 "_"
      This is my first question. How can i handle this to make it Shell execute.
       
      --------
      Second question:
      If i am in the path.
      For Example:
      D:\Projekte\1166_64233_5374
      the code shoud search for specific PDF Files.
      They are named like: 0050569E364B1ED79B900F73E62660EC.pdf
      the first 15 letters are always the same
      0050569E364B1ED
      when he found this data he has to copy it on a Folder on the Desktop.
      (There can also be 2 or 3 pdfs in one Folder with this letters)
      ----
      Please give me some help :-)
       
       
       
       
       
       
    • TrashBoat
      By TrashBoat
      Is this possible:
      Executing a function from an include, but taking the function name from a gui input and then executing that function using the include:
      #include <Something.au3> ;input reads "Tree" $functionName = GuiCtrlRead($input1) $functionName(1) And the include is gonna have
      Func Tree($x) If $x = 1 Then $this = "text" MsgBox(0,$this,"whatever") EndFunc is it possible?
    • SkysLastChance
      By SkysLastChance
      I keep losing the count of my $r varable when I go into the dropdown () function and call the same function.
      #include <Excel.au3> #include <AutoItConstants.au3> #include<GUIConstantsEx.au3> #include<EditConstants.au3> #include<GUIConstants.au3> Global $iBox, $oExcel, $oWorkbook, $r = 1, $x = 3 HowMany() Excel () Dropdown () Sleep (500) Func Dropdown () $list = GUICreate("Chart", 225, 80) $combobox = GUICtrlCreateCombo("Clinic 1", 10, 10, 120, 20) GUICtrlSetData(-1, "Clinic 2|Clinic 3|Clinic 4") $button = GUICtrlCreateButton("Select", 10, 40, 60, 20) GUISetState(@SW_SHOW) While 1 $guibox = GUIGetMsg() Select Case $guibox = $button Select Case GUICtrlRead($combobox) = "Clinic 1" GUIDelete($list) Auto () EndSelect Case $guibox = $GUI_EVENT_CLOSE EndSelect WEnd EndFunc Func HowMany() Local $iMsg While 1 ;~ Turn input into a number $iBox = Number(InputBox ("Regestration", "How Many Patients are there total?")) ;~ If user enters a string or cancels then get them to try again If $iBox = 0 Then $iMsg = MsgBox(1,'Regestration', 'Please enter a valid number') If $iMsg = 2 Then Exit Else ExitLoop EndIf WEnd EndFunc Func Excel() While ProcessExists("EXCEL.EXE") $ms = MsgBox(5,"","Process error. You have an Excel sheet open. You must close it in order to let this program work. Please close it now.") If $ms=2 Then Exit ;~ Doesn't require sleep since the script is paused by the MsgBox above ;~ Sleep(250) WEnd ;~ Shouldn't use Global Scope inside functions moved to top of script Local $sExcelFile = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsx)") If FileExists($sExcelFile) Then ;~ Shouldn't use Global Scope inside functions moved to top of script $oExcel = _Excel_Open () $oWorkbook = _Excel_BookOpen($oExcel,$sExcelFile) ;this will open the chosen xls file. Else $oExcel = _Excel_Open() $oWorkbook = _Excel_BookNew($oExcel, 2);this is here to create the xls file if it does not exist. EndIf EndFunc Func Auto() Local $aArray1 = _Excel_RangeRead($oWorkbook) ;~ If $iBox is greater than no. of rows in $aArray then $iBox equals the number of rows in $aArray If $iBox > (UBound($aArray1) - 1) Then $iBox = UBound($aArray1) - 1 For $i = 2 To UBound($aArray1) - 1 ;$i =0 Start from row A If $aArray1[$i][1] = "" Then Continueloop $sR0 = $aArray1[$i][0] ;status $sR1 = $aArray1[$i][1] ;Last Name $sR2 = $aArray1[$i][2] ;First Name $sR3 = $aArray1[$i][3] ;DOB $sR4 = $aArray1[$i][4] ;Sex $sR5 = $aArray1[$i][5] ;Mailling Address $sR6 = $aArray1[$i][6] ;Zip $sR7 = $aArray1[$i][7] ;Phone # $sR8 = $aArray1[$i][8] ;Visit Reason $sR9 = $aArray1[$i][9] ;Insurance $sR10 = $aArray1[$i][10] ;Clinic $sR11 = $aArray1[$i][11] ;Provider $sR12 = $aArray1[$i][12] ;Appt Time $sR13 = $aArray1[$i][13] ;Appt Date WinWaitActive ("Untitled - Notepad") ControlSend("Untitled - Notepad", "", "", $sR1 & ',' & $sR2 & @CR) $r += 1 If $r > $iBox Then Exit Dropdown () Next EndFunc so the second time I choose clinic 1 I want it to go to the next row which would be Champ brett in my example excel.
       
      Test.xlsx
      Example Format.xlsx