Jump to content
awaix

need to execute cmd commands

Recommended Posts

awaix

Hi,

im really new to this autoit.. ive been reading alot..

i just couldnt get how can i use cmd commands directly into autoit?

like i want to use

ipconfig /flushdns
net stop dnscache
ipconfig /flushdns
net start dnscache
ipconfig /flushdns

but i dont knw how can just get them to do in autoit? and in administrator mode?

i was able to do it by creating .bat file separatly and then executing it by requireadmin run command.. but what about having to have one one .exe? instead of having .bat and .exe?

Share this post


Link to post
Share on other sites
jamesstp20

Avec la commande Run normalement tu saurait capable de faire sa..

A+

Share this post


Link to post
Share on other sites
darkjohn20

$CMD = "ipconfig /flushdns"
RunWait(@ComSpec & " /c " & $CMD)

Edited by darkjohn20

Share this post


Link to post
Share on other sites
awaix

Avec la commande Run normalement tu saurait capable de faire sa..

A+

english please :$

didnt understand a thing.

Share this post


Link to post
Share on other sites
awaix

$CMD = "ipconfig /flushdns"
RunWait(@ComSpec & " /c " & $CMD)

error:
Line 1(File "C:\user\awaix\desktop\test2.au3"):
$CMD = "ipconfig /flushdns" RunWait(@ComSpec & " /c " & $CMD)
$CMD = "ipconfig /flushdns" RunWait(@ComSpec & " /c " & ^ERROR

Error: Variable used without being declared.

Share this post


Link to post
Share on other sites
darkjohn20

It needs to be on separate lines.

Share this post


Link to post
Share on other sites
awaix

now i didnt get any error.. but i didnt see the process too.. it was just a blink.. not sure what happened in it :mellow: where as flushdns takes time to complete itself.. can we do something like..

open cmd first and then execute the commands on it.. while showing whats happening??

Share this post


Link to post
Share on other sites
darkjohn20

Look at RunWait in the Help File.

$CMD = "ipconfig /flushdns"
RunWait(@ComSpec & " /c " & $CMD, @WindowsDir, @SW_SHOW)
Edited by darkjohn20

Share this post


Link to post
Share on other sites
MHz

The code below is perhaps worth a try as it attempts to do all 5 commands in a single CMD instance.

; Use to run the command following && only if the
; command preceding the symbol is successful.
; Cmd.exe runs the first command, and then runs
; the second command only if the first command
; completed successfully.
; Reference:
; http://technet.microsoft.com/en-us/library/bb490954.aspx
$CMD = 'ipconfig /flushdns && ' & _
        'net stop dnscache && ' & _
        'ipconfig /flushdns && ' & _
        'net start dnscache && ' & _
        'ipconfig /flushdns'

; /k keeps the CMD window open.
; /c closes the CMD window once the command is complete.
; Reference:
; Type CMD /? in a command prompt window for help
; with CMD options.
RunWait('"' & @ComSpec & '" /k ' & $CMD, @SystemDir)
  • Like 2

Share this post


Link to post
Share on other sites
darkjohn20

MHz is correct. I completely forgot about /k.

Share this post


Link to post
Share on other sites
RHaslitt

What about commands like netsh when you need to us " in the command?

 

Share this post


Link to post
Share on other sites
Jos

You realize this topic is some 6 years old?
anyway, what exactly is your question? show the command you need and what you tried.

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
VIP
3 hours ago, RHaslitt said:

What about commands like netsh when you need to us " in the command?

 

use single quotes

MsgBox(32, "Set DNS 1", _DosRun('netsh interface ipv4 add dns "Local Area Connection" 8.8.8.8'))
MsgBox(32, "Set DNS 2", _DosRun('netsh interface ipv4 add dns "Local Area Connection" 208.67.222.222 index=2'))

Func _DosRun($sCommand)
    Local $nResult = Run('"' & @ComSpec & '" /c ' & $sCommand, @SystemDir, @SW_HIDE, 6)
    ProcessWaitClose($nResult)
    Return StdoutRead($nResult)
EndFunc   ;==>_DosRun

 


Regards,
 

Share this post


Link to post
Share on other sites
Somerset

Trong do you have any common sense?


 

Spoiler

shoot_zpsfd329d66.png
dontbelieveeverythingyouthink_zps0e1e900

Madness is the first step to understanding...

Share this post


Link to post
Share on other sites
VIP
3 minutes ago, Somerset said:

Trong do you have any common sense?

Can you tell me more, english is not my native language.
"common sense" ?  You want to tell me does not to reply if it has any common sense?


Regards,
 

Share this post


Link to post
Share on other sites
Somerset

This thread was abandoned 6 years ago. The only two people that should be talking this thread should be the Mod(s) and the moron that revived the thread. You inquisition of this thread was unneeded.


 

Spoiler

shoot_zpsfd329d66.png
dontbelieveeverythingyouthink_zps0e1e900

Madness is the first step to understanding...

Share this post


Link to post
Share on other sites
VIP

I thought you were too strict!
Anyway, I will not repeat such an action.
Thank you for your prompt.

best regards,

Trong


Regards,
 

Share this post


Link to post
Share on other sites
Chimp
1 hour ago, Somerset said:

... The only two people that should be talking this thread should be the Mod(s) and the moron that revived the thread....

to which of those two you belong.... :lol: lol

  • Haha 1

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
StormCrowMth

And so here we are again re-living a 2 year old burn. Let this be a fun reminder that a post is useful in the future and can still be expanded beyond the original question at any time.

My code:

$CMD = " cd C:\Users\Someone's\Desktop\Nmf\ && " & _
        " 1.nmf "
RunWait('"' & @ComSpec & '" /c ' & $CMD, @SystemDir)

Problem:

It opens the file with its default program (NICE Player if you are wondering) no problem; But my code cant continue until the cmd window closes, and it doesnt, help!

best regards

Share this post


Link to post
Share on other sites
Jos
2 minutes ago, StormCrowMth said:

 But my code cant continue until the cmd window closes, and it doesnt, help!

That is to be expected since:
RunWait() will wait until the program finishes.
Run() will continue right away providing the PID of the running process.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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

×