ragupta Posted June 12, 2012 Share Posted June 12, 2012 I have a shortcut which trigger powershell.exe with some arguments. After launching this shortcut I need to fire some commands on this window and get the output to make sure if the commands are working fine or not. Let say I have a shorcut icon desctop ... i.e. xyz.lnk When I doble click it launches console with below content ----------- C:\Program Files (x86)\xyz>C:\Windows\System32\windowspowershell\v1.0\powershell.exe -NoExit -ExecutionPolicy RemoteSigned -File .\StartxyzPS.ps1 Windows PowerShell Copyright © 2009 Microsoft Corporation. All rights reserved. PS C:/> --------- I can launch using shellexecute but not sure how to pass commands to it ShellExecute("C:\Users\Public\Desktop\xyz.lnk") Also when I use Run , cmd prompt closes and script exit before I could use stdinwrite function. Local $pid = Run(@ComSpec & " /c " & '"C:\Users\Public\Desktop\xyz.lnk"', "", @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD) Please advise. Link to comment Share on other sites More sharing options...
abberration Posted June 12, 2012 Share Posted June 12, 2012 How about running the program directly? I don't have PowerShell or your OS (I'm on XP), so I can't test this code: shellexecute("C:\Windows\System32\windowspowershell\v1.0\powershell.exe", "-NoExit -ExecutionPolicy RemoteSigned -File .\StartxyzPS.ps1") Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
water Posted June 12, 2012 Share Posted June 12, 2012 (edited) I would too suggest to run the program directly from AutoIt. It's easier to grab the output. This little code snippet shows how I create an Exchange mailbox for a user and check the output to determine if the mailbox was usccessfully created. $sCMD = "C:\Windows\System32\WindowsPowerShellv1.0powershell.exe -command . " & _ "'D:Exchange ServerV14binRemoteExchange.ps1'; Connect-ExchangeServer -auto; Enable-Mailbox -Identity " & _ $Kurzzeichen & " -Alias " & $Kurzzeichen & " -Database " & $sEXDatabase & $sSMTPAddress $PID = Run($sCMD, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD) StdinWrite($PID, @CRLF) StdinWrite($PID) ; Process STDOUT $sSTDOUT = "" While 1 $sOutput = StdoutRead($pid) If @error Then ExitLoop If $sOutput <> "" Then $sSTDOUT = $sSTDOUT & @CRLF & $sOutput WEnd ; Process STDERR $sSTDERR = "" While 1 $sOutput = StdErrRead($pid) If @error Then ExitLoop If $sOutput <> "" Then $sSTDERR = $sSTDERR & @CRLF & $sOutput WEnd Edited June 12, 2012 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now