I have a program that runs a shell command to do a constant ping, but when its ran, it does not bring the cmd window to front.
This seems like it has to have some little fix I am missing.
Code:
Shell("ping " & IPAddy.Text & " -t")
Shell("ping " & IPAddy.Text & " -t", AppWinStyle.NormalFocus)
Use the Style parameter with the argument AppWinStyle.NormalFocus as shown above
MSDN: Shell Function: https://msdn.microsoft.com/en-us/library/xe736fyk(v=vs.90).aspx
Related
I tried a lot with the keepassxc-cli manpage but was not able to solve my seemingly simple task. I couldn't find real examples as well.
I want to invoke keepass-cli from a vba-script (I have reasons ;-) ) and retrieve a username/password (can be in two steps) to use in a script. I can copy the password on the shell when typing:
$ keepassxc-cli clip "path\to\db" "db entry name"
Then I am prompted to type in my master password.
However I would like to keep the user from the cli and rather have an input in my original script so the user can type the master password there and the password is handed over seamlessly.
In short I am looking to a way to enter something along the lines
$ keepassxc-cli clip "path\to\db" "db entry name" -master "my secret master password"
NB: keepassxc has the option --pw-stdin which keepassxc-cli seems to be missing. (Then I could use this answer)
Security level overall is quite low, however I don't want to put a database pw (for read access) verbatim into the script (as it is done by my predecessor), and in a company environment I cannot install plugins for keepassxc or similar.
Any pointers to some examples of keepass-cli examples are also very much appreciated.
Your post is tagged with VBA, and your answer looks like a linux shell?
I couldn't get that to work using CMD, invalid credentials errors etc. (although I didn't try all that hard)
Powershell handles it just fine though.
Assumed you wanted VBA, the paths to the cli and database would need to be changed.
Sub ClipPassword(Name As String, Master As String)
CreateObject("WScript.Shell").Run "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -WindowStyle Hidden -Noninteractive -NoProfile -Command " & Chr(34) & Chr(39) & Master & Chr(39) & " | &" & Chr(39) & "C:\Path\To\KeePassXC-2.7.4-Win64\keepassxc-cli.exe" & Chr(39) & " clip " & Chr(39) & "C:\Path\To\Passwords.kdbx" & Chr(39) & " " & Name & Chr(34)
End Sub
The command run in powershell is essentially the same as your answer
"masterpassword" | &keepasxc-cli clip "database" account
Reading this issue on keepassxc's github let me realise that using echo also helps here:
$ echo notsosecretpassword | keepassxc-cli clip "path\to\db" "db entry name"
Upload file via FTP from Excel VBA was very helpfull, I'm using the code to synchronize a local folder to my FTP server.
Call Shell( _
CurrentProject.Path & "\WinSCP.com /log=" & CurrentProject.Path & "\ftp.log /command " & _
"""open ftp://user:pass#ftp.server.com/"" " & _
"""synchronize local " & localfolder & " /www/remotefolder/wines -filemask=""*.png"" " & _
"""exit""")
I'm trying to issue an exit command at the end, but the code gives me a
Too many parameters for command 'synchronize'.
The line in the log tells me
synchronize local C:\localfolder\wines /www/remotefolder/wines -filemask=*.png exit
The exit is in the same line as the synchronize one, when I use the put script this doesn't happen. What can I do to prevent this?
You are missing closing quote after the synchronize command. And the quotes around -filemask value have to be doubled. Or actually, you do not need them, as the value does not contain spaces.
This will do:
"""synchronize local " & localfolder & " /www/remotefolder/wines -filemask=*.png""" & _
See https://winscp.net/eng/docs/commandline#syntax
The symbol you have at the beginning of —hostkey and —rawsettings is not a simple hyphen-minus (-), but em-dash (—).
Please use hyphen-minus (-) — what is the dash that you find on the standard English [and other] keyboards.
So actually you have the very same problem as in WinSCP forum post you referred to.
Or even easier, have WinSCP GUI generate a script template for you.
Also see FAQ Why are some WinSCP scripting commands specified in a batch file not executed/failing?
Other questions with the same error message, but different problem:
WinSCP command line - Too many parameters for command 'open' when using -rawtransfersettings switch
WinSCP "Too many parameters for command 'open'." error
FTP "Too many parameters for command 'synchronize'" with WinSCP
so I'm trying to get a very simple shell command to execute a batch file that's created, but for some reason the shell command doesn't do anything.
The batch file gets created and when I double click on the batch file it executes the script just fine, but if I try to call the shell command in VBA it appears that it tries to open a command window, but immediately closes it after, not producing any errors. This code used to work fine before I reformatted this laptop AND this code works on another system running Server 2012 R2 (I'm running windows 10)
Dim SedjaShell
f = "C:\Temp\_SedjaScript.bat"
Open f For Output As #1
Print #1, Chr(34) & SedjaDir & Chr(34) & " merge --files " & Page1 & " " & Page2 & " " & TOS & " " & Disclosure & " --output " & OutputDir
Print #1, "Pause"
Close #1
SedjaShell = Shell("C:\Temp\_SedjaScript.bat", 1)
Is there something I might be missing?
EDIT
Adding the contents of _SedjaScript.Bat
"C:\Users\User\Desktop\DealTracker\MergeFiles\sejda-console-3.0.4\bin\sejda-console.bat" merge --files C:\Temp\ContractSummary.pdf C:\Temp\Page2.pdf C:\Temp\TOS.pdf C:\Temp\Disclosure.pdf --output "C:\Users\User\Desktop\DealTracker\Completed Contracts\Company-Name-Inc-07-19-2017-Contract.pdf"
Pause
Thanks to Andre I was able to get the script to work inside VBA's Shell command.
By setting the PATH for my JRE to JAVA_HOME I was able to successfully launch the script.
setx JAVA_HOME "C:\Program Files (x86)\Java\jre1.8.0_141"
setx PATH "%PATH%;%JAVA_HOME%\bin";
I have 2 VB6 application which may launch the same VB.NET application (same exe) via a subMenu. The VB6 code to start this application is a Shell command :
ret = Shell(exe, 1)
My problem is when the user exit the main application (VB6), it won't close the VB.NET application if he opened it.
I tried to use the Taskkill command. It effectively kills the application, but it kills this app for every users on the server !!
I need to do it only for the current user. Can anyone help ?
EDIT : I found some documentation with Taskkill.
It seems that i can precise a user and a domain in the command. I use the following code :
Dim cmdShell As String
quote = Chr$(34)
cmdShell = "taskkill.exe /f /fi " & quote & "USERNAME eq " & _
LCase(connection_User) & quote & " /im " & exeToKill
If someone have a better idea, i'm in :)
I have a problem with CMD in a VB.NET project I'm making. How can I input three different commands to the same CMD window I open through a Button on my Form. Whenever I click the button on my form I want the CMD window to open, execute the first command and then automatically proceed to execute the next command and so on.
The three commands must be run in the same sequence in order to do its job.
The code I used:
Process.start ("cmd","/k First Code " & "Second Code " & "Third Code")
You could write out a batch file to disk and then run the batch file.
Also see: How to run two commands in one line in Windows CMD?
It looks like you can use & to separate commands.
I'd do something like:
Process.Start(String.Format("cmd /k {0} & {1} & {2}", "First Code", "Second Code", "Third Code"))
This might work better: (as an example)
Process.Start("cmd", String.Format("/k {0} & {1} & {2}", "dir c:", "dir /w c:", "pause"))
You can substitute your own commands in here.
This is what I ended up using, thanks to the other answer
Process.start ( "cmd" , "/k First code second code -c Third Code " )