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 Tutorial - Executing PS1 files by double clicking on them

Reply
 
Old 04-15-2008   #1 (permalink)
greatbarrier86
Guest


 
 

Executing PS1 files by double clicking on them

I need some advice. Occasionally, some of my scripts are run by the
technician manually and are not automatically invoked. In the case of
powershell files, i am using either a VBS file or a BAT file to invoke the
PS1 file because PS1s are designed to open with notepad by default. Can
anyone offer me some advice as to a way that would allow the tech to just
execute the PS1 file by clicking on it?

My System SpecsSystem Spec
Old 04-15-2008   #2 (permalink)
RichS [MVP]
Guest


 
 

RE: Executing PS1 files by double clicking on them

By default ps1 files are not executable by double clicking. This is designed
to prevent some of the issues seen with VBScript code that can be run by
malware.

If you want to make the scripts accessible to running manually without
access to the PowerShell prompt why not look at using PowerGUI

--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"greatbarrier86" wrote:
Quote:

> I need some advice. Occasionally, some of my scripts are run by the
> technician manually and are not automatically invoked. In the case of
> powershell files, i am using either a VBS file or a BAT file to invoke the
> PS1 file because PS1s are designed to open with notepad by default. Can
> anyone offer me some advice as to a way that would allow the tech to just
> execute the PS1 file by clicking on it?
My System SpecsSystem Spec
Old 04-15-2008   #3 (permalink)
NilVeritas
Guest


 
 

Re: Executing PS1 files by double clicking on them

You can make a shortcut to WindowsPowershell - the executable, and
name that shortcut what you want. After the shortcut is made, you can
then append to the end of the 'Target' field -nologo -command &'\\path
\to\your\script.ps1' and when someone double clicks the link, and
presuming you have the execution policy set to run your script, a
shell will be created and your script will run it. May not be the
most elegant, but it works.

Essentially the same as scheduling a powershell script in task manager.
My System SpecsSystem Spec
Old 04-16-2008   #4 (permalink)
Newbie


Join Date: Dec 2007
?
 
 

Re: Executing PS1 files by double clicking on them

a bat file
-----------------------------------------

ftype Microsoft.PowerShellScript.1="C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe" -noexit ^&'%%1'
assoc .ps1=Microsoft.PowerShellScript.1

-----------------------------------------
auto exit: remove -noexit
My System SpecsSystem Spec
Old 04-17-2008   #5 (permalink)
greatbarrier86
Guest


 
 

Re: Executing PS1 files by double clicking on them

Thanks,
I like the shortcut idea. The problem with PowerGui is that i dont want to
install it on all the computers i am deploying.

Thanks for the help guys!

"NilVeritas@xxxxxx" wrote:
Quote:

> You can make a shortcut to WindowsPowershell - the executable, and
> name that shortcut what you want. After the shortcut is made, you can
> then append to the end of the 'Target' field -nologo -command &'\\path
> \to\your\script.ps1' and when someone double clicks the link, and
> presuming you have the execution policy set to run your script, a
> shell will be created and your script will run it. May not be the
> most elegant, but it works.
>
> Essentially the same as scheduling a powershell script in task manager.
>
My System SpecsSystem Spec
Old 04-17-2008   #6 (permalink)
Marco Shaw [MVP]
Guest


 
 

Re: Executing PS1 files by double clicking on them

greatbarrier86 wrote:
Quote:

> I need some advice. Occasionally, some of my scripts are run by the
> technician manually and are not automatically invoked. In the case of
> powershell files, i am using either a VBS file or a BAT file to invoke the
> PS1 file because PS1s are designed to open with notepad by default. Can
> anyone offer me some advice as to a way that would allow the tech to just
> execute the PS1 file by clicking on it?
There is another way, I'm just not interested in making it public with
my name attached to it... ;-)

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 04-17-2008   #7 (permalink)
greatbarrier86
Guest


 
 

Re: Executing PS1 files by double clicking on them

What? Huh? Damn...well if you were to tell me, how would i have to go about
asking?

"Marco Shaw [MVP]" wrote:
Quote:

> greatbarrier86 wrote:
Quote:

