B4J Question jShell at the same arg double quotes and single quotes...

Magma

Expert
Licensed User
Longtime User
Hi there...

Well I've got this strange error... and I am trying to figure how i will bypass it... (i know one way will to create a batch or a script for it - but need it like this to avoid - click simulate from batch.)

B4X:
            Dim js As Shell
            Dim params As List
            params.Initialize
            Dim mystring As String=$"(Add-Type '[DllImport(\"user32.dll\")]^public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)"$
            js.Initialize("js", "powershell.exe", Array(mystring))  <---here getting error...
            js.WorkingDirectory="c:\windows\system32"
            If Main.ShellEncoding.Length>0 Then js.Encoding=Main.ShellEncoding
            js.Run(-1)
            Wait for (js) js_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
            'Log(StdOut)

The error:
java.lang.IllegalArgumentException: Can't handle single and double quotes in sam
e argument
at b4j/org.apache.commons.exec.util.StringUtils.quoteArgument(Unknown So
urce)
at b4j/org.apache.commons.exec.CommandLine.addArgument(Unknown Source)

real command line - that works - set diplay monitor at sleep:
B4X:
powershell.exe (Add-Type '[DllImport(\"user32.dll\")]^public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)


*This command set Display-Monitor to sleep...
 
Solution
B4X:
Dim js As Shell
    Dim params As List
    params.Initialize
    Dim mystring As String=$"(Add-Type '[DllImport(\"user32.dll\")]public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)"$
    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)

for me works

teddybear

Well-Known Member
Licensed User
B4X:
powershell.exe (Add-Type '[DllImport(\"user32.dll\")]^public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)


*This command set Display-Monitor to sleep...
You can put the cmdline into a batch file, such as sleep.bat
then use fx.ShowExternalDocument(File.GetUri("Dir", "sleep.bat") to execute it.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
You can put the cmdline into a batch file, such as sleep.bat
then use fx.ShowExternalDocument(File.GetUri("Dir", "sleep.bat") to execute it.
but as i said - i don't want it as batch... for my reasons... (somehow simulating mouse click at some systems)

Powershell Sub with this script-line not working... because at the same line using double quotes and single quotes... so getting different error for Add-Type... but i will create it different... (i will post how)

Thanks to all !!!
 
Upvote 0

XorAndOr

Active Member
Licensed User
Longtime User
B4X:
Dim js As Shell
    Dim params As List
    params.Initialize
    Dim mystring As String=$"(Add-Type '[DllImport(\"user32.dll\")]public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)"$
    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)

for me works
 
Upvote 0
Solution

Magma

Expert
Licensed User
Longtime User
B4X:
Dim js As Shell
    Dim params As List
    params.Initialize
    Dim mystring As String=$"(Add-Type '[DllImport(\"user32.dll\")]public static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)"$
    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)

for me works
Hey that worked...

the difference here is: js.Initialize.... -> js.InitializeDoNotHandleQuotes ... also powershellscript... was replacing double quotes with single - so Add-Type was giving error...
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
1662027702805.png


Also this character "^" removed... but as I see no difference for this script... but if I put it back had error... so I ve removed it... me too :)
 
Upvote 0
Top