# Search the Community

Showing results for tags 'CMD'.

• ### Search By Tags

Type tags separated by commas.

### Forums

• General
• Announcements and Site News
• AutoIt v3
• AutoIt Help and Support
• AutoIt Technical Discussion
• AutoIt Example Scripts
• Scripting and Development
• Developer General Discussion
• Language Specific Discussion
• Operating System Deployment
• Windows Client
• Windows Server
• Office

### Categories

• AutoIt Team
• Beta
• MVP
• AutoIt
• Automation
• Databases and web connections
• Data compression
• Encryption and hash
• Games
• Hardware
• Information gathering
• Internet protocol suite
• Maths
• Media
• PDF
• Security
• Social Media and other Website API
• Windows
• Scripting and Development
• Operating System Deployment
• Windows Client
• Windows Server
• Office

• Forum FAQ
• AutoIt

### Calendars

• Community Calendar

• 0 Replies

• 0 Reviews

• 0 Views

Found 55 results

1. ## [solved] problem to drive a command prompt via a NamedPipe

I'm trying to drive a command prompt by sending instructions via a NamedPipe. This way you can (should) be able to send commands to the command prompt and at the same time "view" the result in the same window. This is not allowed if you run a command prompt with "opt_flag" parameters (redirected streams) because this will disable StdOut on the cmd itself. This small (trivial) snippet works for the first command sent to the cmd, but further submissions will fail. Maybe the problem is in how I use the run () command to start a new cmd with the StdIn redirect from the NamedPipe. It seems that the generated cmd will close automatically after the first reception of the command via NamedPipe. suggestions on how to make it work are welcome thanks #include <NamedPipes.au3> #include <WinAPI.au3> ; Creates an instance of a named pipe Global $sPipeName = "\\.\pipe\pipename" Global$hPipe = _NamedPipes_CreateNamedPipe($sPipeName, 1, 1) MsgBox(0, "Debug", "Pipe created. Now open a CMD") ; run a cmd with only StdIn redirected (StdIn data incoming from a pipe) Global$hCMD = Run(@ComSpec & " /K cmd < " & $sPipeName & @CRLF, "c:\") ; ok? MsgBox(0, "Debug", "now Send a command to the cmd via a NamedPipe") _StdInPipeWrite("dir" & @CRLF) MsgBox(0, 'Debug', "further commands will fail" & @CRLF & "now send command 'dir c:\windows'")$sMessage = "Dir c:\windows" & @CRLF _StdInPipeWrite($sMessage) MsgBox(0, 'Debug', "send another command (will also fail)" & @CRLF & "now send command 'echo Hello'") _StdInPipeWrite("echo Hello" & @CRLF) MsgBox(0, "Debug", "end of test") ProcessClose($hCMD) Func _StdInPipeWrite($sMessage) ; =============================================================================================================================== ; This function writes a message to the pipe ; =============================================================================================================================== Local$iWritten, $iBuffer,$pBuffer, $tBuffer$iBuffer = StringLen($sMessage) + 1$tBuffer = DllStructCreate("char Text[" & $iBuffer & "]")$pBuffer = DllStructGetPtr($tBuffer) DllStructSetData($tBuffer, "Text", $sMessage) If Not _WinAPI_WriteFile( _$hPipe, _ ; ...... Handle to the file to be written $pBuffer, _ ; .... Pointer to the buffer containing the data to be written$iBuffer, _ ; .... Number of bytes to be written to the file $iWritten, _ ; ... The number of bytes written 0 _ ; ............ [optional] A$tagOVERLAPPED structure or a pointer to it ) Then ConsoleWrite("WriteMsg: _WinAPI_WriteFile failed" & @CRLF & _WinAPI_GetLastErrorMessage()) Else ConsoleWrite("WriteMsg: write OK" & @CRLF & _WinAPI_GetLastErrorMessage() & @CRLF) EndIf EndFunc ;==>_StdInPipeWrite
2. ## Gstreamer automation?

