Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Stupid [Diagnostics.Process]::Start("..") tricks

Reply
 
Old 08-10-2006   #1 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Stupid [Diagnostics.Process]::Start("..") tricks

I use [System.Diagnostics.Process]::Start("...") a lot since it can do
everything the Start | Run dialog does. Combined with PowerShell's variable
expansion, it can also be very useful for accessing specific web pages
quickly. Here's a quick collection of some of the things you can do with it
for people who haven't worked with it before.

Currently I use the following function and alias to simplify things even
further:
function Start-Process
{
Param([string]$name)
[System.Diagnostics.Process]::Start("$name")
}
Set-Alias saps Start-Process


+ Using well-known names
You can open the fonts folder with
Start-Process fonts
You can open the control panel with
Start-Process control


+ Using App Paths
Applications with a registered app path can be invoked by name. For example,
at a command prompt or PowerShell prompt, you can't directly type 'winword'
or 'winword.exe' to start Microsoft Word. However, the shell execution
process checks app paths, so you can do this:
saps winword
Note that you do get back a process reference which can be used elsewhere.


+ Opening URLs
Start-Process http://www.google.com


+ Accelerated subdomain access
Since I always have a PowerShell window open, I find it's faster to use an
accelerator function rather than open IE, wait for it to be ready, then type
in a subdomain name and let it search. I have several subdomain accelerator
functions; here's the one for .com domains:
function htc
{
Param([string]$subdomain)
$ps = [System.Diagnostics.Process]
$ps::Start("http://www.$subdomain.com");
}

This lets me do
htc google
htc microsoft


+ Getting an MSKB article by ID
function Get-Mskb
{
Param([string]$kbid)
$ps = [System.Diagnostics.Process]
$ps::Start("http://support.microsoft.com/kb/$kbid");
}
Now you can do this:
Get-Mskb 123456


+ Getting a Security Bulletin by ID
Similarly to the above:
function Get-Msb
{
Param([string]$MsbId)
$MsbBaseUrl =
"http://www.microsoft.com/technet/security/bulletin/MS"
$ps = [System.Diagnostics.Process]
$ps::Start("$MsbBaseUrl$MsbId.mspx");
}

This allows you to quickly enter a Microsoft Security Bulletin by entering
it's ID. Note that you currently do need to have the leading zeros in place.
Get-Msb 06-001


+ Accessing a Wiki page - culture correct!
I use wikipedia.org regularly. There are several distinct languages used,
and the server name is unique for each language family. Since Wikipedia uses
the standard 2-letter ISO language names, this is very easy to include in a
function.

function Get-Wiki
{
Param([string]$WikiWord,
$culture = (Get-UICulture).TwoLetterISOLanguageName)
$WikiUrlBase = "http://$culture.wikipedia.org/wiki/"
$ps = [System.Diagnostics.Process]
$ps::Start("$WikiUrlBase$WikiWord");
}
This lets me do this:
Get-Wiki solipsism

Ah, but what if you're on an English language computer and want to get a
_French_ Wiki page?
That's what the -Culture parameter is for:

Get-Wiki -Culture:fr Wiktionnaire

Note that you can get a complete listing of the 2-letter ISO codes like
this:

[System.Globalization.CultureInfo]::GetCultures("AllCultures") |
ft -AutoSize -Property TwoLetterISOLanguageName,DisplayName



My System SpecsSystem Spec
Old 08-10-2006   #2 (permalink)
Abhishek Agrawal [MSFT]


 
 

Re: Stupid [Diagnostics.Process]::Start("..") tricks

This is very cool. This is going into my profile

--
Abhishek Agrawal [MSFT]
Windows PowerShell Team
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

"Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message
news:Os7JS1HvGHA.5092@TK2MSFTNGP05.phx.gbl...
>I use [System.Diagnostics.Process]::Start("...") a lot since it can do
>everything the Start | Run dialog does. Combined with PowerShell's variable
>expansion, it can also be very useful for accessing specific web pages
>quickly. Here's a quick collection of some of the things you can do with it
>for people who haven't worked with it before.
>
> Currently I use the following function and alias to simplify things even
> further:
> function Start-Process
> {
> Param([string]$name)
> [System.Diagnostics.Process]::Start("$name")
> }
> Set-Alias saps Start-Process
>
>
> + Using well-known names
> You can open the fonts folder with
> Start-Process fonts
> You can open the control panel with
> Start-Process control
>
>
> + Using App Paths
> Applications with a registered app path can be invoked by name. For
> example, at a command prompt or PowerShell prompt, you can't directly type
> 'winword' or 'winword.exe' to start Microsoft Word. However, the shell
> execution process checks app paths, so you can do this:
> saps winword
> Note that you do get back a process reference which can be used elsewhere.
>
>
> + Opening URLs
> Start-Process http://www.google.com
>
>
> + Accelerated subdomain access
> Since I always have a PowerShell window open, I find it's faster to use an
> accelerator function rather than open IE, wait for it to be ready, then
> type in a subdomain name and let it search. I have several subdomain
> accelerator functions; here's the one for .com domains:
> function htc
> {
> Param([string]$subdomain)
> $ps = [System.Diagnostics.Process]
> $ps::Start("http://www.$subdomain.com");
> }
>
> This lets me do
> htc google
> htc microsoft
>
>
> + Getting an MSKB article by ID
> function Get-Mskb
> {
> Param([string]$kbid)
> $ps = [System.Diagnostics.Process]
> $ps::Start("http://support.microsoft.com/kb/$kbid");
> }
> Now you can do this:
> Get-Mskb 123456
>
>
> + Getting a Security Bulletin by ID
> Similarly to the above:
> function Get-Msb
> {
> Param([string]$MsbId)
> $MsbBaseUrl =
> "http://www.microsoft.com/technet/security/bulletin/MS"
> $ps = [System.Diagnostics.Process]
> $ps::Start("$MsbBaseUrl$MsbId.mspx");
> }
>
> This allows you to quickly enter a Microsoft Security Bulletin by entering
> it's ID. Note that you currently do need to have the leading zeros in
> place.
> Get-Msb 06-001
>
>
> + Accessing a Wiki page - culture correct!
> I use wikipedia.org regularly. There are several distinct languages used,
> and the server name is unique for each language family. Since Wikipedia
> uses the standard 2-letter ISO language names, this is very easy to
> include in a function.
>
> function Get-Wiki
> {
> Param([string]$WikiWord,
> $culture = (Get-UICulture).TwoLetterISOLanguageName)
> $WikiUrlBase = "http://$culture.wikipedia.org/wiki/"
> $ps = [System.Diagnostics.Process]
> $ps::Start("$WikiUrlBase$WikiWord");
> }
> This lets me do this:
> Get-Wiki solipsism
>
> Ah, but what if you're on an English language computer and want to get a
> _French_ Wiki page?
> That's what the -Culture parameter is for:
>
> Get-Wiki -Culture:fr Wiktionnaire
>
> Note that you can get a complete listing of the 2-letter ISO codes like
> this:
>
> [System.Globalization.CultureInfo]::GetCultures("AllCultures") |
> ft -AutoSize -Property TwoLetterISOLanguageName,DisplayName
>
>



My System SpecsSystem Spec
Old 08-10-2006   #3 (permalink)
=?iso-8859-1?Q?Maximilian_H=E4nel?=


 
 

Re: Stupid [Diagnostics.Process]::Start("..") tricks

Hi Alex K.

very cool!

> + Using well-known names
> You can open the fonts folder with
> Start-Process fonts
> You can open the control panel with
> Start-Process control


Do you know a (complete) list for the well known names in Inet?

tia

Max
My System SpecsSystem Spec
Old 08-11-2006   #4 (permalink)
Marty List


 
 

Re: Stupid [Diagnostics.Process]::Start("..") tricks


Very nice. I have similar functions configured, but I'll definitely be
stealing these two from you:

Get-Mskb
Get-Mssb


