Jump to content

need to execute cmd commands


Recommended Posts

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?

Link to comment
Share on other sites

$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.
Link to comment
Share on other sites

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??

Link to comment
Share on other sites

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)
Link to comment
Share on other sites

  • 6 years later...
  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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,
 

Link to comment
Share on other sites

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,
 

Link to comment
Share on other sites

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

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
Share on other sites

  • 1 year later...

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

Link to comment
Share on other sites

  • Developers
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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...