> > I need some advice. Occasionally, some of my scripts are run by the
> > technician manually and are not automatically invoked. In the case of
> > powershell files, i am using either a VBS file or a BAT file to invoke the
> > PS1 file because PS1s are designed to open with notepad by default. Can
> > anyone offer me some advice as to a way that would allow the tech to just
> > execute the PS1 file by clicking on it?
>
> There is another way, I'm just not interested in making it public with
> my name attached to it... ;-)
>
> Marco
>
> --
> Microsoft MVP - Windows PowerShell
> http://www.microsoft.com/mvp
>
> PowerGadgets MVP
> http://www.powergadgets.com/mvp
>
> Blog:
> http://marcoshaw.blogspot.com
>
My System SpecsSystem Spec
Old 04-18-2008   #8 (permalink)
Mark E. Schill
Guest


 
 

Re: Executing PS1 files by double clicking on them

I have the same problem because I create powershell scripts that I send
to my colleagues to run. I have been toying around with the idea of
creating a small application that I would associate the .ps1 extension
to and accept the PowerShell script as a parameter. So you would
double-click the .ps1 file and it would bring up a window asking you to
confirm that you really want to do it and execute the script in
PowerShell if you accept. And it would have lots of warnings.


Mark

Marco Shaw [MVP] wrote:
Quote:

> greatbarrier86 wrote:
Quote:

>> I need some advice. Occasionally, some of my scripts are run by the
>> technician manually and are not automatically invoked. In the case of
>> powershell files, i am using either a VBS file or a BAT file to invoke
>> the PS1 file because PS1s are designed to open with notepad by
>> default. Can anyone offer me some advice as to a way that would allow
>> the tech to just execute the PS1 file by clicking on it?
>
> There is another way, I'm just not interested in making it public with
> my name attached to it... ;-)
>
> Marco
>
My System SpecsSystem Spec
Old 04-26-2008   #9 (permalink)
Newbie


Join Date: Apr 2008
Vista Ultimate x64
 
 

Re: Executing PS1 files by double clicking on them

To avoid the concerns of changing the ps1 extension association, how about adding a right click choice to SendTo PowerShell?

Here is a little VBScript I wrote to set this up.

Code:
'==========================================================================
'
' NAME: SendToPowerShell.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: Home
' DATE  : 4/24/2008
' COPYRIGHT (c) 2008 All Rights Reserved
'
' COMMENT: Adds SendTo right menu choice for PowerShell.
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.
'
'==========================================================================
Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
strSendToFolder = WSHShell.SpecialFolders("SendTo")
If Not objFSO.FolderExists(Windir & "\sysWOW64") Then 
 strPathToNotepad = WinDir & "\system32\WindowsPowerShell\v1.0\powershell.exe"
 Set objShortcut = WSHShell.CreateShortcut(strSendToFolder & _
  "\PowerShell.lnk")
 objShortcut.TargetPath = strPathToNotepad
 objShortcut.Save
Else
 strPathToNotepad = WinDir & "\sysWOW64\WindowsPowerShell\v1.0\powershell.exe"
 Set ps86 = WSHShell.CreateShortcut(strSendToFolder & _
  "\PowerShell(x86).lnk")
 ps86.TargetPath = strPathToNotepad
 ps86.Save
 strPathToNotepad = WinDir & "\system32\WindowsPowerShell\v1.0\powershell.exe"
 Set ps64 = WSHShell.CreateShortcut(strSendToFolder & _
  "\PowerShell.lnk")
 ps64.TargetPath = strPathToNotepad
 ps64.Save
End If
My System SpecsSystem Spec
Old 05-16-2008   #10 (permalink)
Stiletto
Guest


 
 

Re: Executing PS1 files by double clicking on them

You shouldn't have to add anything to you shortcut. It should pass the file
to the script in the $args collection. Typically accessed as $args[0]

"Doug Griffin" wrote:
Quote:

> Hiyas. I have been experimenting with the shortcut method and it works great.
>
> I have a powershell script that I use routinely to to do make changes to an
> xml file. It would be great if I could create a shortcut that I could drag
> and drop the file on to and have the script do its stuff on this file.
>
> Is there a way I can pass the path of the file I drop onto the shortcut into
> my powershell script?
>
> I have tired %L which is one I use for registry context menus, but no go.
>
> Also, anyone know where I can find a list of what environment variables are
> availble? I can find stuff like %programfiles% easy enough with google, but
> can't find anything on what "%L" means (I think literal path), but I am after
> a list of all the environment variables and their meanings.
>
> thanks much for any advice
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
My mouse keeps double clicking... Vista hardware & devices
Double clicking. Vista file management
Trouble Double Clicking Vista General
How to preview photos by double clicking them? Vista General
Can't open files by double clicking on them... Vista file management


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