"Alex K. Angelopoulos [MVP]" <aka@online.mvps.org> wrote in message
news:Os7JS1HvGHA.5092@TK2MSFTNGP05.phx.gbl...
>I use [System.Diagnostics.Process]::Start("...") a lot since it can do
>everything the Start | Run dialog does. Combined with PowerShell's variable
>expansion, it can also be very useful for accessing specific web pages
>quickly. Here's a quick collection of some of the things you can do with it
>for people who haven't worked with it before.
>
> Currently I use the following function and alias to simplify things even
> further:
> function Start-Process
> {
> Param([string]$name)
> [System.Diagnostics.Process]::Start("$name")
> }
> Set-Alias saps Start-Process
>
>
> + Using well-known names
> You can open the fonts folder with
> Start-Process fonts
> You can open the control panel with
> Start-Process control
>
>
> + Using App Paths
> Applications with a registered app path can be invoked by name. For
> example, at a command prompt or PowerShell prompt, you can't directly type
> 'winword' or 'winword.exe' to start Microsoft Word. However, the shell
> execution process checks app paths, so you can do this:
> saps winword
> Note that you do get back a process reference which can be used elsewhere.
>
>
> + Opening URLs
> Start-Process http://www.google.com
>
>
> + Accelerated subdomain access
> Since I always have a PowerShell window open, I find it's faster to use an
> accelerator function rather than open IE, wait for it to be ready, then
> type in a subdomain name and let it search. I have several subdomain
> accelerator functions; here's the one for .com domains:
> function htc
> {
> Param([string]$subdomain)
> $ps = [System.Diagnostics.Process]
> $ps::Start("http://www.$subdomain.com");
> }
>
> This lets me do
> htc google
> htc microsoft
>
>
> + Getting an MSKB article by ID
> function Get-Mskb
> {
> Param([string]$kbid)
> $ps = [System.Diagnostics.Process]
> $ps::Start("http://support.microsoft.com/kb/$kbid");
> }
> Now you can do this:
> Get-Mskb 123456
>
>
> + Getting a Security Bulletin by ID
> Similarly to the above:
> function Get-Msb
> {
> Param([string]$MsbId)
> $MsbBaseUrl =
> "http://www.microsoft.com/technet/security/bulletin/MS"
> $ps = [System.Diagnostics.Process]
> $ps::Start("$MsbBaseUrl$MsbId.mspx");
> }
>
> This allows you to quickly enter a Microsoft Security Bulletin by entering
> it's ID. Note that you currently do need to have the leading zeros in
> place.
> Get-Msb 06-001
>
>
> + Accessing a Wiki page - culture correct!
> I use wikipedia.org regularly. There are several distinct languages used,
> and the server name is unique for each language family. Since Wikipedia
> uses the standard 2-letter ISO language names, this is very easy to
> include in a function.
>
> function Get-Wiki
> {
> Param([string]$WikiWord,
> $culture = (Get-UICulture).TwoLetterISOLanguageName)
> $WikiUrlBase = "http://$culture.wikipedia.org/wiki/"
> $ps = [System.Diagnostics.Process]
> $ps::Start("$WikiUrlBase$WikiWord");
> }
> This lets me do this:
> Get-Wiki solipsism
>
> Ah, but what if you're on an English language computer and want to get a
> _French_ Wiki page?
> That's what the -Culture parameter is for:
>
> Get-Wiki -Culture:fr Wiktionnaire
>
> Note that you can get a complete listing of the 2-letter ISO codes like
> this:
>
> [System.Globalization.CultureInfo]::GetCultures("AllCultures") |
> ft -AutoSize -Property TwoLetterISOLanguageName,DisplayName
>
>



My System SpecsSystem Spec
Old 08-11-2006   #5 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: Stupid [Diagnostics.Process]::Start("..") tricks

"Maximilian Hänel" <ngSpam@smjh.de> wrote in message
news:%23ATmo4KvGHA.1772@TK2MSFTNGP06.phx.gbl...
> Hi Alex K.
>
> very cool!
>
>> + Using well-known names
>> You can open the fonts folder with
>> Start-Process fonts
>> You can open the control panel with
>> Start-Process control

