Jump to content
Sign in to follow this  
careca

Use a variable in the parameters of shellexecute?

Recommended Posts

careca

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.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
careca

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.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
kaotkbliss

$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
careca

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.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
kaotkbliss

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
careca

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.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
careca

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.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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  

  • Similar Content

    • California
      By California
      Hello,
      I wrote a benchmark script to measure variable declarations
      to find out whether you should focus more on static or global variables
      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.5 #ce ---------------------------------------------------------------------------- #Region Pre-Setting Local $iTally1 = 0 Local $iTally2 = 0 Local $iTally3 = 0 Local $iTally4 = 0 Local $iTally5 = 0 Local $iTally6 = 0 Local $iTally7 = 0 Global $GLOBALCONST1 = 1 Global $GLOBALCONST2 = 1 Global $GLOBALCONST3 = 1 Global $GLOBALCONST4 = 1 Global $GLOBALCONST5 = 1 #EndRegion Pre-Setting #Region Test Functions Func s1() Static $i = $GLOBALCONST1 Return $i EndFunc Func g2() Return $GLOBALCONST2 EndFunc Func g3() Static $i7 = "gsdgdfegbgbrwefw" Return $GLOBALCONST3 EndFunc Func g4() Static $i1 = 1 Static $i2 = "asd" Static $i3 = 234 Static $i4 = True Static $i5 = [0] Static $i6 = "hgsdg" Static $i7 = 1 Static $i8 = 1 Static $i9 = 1 Static $i0 = 1 Return $GLOBALCONST4 EndFunc Func g5() Local $i = $GLOBALCONST5 Return $i EndFunc Func g6() Local $i = 1 Return $i EndFunc Func g7() Return 1 EndFunc #EndRegion Test Functions #Region Benchmark Loop For $i = 0 To 15 Local $tDelta = TimerInit() Do $iTally1 += s1() Until TimerDiff($tDelta) >= 1000 Local $tDelta = TimerInit() Do $iTally2 += g2() Until TimerDiff($tDelta) >= 1000 Local $tDelta = TimerInit() Do $iTally3 += g3() Until TimerDiff($tDelta) >= 1000 Local $tDelta = TimerInit() Do $iTally4 += g4() Until TimerDiff($tDelta) >= 1000 Local $tDelta = TimerInit() Do $iTally5 += g5() Until TimerDiff($tDelta) >= 1000 Local $tDelta = TimerInit() Do $iTally6 += g6() Until TimerDiff($tDelta) >= 1000 Local $tDelta = TimerInit() Do $iTally7 += g7() Until TimerDiff($tDelta) >= 1000 Next #EndRegion Benchmark Loop ConsoleWrite(@CRLF&"Static1: "&$iTally1&" pkt"&@CRLF&"Global2: "&$iTally2&" pkt"&@CRLF&"Global3: "&$iTally3&" pkt"&@CRLF&"Global4: "&$iTally4&" pkt"&@CRLF&"Local5: "&$iTally5&" pkt"&@CRLF&"Local6: "&$iTally6&" pkt"&@CRLF&"Hardcode7:"&$iTally7&" pkt"&@CRLF) #cs Result Static1: 10291881 pkt global to static Global2: 13977324 pkt only global Global3: 9886169 pkt global and static Global4: 2933051 pkt global and many statics Local5: 9937314 pkt global to local Local6: 10306484 pkt only local Hardcode7: 14835319 pkt no variable #ce Result:
      100% no variable, hardcore value
      94% only global variable use
      69% only local variable use with hardcore value set
      69% only static variable use with global variable value set
      67% declaration of local variable with global variable value set
      66% only global variable use with one static variable beside
      20% only global variable use with ten static variables beside
      My thesis of the result:
      Be careful with declarations, whether local, global or static Note: in my test the global variable performance was better than the local one, but in practice the global one would lose performance due to multiple operations
       
      What is your best practice sharing data between multiple functions?
    • TheAutomator
      By TheAutomator
      Is this better to check a variable before you assign it to a value that could be the same?
      for example:
      local $EmptyLog = false func WriteLog($text) _guictrledit_appendtext($log, ($EmptyLog ? @CRLF : $empty) & $text) If $EmptyLog Then $EmptyLog = False endfunc or does AutoIt behind the scenes already check this?
      i guess overwriting memory with the same value over and over again is not good if you can prevent this with a check?
    • JNutt
      By JNutt
      I see $hWnd used as a local variable in a lot of script examples.  I know the 'h' is used for handles, but what is the 'Wnd' short for?
      Thanks!
    • Rskm
      By Rskm
      i have seen many pointing out issues related to this, i tried reading through them - still unable to solve mine.. i have a script which reads certain lines based on a search item, this is an iterative process - the ldflst_file gets updated for each iteration and the script finds the line number which has the search item. this works perfectly for few iterations, but stops in some cases abruptly with the error = 
      Subscript used on non-accessible variable $aRead^ ERROR I have verified that the search item is present in the file. what could be the reason for this code to stop in certain cases. thanks for help
      my code below (partial).. full code is in attachment
       
      local $aRead=FileReadToArray($ldflst_file)
      global $ldflst_var1=" JOINT  LOAD       FORCE(X)        FORCE(Y)        FORCE(Z)       MOMENT(X)       MOMENT(Y)       MOMENT(Z)"
       
      for $i= 0 to $ldflst_totlines    ; ldflst_totlines is total number of  lines in the file 'ldflst_file'

          if $aRead[$i]=$ldflst_var1 Then
              $ldflst_LFound=$i
              ExitLoop
              else
              EndIf
      Next
       
       
      nomo_new1.au3
    • kartune
      By kartune
      Hello, i'm trying to rename a variable to another variable name (not the value attached to the variable).  This would save me TONS of coding.
      Here is an example:
       
      <autoit>
      Local $clear1="$SATJ"  ;sets the $clear1 variable to become $SATJ
      GUICtrlSetState($clear1 & "3", $GUI_UNCHECKED)  ;i want this to come out to be $SATJ3, it should look something like - GUICtrlSetState($SATJ3, $GUI_UNCHECKED)
      </autoit>
      Is this possible?  I've been searching all the forums and help files for hours.  My javascript friend referenced me to the solution on JS, which lead me to searching through the "assign" help on autoit, but not much info on it.
      I've already tried
      <autoit>
      Assign($clear1, $SATJ)
      </autoit>
       
      any help is greatly appreciated!!! 
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.