launch exe files in ps1

Hi all I wanna to know how can I launch a exe file within a powershell 
script, for instances I have this function in a script:

Function edit($file){
	$program = 'd:\Program Files (x86)\PowerGUI\ScriptEditor.exe';
	$psi= New-Object System.Diagnostics.ProcessStartInfo;
	$sb = New-Object System.Text.StringBuilder;
	$sb.Append("'");
	$sb.Append($((Get-ChildItem $file).FullName));
	$sb.Append("'");
	$psi.Arguments = $sb.Tostring();
	$psi.FileName = $program;
	[System.Diagnostics.Process]::Start($psi);

}

that is an incredible work and with errors (doesn't find the file to edit, 
so always powergui offers me to create new file) for something that directly 
in powershell can be done like this:
& 'D:\Program Files (x86)\PowerGUI\ScriptEditor.exe' $((gci 
..\FiletoEdit.ps1).FullName)

How can I do that in a ps1 file?


-- 
Michael Soza
Estudiante Ingenier�a Civil Inform�tica
Universidad de Concepci�n 

0
Michael
11/26/2009 4:58:34 PM
windows.powershell 690 articles. 0 followers. Follow

3 Replies
1204 Views

Similar Articles

[PageSpeed] 8

Your right that is a fair amount of typing but at least you got to learn some 
of the .NET types which can be useful.

However you've lost me on what you want. Both your function "edit" as well 
as your use of the call operator on PowerGUI's editor can be used ins a .PS1 
file without modification.

If you're looking for alternate methods my I suggest you get quite familar 
with all the help Powershell provides you.

Get-Help
Get-Type
Get-Member

and of course

Get-Command

which is what I'm using here.

Since you want to start a process you could either search for all cmdlets 
that have the "verb":  Start,  the "noun":  Process or some derivative of 
these. Get-Verb will show all the available verbs.

In either case here Get-Command will print out Start-Process. So to open 
either a new script or existing script its as simple as 

Start-Process notepad.exe foo.ps1

for an existing file that has an association  its even simpiler

Invoke-Item foo.ps1

bob

"Michael Soza" wrote:

> Hi all I wanna to know how can I launch a exe file within a powershell 
> script, for instances I have this function in a script:
> 
> Function edit($file){
> 	$program = 'd:\Program Files (x86)\PowerGUI\ScriptEditor.exe';
> 	$psi= New-Object System.Diagnostics.ProcessStartInfo;
> 	$sb = New-Object System.Text.StringBuilder;
> 	$sb.Append("'");
> 	$sb.Append($((Get-ChildItem $file).FullName));
> 	$sb.Append("'");
> 	$psi.Arguments = $sb.Tostring();
> 	$psi.FileName = $program;
> 	[System.Diagnostics.Process]::Start($psi);
> 
> }
> 
> that is an incredible work and with errors (doesn't find the file to edit, 
> so always powergui offers me to create new file) for something that directly 
> in powershell can be done like this:
> & 'D:\Program Files (x86)\PowerGUI\ScriptEditor.exe' $((gci 
> ..\FiletoEdit.ps1).FullName)
> 
> How can I do that in a ps1 file?
> 
> 
> -- 
> Michael Soza
> Estudiante Ingeniería Civil Informática
> Universidad de Concepción 
> 
> .
> 
0
Utf
11/29/2009 6:25:01 PM
Thanks Bob, I didn't know how to invoke exe files,  because if a enclosed 
them in quotes they become strings and if not and the path to the file 
contains spaces then the exe file is not found.
I did a search till I found the answer, I can use the cmdlet that you 
mention but there is a special keyword for that purpose - The & keyword!!!
Examples:
& {block of sentences}   ...Executes the block of sentences
& script.ps1  ...Executes the script
& "some exe file in a directory with spaces in the path"  ...executes the 
exe file

And my Edit Function is now a lot more simple and works always :).
Function edit($file){
	$program = 'd:\Program Files (x86)\PowerGUI\ScriptEditor.exe';
	& $program (gci $file).FullName}

Regards
Michael Soza.