Greetings, I would like to be able to write a script to send commands to the console for creation of Gstreamer pipelines. I was thinking of something similar to this: Local $iPID = Run("C:\Windows\System32\cmd", "", @SW_MAXIMIZE) ;THIS OPENS THE CONSOLE...!!! if$iPID == 0 Then ConsoleWrite(@CRLF & "I DID NOT OPEN CMD...error: " & @error & @CRLF) if $iPID <> 0 Then ConsoleWrite(@CRLF & "I OPENED CMD...!!!" & @CRLF)$hCmd = WinGetHandle("C:\WINDOWS\system32\cmd.exe") if $hCmd <> 0 Then WinActivate($hCmd) ;ensure command console is active... $sOutput = Send("cd C:\gstreamer\1.0\x86_64\bin" & @CRLF,$SEND_RAW) $sOutput = Send("gst-launch-1.0 videotestsrc ! autovideosink" & @CRLF,$SEND_RAW) Sleep(3000) ControlSend($hCmd, "", "", "exit" & @CR) EndIf ;$hCmd NOT "0"... I don't really know if this is the best way to open the console and send commands into it. I'm also not sure about how to best catch any errors that may occur...likely this needs to be accomplished with the STDOUTREAD command however I've not had experience using it before and therefore would appreciate some advice that anybody may offer. Basically I'm seeking guidance on how to best automate the opening of the console, sending lines of commands to be executed, and handling any potential errors in the execution of those commands...I thank you in advance. Regards.
3. ## Script to get input from user ,check in csv file and read corresponding values and pass that value to cmd

Hi all, I have a csv file as below, I wand to find srno from csv and send corresponding ip and pass to commend cmd prompt. Please guide me to create script . srno,name,ip,pass 1,name1,ip1,pass1 2,name2,ip2,pass2
4. ## cmd Unicode text maker

Hi dear With this script you can print Unicode text in the CMD screen the script is easy to use just you write the text that contains Unicode in the first input and the script automatically reflect the code in the second input you can copy the text to the clipboard or you can try printing the text in the CMD window I apologize to everyone for colors and shape if not appropriate I'm a blind man and I do not see Thank you for your understanding Greetings to all of youCmdUtM.au3
5. ## Free console after _WinAPI_AttachConsole()

Hi. Thanks to this post (https://www.autoitscript.com/forum/topic/189553-writing-to-cmd/?do=findComment&comment=1361142) I can now write a helpfile to the cmd when for instance passing parameter -h or -help at cmd. But then cmd is blocked by the script (I had to free it with CTRL+BREAK): #include <WinAPI.au3> _WinAPI_AttachConsole() $hConsole = _WinAPI_GetStdHandle(1) _WinAPI_WriteConsole($hConsole, "Print helpfile................" & @CRLF) Inside MSDN Library then I found this sentence: A process can use the FreeConsole function to detach itself from its console. But I don't find something like _WinAPI_FreeConsole(). How can I do it in another way? Regards, Conrad
6. ## Return a sentence in cmd when launch from it

Hello I would like to know if there is a way to return a sentence in cmd when I launch from it (because I add arguments). For example, diskpart.exe which help to manage the key and hdd connected, when you launch it with the parameter "/f" the app return a sentence saying that it don't recognize the parameter "/f" and it return the sentence in the cmd where i started the application, not a new one. That's what I want to do but I couldn't find anything that would solve my problem on internet and on AutoIt like ConsoleWrite / ConsoleWriteError (don't work). Thanks
7. ## Capturing PSEXEC's command line output

I'm attempting to capture the output from the command line tool PSEXEC. I'm using AutoIT to run an instance of PSEXEC against a remote PC to audit Local Admins in my environment using net.exe (C:\Windows\System32> net localgroup administrators). However the usual trick I use to capture command line output does not appear to work well with PSEXEC, as the bottom portion of the output is missing from the return. Any ideas or recommendations are greatly appreciated. Here is what I'm working with: ;This script will read from a list of hosts and report who has local admin privileges on the machine #RequireAdmin Global $fileName = @ScriptDir & '\test.txt' ;hostlist, one host per line readHostList() ;Read list of hosts Func readHostList() Local$file = FileOpen($fileName, 0) While 1$line = FileReadLine($file) If @error = -1 Then ExitLoop ConsoleWrite($line & @CRLF) ;MsgBox(0,0,$line) getLocalAdmins($line) WEnd FileClose($file) EndFunc ;run PSEXEC to list local admins Func getLocalAdmins($remotePC) Local $testFile = @ScriptDir &'\test234.txt' FileOpen($testFile, 1) Local $psexec = 'psexec \\' &$remotePC & ' net localgroup administrators' FileWriteLine($testFile, _RunCmd($psexec) ) FileClose($testFile) EndFunc ;Used to return CLI output Func _RunCmd($sCommand) Local $nPid = Run(@Comspec & " /c" &$sCommand, @SystemDir, @SW_Hide, 8), $sRet = "" If @Error then Return "ERROR:" & @ERROR ProcessWait($nPid) While 1 $sRet &= StdoutRead($nPID) If @error Or (Not ProcessExists ($nPid)) Then ExitLoop WEnd Return$sRet EndFunc ## If i manually run the command on the remote PC via PSEXEC I will get the following output: PsExec v2.11 - Execute processes remotely Copyright (C) 2001-2014 Mark Russinovich Sysinternals - www.sysinternals.com Starting net on PCNAME... on PCNAME... net exited on PCNAME with error code 0. ------------------------------------------------------------------------------- admin Administrator Alias name administrators Domain\Domain Admins Comment Administrators have complete and unrestricted access to the computer/domain Members The command completed successfully. ## The returned output from running the above script is as follows: PsExec v2.11 - Execute processes remotely Copyright (C) 2001-2014 Mark Russinovich Sysinternals - www.sysinternals.com Alias name administrators Connecting to PCNAME... Starting PSEXESVC service on PCNAME... Connecting with PsExec service on PCName... Starting net on PCNAME.. net exited on PCNAME with error code 0. **Note to test this script PSEXEC must be in the system dir or the path in the script changed PSEXEC tool: https://docs.microsoft.com/en-us/sysinternals/downloads/psexec
8. ## Elevated CMD Prompt