>
> Do you know a (complete) list for the well known names in Inet?


Actually, what I said about well-known names is wrong - it turns out that
the fonts launch is based on finding the folder named Fonts, and when using
"control" we launch control.exe from the search path.

For well-known Internet names, I'm not quite certain what you mean. Can you
explain more?


My System SpecsSystem Spec
Old 08-11-2006   #6 (permalink)
=?iso-8859-1?Q?Maximilian_H=E4nel?=


 
 

Re: Stupid [Diagnostics.Process]::Start("..") tricks

Hi Alex,

> Actually, what I said about well-known names is wrong - it turns out
> that the fonts launch is based on finding the folder named Fonts, and
> when using "control" we launch control.exe from the search path.


Very interesting! I wasn't aware of control.exe :-0
Does there exist an analogue exe for invoking the explorer view where
the Eventlog, Services etc. icons reside? In German this view is called
"Verwaltung". Not sure how it's called on English Systems :-(

> For well-known Internet names, I'm not quite certain what you mean.
> Can
> you explain more?


What I wanted to say is, whether you know a link where I can read more
about those well-known names.
But if well-known names do not exist it's unnecessary to ask for a link
;-)

cu

Max

My System SpecsSystem Spec
Old 08-11-2006   #7 (permalink)
=?Utf-8?B?Um9tYW4gS3V6bWlu?=


 
 

RE: Stupid [Diagnostics.Process]::Start("..") tricks

Nice. My two cents. The script below demonstrates how to:

*) start a process with arguments
*) wait for a process exit (BTW, you can specify timeout value)
*) view/edit some text in Notepad

--- 8< ---

## Edit-Text.ps1
## Edits text input in Notepad and returns modified text
## Usage: [ <text> | ] Edit-Text