"Bob Landau" <BobLandau@discussions.microsoft.com> wrote in message 
news:4965AB07-DEA3-4DFC-81AA-1DAC87F79241@microsoft.com...
> Your right that is a fair amount of typing but at least you got to learn 
> some
> of the .NET types which can be useful.
>
> However you've lost me on what you want. Both your function "edit" as well
> as your use of the call operator on PowerGUI's editor can be used ins a 
> .PS1
> file without modification.
>
> If you're looking for alternate methods my I suggest you get quite familar
> with all the help Powershell provides you.
>
> Get-Help
> Get-Type
> Get-Member
>
> and of course
>
> Get-Command
>
> which is what I'm using here.
>
> Since you want to start a process you could either search for all cmdlets
> that have the "verb":  Start,  the "noun":  Process or some derivative of
> these. Get-Verb will show all the available verbs.
>
> In either case here Get-Command will print out Start-Process. So to open
> either a new script or existing script its as simple as
>
> Start-Process notepad.exe foo.ps1
>
> for an existing file that has an association  its even simpiler
>
> Invoke-Item foo.ps1
>
> bob
>
> "Michael Soza" wrote:
>
>> Hi all I wanna to know how can I launch a exe file within a powershell
>> script, for instances I have this function in a script:
>>
>> Function edit($file){
>> $program = 'd:\Program Files (x86)\PowerGUI\ScriptEditor.exe';
>> $psi= New-Object System.Diagnostics.ProcessStartInfo;
>> $sb = New-Object System.Text.StringBuilder;
>> $sb.Append("'");
>> $sb.Append($((Get-ChildItem $file).FullName));
>> $sb.Append("'");
>> $psi.Arguments = $sb.Tostring();
>> $psi.FileName = $program;
>> [System.Diagnostics.Process]::Start($psi);
>>
>> }
>>
>> that is an incredible work and with errors (doesn't find the file to 
>> edit,
>> so always powergui offers me to create new file) for something that 
>> directly
>> in powershell can be done like this:
>> & 'D:\Program Files (x86)\PowerGUI\ScriptEditor.exe' $((gci
>> ..\FiletoEdit.ps1).FullName)
>>
>> How can I do that in a ps1 file?
>>
>>
>> -- 
>> Michael Soza
>> Estudiante Ingeniería Civil Informática
>> Universidad de Concepción
>>
>> .
>> 
0
Michael
12/1/2009 3:32:28 PM
Hi Michael,

little bit late, however do you know there is cmdlet Start-Process (alias 
Start)??

Martin

"Michael Soza" <voodoomsr@hotmail.com> wrote in message 
news:BF8530F5-6A9B-4206-A68F-5E12A52CECB1@microsoft.com...
> Thanks Bob, I didn't know how to invoke exe files,  because if a enclosed 
> them in quotes they become strings and if not and the path to the file 
> contains spaces then the exe file is not found.
> I did a search till I found the answer, I can use the cmdlet that you 
> mention but there is a special keyword for that purpose - The & keyword!!!
> Examples:
> & {block of sentences}   ...Executes the block of sentences
> & script.ps1  ...Executes the script
> & "some exe file in a directory with spaces in the path"  ...executes the 
> exe file
>
> And my Edit Function is now a lot more simple and works always :).
> Function edit($file){
> $program = 'd:\Program Files (x86)\PowerGUI\ScriptEditor.exe';
> & $program (gci $file).FullName}
>
> Regards
> Michael Soza.
>
> "Bob Landau" <BobLandau@discussions.microsoft.com> wrote in message 
> news:4965AB07-DEA3-4DFC-81AA-1DAC87F79241@microsoft.com...
>> Your right that is a fair amount of typing but at least you got to learn 
>> some
>> of the .NET types which can be useful.
>>
>> However you've lost me on what you want. Both your function "edit" as 
>> well
>> as your use of the call operator on PowerGUI's editor can be used ins a 
>> .PS1
>> file without modification.
>>
>> If you're looking for alternate methods my I suggest you get quite 
>> familar
>> with all the help Powershell provides you.
>>
>> Get-Help
>> Get-Type
>> Get-Member
>>
>> and of course
>>
>> Get-Command
>>
>> which is what I'm using here.
>>
>> Since you want to start a process you could either search for all cmdlets
>> that have the "verb":  Start,  the "noun":  Process or some derivative of
>> these. Get-Verb will show all the available verbs.
>>
>> In either case here Get-Command will print out Start-Process. So to open
>> either a new script or existing script its as simple as
>>
>> Start-Process notepad.exe foo.ps1
>>
>> for an existing file that has an association  its even simpiler
>>
>> Invoke-Item foo.ps1
>>
>> bob
>>
>> "Michael Soza" wrote:
>>
>>> Hi all I wanna to know how can I launch a exe file within a powershell
>>> script, for instances I have this function in a script:
>>>
>>> Function edit($file){
>>> $program = 'd:\Program Files (x86)\PowerGUI\ScriptEditor.exe';
>>> $psi= New-Object System.Diagnostics.ProcessStartInfo;
>>> $sb = New-Object System.Text.StringBuilder;
>>> $sb.Append("'");
>>> $sb.Append($((Get-ChildItem $file).FullName));
>>> $sb.Append("'");
>>> $psi.Arguments = $sb.Tostring();
>>> $psi.FileName = $program;
>>> [System.Diagnostics.Process]::Start($psi);
>>>
>>> }
>>>
>>> that is an incredible work and with errors (doesn't find the file to 
>>> edit,
>>> so always powergui offers me to create new file) for something that 
>>> directly
>>> in powershell can be done like this:
>>> & 'D:\Program Files (x86)\PowerGUI\ScriptEditor.exe' $((gci
>>> ..\FiletoEdit.ps1).FullName)
>>>
>>> How can I do that in a ps1 file?
>>>
>>>
>>> -- 
>>> Michael Soza
>>> Estudiante Ingeniería Civil Informática
>>> Universidad de Concepción
>>>
>>> .
>>> 
0
Martin
12/2/2009 9:11:05 AM
Reply:

