However when I use my cmd based executable it opens and does nothing, I believe it still needs to load after opening and so when the arguments are passed it isn’t ready to load them yet.
Is there a way to pass arguments to an already opened cmdlet?
I have tried this wich emulates the keyboard to write my command into the cmd window and then presses “enter”. It works, but requires another task on my pc to open via Remote Desktop the server so it detects a keyboard to emulate.
Is your “cmd based executable” not actually cmd.exe? I’m guessing it’s another launcher that calls cmd.exe to start a process/application? If that’s the case, you’re getting into some nested command stuff that gets a little grey…
Can you tell us what “cmd based executable” you’re working with and maybe provide us with the code you’re using and output from running it?
Youy guessed right, I’m not using cmd.exe. I’m using OpenSSL (wich runs a cmd like window, It reads regular cmd commands) to encrypd and decrypt files.
I have some CSV files that will be generated on a server with 3DES encryption that I need to decrypt every day with OpensSL and then send to another remote PC for analysys and import.
The string I run is formatted like this (I construct it via Powershell using the various file path):
Well, certutil can be run from a standard command prompt or PowerShell without launching OpenSSL, at least in my experience. You can also run OpenSSL commands directly from a standard prompt or PowerShell without entering the interactive shell. So, if that’s all you need to do, you can create the command string and call the executable directly from the script.
I’ve included 2 options below. (Keep in mind that I have not executed this script, and I don’t even have OpenSSL installed on this machine, so you may have to tweak it until you get it right!)
Using the ampersand (‘&’) in front of the command tells the PowerShell interpreter to kick off the external process and let it do its thing. Using Start-Process to kick it off allows you to do things like controlling the window and receiving any output. In your case, I don’t think it would really matter, but look into the pros and cons of each.
So, I’m not sure I really answered your original question about passing args to a running process, but maybe I gave you a different approach to your solution!
Thank you so much! I used the second option and it works, there is only a single problem left, not all the files are decoded.
Right now in my start folder I have 17 files, decoding one after another didn’t wotk on all files (only 8 were decoded), so I tried putting a time-out between each decode process.
Start-Sleep -Milliseconds 5000
My first time-out was 1 second and I noticed it decoded more files, so I tried increasing the time-out. With 5 seconds it decoded 16 out of 17 files, almost good, but with 6 seconds it decoded 12 files only.
Any suggestions? Note that i don’t know how many files there will be each day to decode, codul be 6 or could be 30 (more I doubt).
I first check of the original file is present in a folder I use for backup, if it isn’t I copy the file and then I proceed to decode it. The backup check is to not decode the same file twice.
For decode yes, I mean the 2 operations to be successful and having the decrypted CSV.
With the emulation of the keyboard timing wasn’t an issue, I don’t know if it is too fast or not in executing Certutil and opensssl
Thank you, I tought later of that, a Sleep of 5 seconds (maybe I can reduce it, but for now it doesn’t matter much) between the 2 Satrt-Process fixed everything