Hi, I am currently trying to create a tool that will automate some task we need to preform at work. The task that I am trying to automate are mostly powershell based. I did a search on the forum and I came across sapien.activexposh COM object. A perfect match to create a GUI in autoit and a clean way to push powershell command for execution. But i hit a roadblock and I hope that someone can help me solve it. - before you can use this sapien activexposh object you must register it using RegAsm.exe. - The command to register the object is: “C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm /codebase {directory}\ActiveXPoshV3.dll” - The command prompt needs to be elavated prompt The problem: When I run [start -> cmd -> right click -> run as administrator] its seems to open a elevated prompt. But this prompt doesn’t have enough privilege to register a object in regasm.exe (RegAsm : error RA0000) The weird stuff: When I [create cmd shortcut to desktop -> right click -> run as administrator] it get a elevated prompt with enough permission to register a object with regasm.exe. (using the same account and laptop!) There seems to be a clear difference when opening the cmd prompt in the way I explained above, see screenshot Question: Is there way to programmatic start the Administrator:cmd window? BTW runas doesn’t seem to work for me…

14. ## Running PS1 Script with Parameters

Trying to automate the sideload of a Windows Store app via .ps1 script... RunWait(@ComSpec & ' /c' & 'C:\"WB Resources"\APP_Prod\Add-AppDevPackage.ps1') Above doesn't work... I assume this is trying to open in CMD. Normally we right click the .ps1 and open with powershell, then we have to type "A" to start the install, it installs and then type any yet to exit. However I cant get the powershell to even open. Kind of puzzled here, any suggestions would be a help. PS I also tried to convert the .ps1 to exe, but that was a huge failure... lol
15. ## Can't read STDOUT for quser

Hi! I'm triying to get the session id to close automatically a RDP session. I tried doing this: #RequireAdmin #include <Constants.au3> $DOS = Run('C:\Windows\System32\query.exe user', "", @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD) ;Run(@ComSpec & " /c " & 'Query User', "", @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD) ;Run(@ComSpec & " /c " & 'quser', "", @SW_HIDE,$STDERR_CHILD + $STDOUT_CHILD) ProcessWaitClose($DOS) $Message = StdoutRead($DOS) MsgBox(0,'',$Message) But the$Message is always empty, if I execute any of these commands in a cmd window, it works Any idea on why is this falling? there is another way to get this info? PS: Sorry for my english, i'm not native.

22. ## While Runwait

Hello, I just wrote a script that should copy data into my cloud using xcopy (cmd), but I want the Status Bar I have in my GUI to change it's text like that: working. -> working.. -> working... -> working. ... I would also like to make a button which interrupts xcopy (simply closing it should do the trick), but I don't know how to call ProcessClose("xcopy.exe") using a button, while I'am waiting for RunWait to finish. Example: $command = 'xcopy "' & @DesktopDir & '\text.txt"' & ' "\\ADMIN-CLOUD\private\" /EECHIY'$SW_STATE = @SW_HIDE RunWait(@ComSpec & " /c " & '"' & $command & '"', @DesktopDir,$SW_State) Please tell me if you need any further information!

25. ## Check wether AutoitScript has finished

How can I check wether my current autoitscript (.exe) has finished, my problem is that I have a button which starts the autoit, if the user clicks twice in the button or more times the script shall check if its runs or not
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...