Similar Artilces:

Appending a second csv file
I have been working with importing a csv file into excel and then saving the output as a prn file that we will use for uploading. My next challenge is to append at the end of this Excel file (before saving as a prn) with a second file that will have different fixed length requirements than the original import. The second file will consist of a single row but again the fixed length requirements are different than the original import. Any ideas how to automate this or since it is a single row should we just input manually? Any advice? Record it once as a macro, put a button on the...

Toolbar macros, Personal.xls and the .xlb file
Several of my toolbar buttons are associated with macros. Whenever I update the toolbars I copy my .xlb file to the other 2 or 3 machines I work on. However my Personal.xls file is not located in the same folder on each machine. Consequently after copying the new .xlb file across to the other machines, I have to re-point each button to the correct macro. Is there an easier way of doing this - eg. with some specific macro? Your life will become much simpler if you include code to create the toolbar when the workbook is opened and include code to destroy the toolbar when the workbook is closed...

File combination help~!
some rules about combining data in my mind'eye are below,because Englis isn't my native language,if you feel puzzle about something inside,o something incorrect,please make me know. 1.From the steps above,we have uniformed all the data files we hav collected in a given market,into a given formation,and we put them in a forlder together. 2.Assuming that we have three data files,which are name file1,file2,and file3. 3.each raw of data(raw-data for short) is composed of seve data:date(D),Open price(O),high price (H),low price(L),close price(C),volumn(V),open interest(OI),an tag...

*.csv file question
Question : I have *.csv file that contains data I would like to chart using MS Excel . The data in the *.csv file is updated by another window every minute for a period of 7 hours. If I load the *.csv file into Excel my chart will be current for only one minute. Is it possible to reload the same *.csv file one minute later and have an updated chart and will this present a possible conflict with the other window if I load the file at the same time the other window is updating the data ? On Fri, 1 Oct 2004 12:48:21 -0600, "Rob" <rls_jls@worldnet.att.net> wrote: Have a loo...

vbs script to list files in a directory and email results
Hi. Been trying to write something with out any luck. Im looking for a script that will look in a given directory (i.e. c:\mydata) and e-mail details of what files are in that directory, the details needed are file names, date modified and size. Anyone got any sample scripts ? Thanks "systemtek" <duncan@systemtek.co.uk> wrote in message news:8c076e3d-9231-452b-8700-fd6227eb9bc8@y12g2000vbg.googlegroups.com... > Hi. > > Been trying to write something with out any luck. Im looking for a > script that will look in a given directory (i.e. c:\...

Outlook.exe will not close
When I try to log off in Windows XP (I have several users set up with me as administrator), outlook.exe will not automatically close. A timer window will appear. I either have to click it off manually or wait for it to time itself off before it will go to the users desktop. This happens when I have opened Outlook and after I have manually closed the program. If I never accessed when I was logged on I do not have the problem. How do I get Outlook.exe to close automatically when I log off in Windows XP? .. Thomas Wrote: > When I try to log off in Windows XP (I have several use...

Publisher-Inserting a file
I am using MS Windows XP Home and MS Office 2003-Pro Publisher 2003. After having a crash where I had to use the switch in back to shut down, I have been unable to insert any files into a publisher page. I keep getting a notice that "MicroSoft has encounted a problem and must close. Send report, which I have done. This hasn't corrected the proble and I need to be able to insert some files from scanning and change their color to black and reduce the brightness to use as a watermark. Can someone please tell me how to correct this problem? Thanks "MOE" Hi MOE (searchno...

Address book file location?
This is a multi-part message in MIME format. ------=_NextPart_000_000A_01C35E79.184CB580 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Where is the address book file located in Outlook 2000? I am trying to = make a backup onto a cd and cannot locate it... ------=_NextPart_000_000A_01C35E79.184CB580 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type...

Inserting a file "link" in outlook 2002
Having an issue trying to insert a link (not a hyperlink, don't want users to know the path to the file) into a post, which is directed out to a file on a server. These posts that were previously created were done in exchange, which we were able to insert a shortcut which was only a shorcut and it open the version of the file that is on the server. Now....having upgraded to XP and now on outlook 2002 we are unable to do this. When inserting a file you do not have to option to insert as a link, it inserts the whole entire file. It needs to be just be a shortcut as when they ma...

Sorting PO.XML and PORCV.XML File
Is it possible to set how the Po.xml and porcv.xml files are sorted? I know they will sort based on how the Items are sorted in the contents tab, The problem I am having is that I need to sort based on the BinLocation and it is not one of the fields on the Contents tab. Any Ideas? Thanks, Butch This is a multi-part message in MIME format. ------=_NextPart_000_0619_01C75557.A2B44F70 Content-Type: multipart/alternative; boundary="----=_NextPart_001_061A_01C75557.A2B44F70" ------=_NextPart_001_061A_01C75557.A2B44F70 Content-Type: text/plain; charset="iso-8859-1" Cont...

"unexpected file format" error when opening an attachment
Outlook 2003 sp2. When I try to open the attachment from the same person, it seems that label factory tries to open it. ...

Need sberet.msi file after installing SP-3.
After downloading SP-3 for Microsoft Office 2002, when installing updates to Xcel a message asking me to insert my MS office Small buisness disc because iy can't find a sberet,msi file. My Dell PC came already loaded wiht the SBE and I have no discs. Word, Powerpoint & Publisher updated fine. Why not Xcel. What do I do now. Don't tell me to call Dell a/c they do not supply discs on older versions. ...

MnyBank : Ofc Ofx file conversion and Money import (V1.5.17)
Version 1.5.17 - Batch file conversion from CSV, QIF, OFC, OFX V1, OFX V2 (xml) to OFX V1, OFX V2 (xml), Excel (xml), - Demo at http://ferraroa.dyndns.org:8200/MnyBank/help/ with online conversion from OFC, OFX V1, OFX V2 (xml) to OFX V1, OFX V2 (xml), Excel (xml). A test file can be downloaded from the web not to use private data for testing. Version 1.5.16 : - Can save data into Excel Xml files (File/Save As) - Setting wizard in french and english - New link : http://ferraroa.dyndns.org:8200/MnyBank/bin/MnyBank.zip Version 1.5.12 : english help file and documentation (except...

Cannot open long file names
Weird glitch when upgrading Win 98 machine to XPPro - Excel will now not open any file name with 27 characters (not including the '.xls suffix') or longer. The error message asks to check file location & spelling. If filename is shortened to 26 characters or less - opens fine. However, after a Excel 97 reinstall, a long file name opened (1st file opened) but excel returned an error along the lines of 'you cannot open more than 1 file with the same name at a time' & on trying to open another long file name, the same error as above. These 'long files' open okay ...

Generate multiple ACH Files (NACHA files) based on routing numbers
We are using GP 9.0 with Direct Deposit Module. We would like to find if there a way in GP to Generate multiple ACH Files (NACHA files) based on routing numbers setup for employee's in Great Plains. We are currently setup to generate 1 ACH file per company. Customer support response was that there is no solution in any version of GP. If someone can of any assistance with this request, it would be great appreciated. Thanks. Azfar Azfar, You could write a VBScript or VB program that will take the output file and split it in multiple files based on routing number. This should be...

signature file
I want to know if you can setup multiple users on the server so that when they send an email. They would see a message going out for example: This email is stricly private, if it is not yours please disreguard thanks "test123" <anonymous@discussions.microsoft.com> wrote: >I want to know if you can setup multiple users on the >server so that when they send an email. They would see a >message going out for example: This email is stricly >private, if it is not yours please disreguard > >thanks It generally needs to be a blanket implementation and ht...

Importing a .dat file into IM
Does anyone know of a tool I can use to clean and rename a .dat file to .txt file for an IM import. I think I can just use DTS or VB Script to automated that process.. If anyone has some advise for me that would ideal.. You can use the ABC Amber Agent Converter to do a bunch of file conversions between different formats http://www.processtext.com/abcagent.html Best regards, -- MG.- Mariano Gomez, MIS, MCP, PMP Maximum Global Business, LLC http://www.maximumglobalbusiness.com "adatasys" wrote: > Does anyone know of a tool I can use to clean and rename a .dat file to .txt ...

The converter failed to save the file
I'm trying to use the PowerPoint Viewer 2007 to open a sample pptx file made with PowerPoint 2007. I have installed FileFormatConverters.exe as well. When I try to open the file, a prompt with "Save As" in the title bar and "The converter failed to save the file." in the text appears. I can open PowerPoint 2003 files without any trouble. Any ideas? Thanks, The PPT 2007 Viewer actually includes the compatibilty pack -- that's why the installer is, like, 25MB. (The compat pack is FileFormatConverters.exe.) So you should have the compat pack once with ...

can dbx files be deleted safely
trying free up some space can i safely delete all dbx files ..DBX files are used by Outlook Express. If you're absolutely sure you don't need any of your old OE information (mail and news), you can probably delete those files. You might want to send them to the Recycle Bin for a few days first to make sure you don't need them before you permanently delete them. -- Jocelyn Fiorello MVP - Outlook *** Messages sent to my e-mail address will NOT be answered -- please reply only to the newsgroup to preserve the message thread. *** In news:74d401c3eb38$df443130$7d02280a@phx.gbl, ...

Can't open files from a different version saved to 2000 format
Hi, I am having problems opening a file sent to me by someone using Publisher 2003. I have Publisher 2000. She saved to the 2000 format, but it says that I cannot open files from a different version. The document shows up in the preview area, but will not open. She even tried to save it to the 98 format, but it still will not open. Any ideas? Julie wrote: > Hi, > > I am having problems opening a file sent to me by someone using > Publisher 2003. I have Publisher 2000. She saved to the 2000 format, > but it says that I cannot open files from a different version. The > d...

Open Files, perform action - fails
The following code casues an application defined error and I need hel understanding why. The code for finding the word "closed" in column works fine in a worksheet all by itself. And the code that reads file list from a directory works fine by itself. However, the tw together seem not to behave together...Any thoughts???? Sub OpenWorkbooksInLocation() Application.ScreenUpdating = True 'to see whats happening Dim i As Integer With Application.FileSearch 'find files .NewSearch .LookIn = "C:\Test" 'Amend to suit .SearchSubFolders = False .Filename = "...

Form size and Global.js file in the CRM or SFA's .JS
In 3.0 I used the .JS to control individual form sizes. Can this still be done on 4.0 as I have used some other on-open methods and the form size is seen to open and reset each time which is a little slow and 'untidy'. If so does anyone have a sample script? ...

n2k file
Is it possible to move/export the nickname file (that auto completes addresses) to another system and have it function? Is it possible to edit the file and eliminate addresses that autocomplete? Dave <pillwintek@yahoo.com> wrote: > Is it possible to move/export the nickname file (that auto > completes addresses) to another system and have it > function? If you place it in the proper folder and giv it the proper name, probably. > Is it possible to edit the file and eliminate addresses > that autocomplete? Only within Outlook by highlighting the suggestion and press...

Opening Word files
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: Power PC I am having trouble opening docx files that I have previously saved &amp; opened. Every time I try to open I get a box saing &quot;The open XML file canot be opened because there are problems with the contents. <br> Details <br> Unspecified Error <br> Location: 2 Apply all the latest updates to OS X and Microsoft Office. You have not specified your version levels, and that's the first step. Cheers On 2/03/10 12:08 PM, in article 59bb3b20.-1@webcrossing.JaKIaxP2ac0, "M...

Unable to see files in folders
When I try to find a file that I know is in a folder, I don't see it. When I do a search, it shows up. Do I have something checked wrong that does not allow me to see certain files. They are .jpg files that I put in the folders. -- Dick Sorry Dick: You have not given enough information for us to answer. We need to know your OS version and level (e.g. OS 10.4.10) and "how" you are trying to see the files (in which application? The Finder?) On 4/09/07 4:00 AM, in article D6CDEEAC-922C-4DB3-8363-10EB6FCF8907@microsoft.com, "Dick" <Dick@discussions.microso...