I don't know how to call powershell script from powerbuilder. Some one please help
Thanks
I don't know how to call powershell script from powerbuilder. Some one please help
Thanks
Just in case you like to use dirty quick work with cmd then following might be useful. This sample code sends email through Powershell.
I suggest the example that Roland Smith talks about is better way.
String psPath = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
Integer li_FileNum
String theCmd
li_FileNum = FileOpen("C:\Temp\cmd.ps1", LineMode!, Write!, LockWrite!, Replace!)
theCmd = "$EmailFrom = ~"" + SendFrom.Text + "~""
FileWrite(li_FileNum, theCmd)
theCmd = "$EmailTo = ~"" + SendTo.Text + "~""
FileWrite(li_FileNum, theCmd)
theCmd = "$Subject = ~""+Subject.Text+"~""
FileWrite(li_FileNum, theCmd)
theCmd = "$Body = ~""+ Msg.Text + "~""
FileWrite(li_FileNum, theCmd)
theCmd = "$SMTPServer = ~"smtp.gmail.com~""
FileWrite(li_FileNum, theCmd)
theCmd = "$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)"
FileWrite(li_FileNum, theCmd)
theCmd = "$SMTPClient.EnableSsl = $true"
FileWrite(li_FileNum, theCmd)
theCmd = "$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(~"fartonheart@gmail.com~", ~"goldplated123~");"
FileWrite(li_FileNum, theCmd)
//theCmd = "$emailattachment = ~"c:\temp\datawindow.pdf~""
//FileWrite(li_FileNum, theCmd)
//
//theCmd = "$attachment = New-Object System.Net.Mail.Attachment($emailattachment, ~'text/plain~')"
//FileWrite(li_FileNum, theCmd)
//
//theCmd = "$Attachments.Add($attachment)"
//FileWrite(li_FileNum, theCmd)
//
theCmd = "$IsBodyHTML = $false"
FileWrite(li_FileNum, theCmd)
theCmd = "$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)"
FileWrite(li_FileNum, theCmd)
FileClose(li_FileNum)
int li_rc
string ls_command
string ls_directory
ls_directory = "C:\temp"
ls_command = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "&'
ls_command += " '" + ls_directory + "\cmd.ps1' "
li_rc = Run ( ls_command, Minimized! )
Run (.....cmd)
The above sudo will run powershell command but not return anything. Run function return 0 or 1. But, we need data that we getting from command.
Detail:-
Run ("powershell.exe -command Set-Location 'C:\'; mkdir .\Test -ea 0; "some command it will return some output json here";)
The above code will create test folder in C drive and get some json data. Here, Ineed json data, but run will return only 0 or 1.
anyone knows how return Json data?
Do a search on that page for "wbemscripting", I'm a noob on this, but it might enable you to run powershell commands?
This might also be interesting: https://stackoverflow.com/questions/64084420/vba-wscript-shell-executing-a-powershell-command
(hopefully).
regards,
MiguelL
You could simple run powershell.exe from PowerBuilder.
e.g.
Run ("powershell.exe -command 'hello';start-sleep 10")
I want read output of
output = Run (cmd..)
I want output. But run will return either 0 or 1.