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

    • Atoxis
      By Atoxis
      Howdy, this is my first post, massive fan of autoit. 
      I've searched and tried and I would just like people who are better at this than me to let me know if this is even a thing.

      I'd like to perform just a variable. For example, it would be. *see inserted code*
      So what i'm wanting is, create the constant $test, and that variable would be what is followed after the = . Then perform the _FileCreate. Then perform the variable.  Logically or in my head rather.. That variable is declared and is equal to what it is set to above, therefore just placing the variable plainly in the script, it should be equal to what it was declared as.  So what am I doing wrong, and or how can I have autoit just perform the variable.  

       
      #include <File.au3> Const $test = FileWriteLine(@DesktopDir & "\Log.txt", @CRLF ) _FileCreate(@DesktopDir & "\Log.txt") $test  
    • BlazerV60
      By BlazerV60
      Hello all,
      I've been trying to figure out how to launch Google Chrome in the background (hidden) but it doesn't seem possible. I've tried the following methods:
      ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "", "", "", @SW_HIDE) Also I've tried:
      ShellExecute(@ComSpec, "/c start chrome.exe","","",@SW_HIDE) Lastly I tried:
      RunWait('"'&@ProgramFilesDir&'\Google\Chrome\Application\chrome.exe" --silent-launch',@ScriptDir)  
      But all of them launch my chrome browser without hiding it. Does anyone know a workaround for this or if AutoIT just can't Chrome? 
      Bonus points if you know how to make it launch chrome hidden and make it go to https://www.autoitscript.com
       
      Thank you,
      Brian
    • ur
      By ur
      I have a script , during compilation and test execution, it worked perfectly but sometimes I am getting error as "Variable used without being declared."
       
      I understood somewhere in the branching logic this is happening.
       
      But not able to find it exactly.
       
      As I am using multiple include statements.the line number is also not giving accurately.
       

       
      Can anyone suggest what is the approach to resolve this?
    • 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