Running Powershell With PHP On IIS -


php code -:

<?php      $user = "email@outlook.com";      $script = "c:\\inetpub\\wwwroot\\shell_script\\sc.ps1";      $query = shell_exec("powershell -command $script <nul");      if($query) {    echo "successful" ; } else    echo "failed"; } ?> 

powershell code -:

$outlook = new-object -comobject outlook.application $mail = $outlook.createitem(0)  $mail.to = "email2@outlook.com" $mail.subject = "new leave request" $mail.body =" dear,  email contains body of email"  $mail.send() 

i have powershell installed on laptop windows server 2012 on windows 8.

i have website hosted on windows server 2012 iis

when run powershell script sc.ps1 on command line on server command ./sc.ps1 mail sent outlook.

but when run php page in have shell_exec command mail not triggered outlook , returns page message successful written in php code. work done on windows server 2012

running powershell script on command line sends mail when running script via powershell doesn't trigger mail , returns successful shell-exec query running.

i have done set-executionpolicy unrestricted .

microsoft not recommend, , not support, automation of microsoft office applications unattended, non-interactive client application or component (including asp, asp.net, dcom, , nt services), because office may exhibit unstable behavior and/or deadlock when office run in environment.

if building solution runs in server-side context, should try use components have been made safe unattended execution. or, should try find alternatives allow @ least part of code run client-side. if use office application server-side solution, application lack many of necessary capabilities run successfully. additionally, taking risks stability of overall solution. read more in considerations server-side automation of office article in msdn.

as workaround may use low-level api - extended mapi supports such scenarious, or other third-party wrapper around api (for example, redemption).


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -