I try to call powershell with the parameters:
PowerShell -Command "Add-Type –AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak('hello');"
However, I cannot figure out how to do it.
does nothing, not even throw an exception. The shl.process_completed is not raised. If the above command line however is entered in powershell, it works.
Thanks for help
Thank you, Chris, I did not copy this statement in my first post, but I tried run / runsynchronous / runwithoutputevents. No luck. So maybe there is something wring with the parameters.
This is really a really cool snippet. It makes it very simple to run Windows 10 PowerShell scripts. It doesn't require special permissions. Public Sub PowerShellScript(s As String) As ResumableSub s = s.Replace(CRLF, ";").Replace("""", "'") Dim shl As Shell...
Dim js As Shell
Dim params As List
params.Initialize
Dim mystring As String=$"(Add-Type ....your command......)"$
js.InitializeDoNotHandleQuotes("js", "powershell.exe", Array(mystring))
js.WorkingDirectory="c:\windows\system32"
js.Run(-1)
Wait for (js) js_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
'Log(StdOut)
The problem is obviously where you entered "your command" ! So I looked for a workaround and found one with Balabolka. It has a free download for a command line utility (balcon.exe) and is easy to call:
B4X:
Sub Button1_Click
Private TextString As String = TextField1.text 'entered in the main form
fx.Clipboard.SetString(TextString) 'get it to the clipboard
shl.Initialize("shl","c:\program files\balcon\balcon.exe",Array As String("-c")) 'or any other reasonable path to balcon.exe
shl.Run(10000) 'plenty of timeout
End Sub
Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
If Success And ExitCode = 0 Then
Log("Success")
Log(StdOut)
Else
Log("Error: " & StdErr)
End If
End Sub
the -c command (there are a tad of others commands) speaks the contents of the text in the clipboard. Thanks to all for the help!