end
{
$file = [System.IO.Path]::GetTempFileName()
$input | Set-Content $file
$ps = [System.Diagnostics.Process]::Start("notepad", "`"$file`"")
$ps.WaitForExit()
Get-Content $file
Remove-Item $file
}

--- 8< ---

--
Thanks,
Roman

My System SpecsSystem Spec
Old 08-11-2006   #8 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: Stupid [Diagnostics.Process]::Start("..") tricks

"Maximilian Hänel" <ngSpam@smjh.de> wrote in message
news:%23bOUtmVvGHA.1284@TK2MSFTNGP05.phx.gbl...
> Hi Alex,


> Very interesting! I wasn't aware of control.exe :-0
> Does there exist an analogue exe for invoking the explorer view where the
> Eventlog, Services etc. icons reside? In German this view is called
> "Verwaltung". Not sure how it's called on English Systems :-(


I'm not sure about the particular view you mean, unless you're talking about
the (in English) Computer Management console, normally located at
%SystemRoot%\system32\compmgmt.msc. For that, you could use
Start-Process compmgmt.msc

> But if well-known names do not exist it's unnecessary to ask for a link
> ;-)


I was actually thinking about shell namespace extensions, and had assumed
that you could invoke them this way. It turns out you _can_ invoke some of
them via their 'path'. The path is a GUID for the magic namespaces such as
Network Connections, etc. Here's how I normally find them:

$sa = New-Object -ComObject Shell.Application
0..255 | %{$sa.Namespace($_).Self} | ft Name,Path -AutoSize -Wrap

This just uses the Shell.Application NameSpace() method that accepts a
virtual directory identifier (which must be in the 0-255 range). Microsoft
only uses about 50-60 of these on XP. Some information about shell
namespaces is here on MSDN, although it may not be useful:
http://windowssdk.msdn.microsoft.com.../ms538005.aspx

The important thing is that you can use the path information as an argument
to Start-Process to start the named view. The GUIDs generally need to be
quoted. Here are the examples from my system - lines will be wrapped!

Start-Process '::{871C5380-42A0-1069-A2EA-08002B30309D}'
# starts Internet Explorer

Start-Process
'::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{21EC2020-3AEA-1069-A2DD-08002B30309D}'
# starts Control Panel

Start-Process
'::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\::{2227A280-3AEA-1069-A2DE-08002B30309D}'
# starts Printers and Faxes

Start-Process '::{645FF040-5081-101B-9F08-00AA002F954E}'
# starts Recycle Bin

Start-Process '::{20D04FE0-3AEA-1069-A2D8-08002B30309D}'
# starts My Computer

Start-Process '::{208D2C60-3AEA-1069-A2D7-08002B30309D}'
# starts My Network Places

Start-Process
'::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}'
# starts Network Connections



My System SpecsSystem Spec
Old 08-11-2006   #9 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: Stupid [Diagnostics.Process]::Start("..") tricks

How about this amendment to the original, then? I went with the
ProcessStartInfo to allow simple invocation with no arguments where desired.

function Start-Process
{
Param([string]$Filename,[string]$ArgumentString = [System.String]::Empty)
$si = New-Object System.Diagnostics.ProcessStartInfo
$si.Filename = $Filename;
if($ArgumentString){$si.Arguments = $ArgumentString};
$si.Filename, $si.Arguments;
[System.Diagnostics.Process]::Start($si);
}

"Roman Kuzmin" <RomanKuzmin@discussions.microsoft.com> wrote in message
news:B7A7096A-12CF-44B9-AEC9-2DD202340BAB@microsoft.com...
> Nice. My two cents. The script below demonstrates how to:
>
> *) start a process with arguments
> *) wait for a process exit (BTW, you can specify timeout value)
> *) view/edit some text in Notepad
>
> --- 8< ---
>
> ## Edit-Text.ps1
> ## Edits text input in Notepad and returns modified text
> ## Usage: [ <text> | ] Edit-Text
>
> end
> {
> $file = [System.IO.Path]::GetTempFileName()
> $input | Set-Content $file
> $ps = [System.Diagnostics.Process]::Start("notepad", "`"$file`"")
> $ps.WaitForExit()
> Get-Content $file
> Remove-Item $file
> }
>
> --- 8< ---
>
> --
> Thanks,
> Roman
>



My System SpecsSystem Spec
Old 08-11-2006   #10 (permalink)
=?iso-8859-1?Q?Maximilian_H=E4nel?=


 
 

Re: Stupid [Diagnostics.Process]::Start("..") tricks

Hi Alex,

> I'm not sure about the particular view you mean, unless you're
> talking
> about the (in English) Computer Management console, normally located
> at
> %SystemRoot%\system32\compmgmt.msc. For that, you could use
> Start-Process compmgmt.msc


Well, not exactly, but we are going closer ;-) I'm talking about
CSIDL_COMMON_ADMINTOOLS and/or CSIDL_ADMINTOOLS.
So I guess that view is called "Administrative Tools" on english
systems. I was hoping to find such a nice shortcut as control.exe.

> I was actually thinking about shell namespace extensions, and had
> assumed that you could invoke them this way. It turns out you _can_
> invoke some of them via their 'path'. The path is a GUID for the
> magic
> namespaces such as Network Connections, etc. Here's how I normally
> find
> them:
> $sa = New-Object -ComObject Shell.Application
> 0..255 | %{$sa.Namespace($_).Self} | ft Name,Path -AutoSize -Wrap


Thanks a lot! With that information I was able to invoke my
"Verwaltung" view with this code:

$sa = New-Object -ComObject Shell.Application
Start-Process $sa.Namespace(47).Self.Path

However this view is not exactly the same as when invoked via Windows
Startmenu (compare the address bars). Any ideas?

Thanks again for your great explanations,

Max

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
[diagnostics.process]::start("exe") PowerShell
redirecting standar output when using [System.Diagnostics.Process]::Start PowerShell
Question about [System.Diagnostics.Process]::Start() PowerShell
Stupid highlighted"square"around selected desktop icons! Vista General
Using ProcessStartInfo with [System.Diagnostics.Process]::Start PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46