![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| 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 Specs![]() |
| | #2 (permalink) |
| 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 Specs![]() |
| | #3 (permalink) |
| 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 Specs![]() |
| | #4 (permalink) |
| Newbie | 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 Specs![]() |
| | #5 (permalink) |
| 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 Specs![]() |
| | #6 (permalink) |
| 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? 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 Specs![]() |
| | #7 (permalink) |
| 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 Specs![]() |
| | #8 (permalink) |
| 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 Specs![]() |
| | #9 (permalink) |
| Newbie | 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 Specs![]() |
| | #10 (permalink) |
| 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 Specs![]() |
![]() |
| 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 | |||