![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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 | Can you drag-n-drop a file on top of a PS script to run the script? With VBScript files, you can drag-n-drop another file on top of the VBScript file. This executes the VBScript and then the path of the dropped file is passed in as an argument to the script. You can also put VBScript scripts into your Send To folder in your local profile, then "send" files to the script. Finally, wscript.exe can take a UNC path to a script in a remote shared folder and run scripts from the share. Are these tricks possible with PowerShell too? Thanks! |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Can you drag-n-drop a file on top of a PS script to run the script? Short Answer (by default) No,No,Yes (but be careful of signing.) Long Answer By default powershell does not register .ps1 to powershell... they get registered to notepad. This is a security measure. You can however associate ..ps1 with Powershell and it will work although atm I cant test all your scenarios because I am using Vista... Its a tad different in those areas. "Jen Taylor" <jtaylor23@aol.com> wrote in message news:%23PPS4gOcHHA.2300@TK2MSFTNGP06.phx.gbl... > With VBScript files, you can drag-n-drop another file on top of the > VBScript file. This executes the VBScript and then the path of the > dropped file is passed in as an argument to the script. > > You can also put VBScript scripts into your Send To folder in your local > profile, then "send" files to the script. > > Finally, wscript.exe can take a UNC path to a script in a remote shared > folder and run scripts from the share. > > Are these tricks possible with PowerShell too? > > Thanks! > > > > |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Can you drag-n-drop a file on top of a PS script to run the script? > By default powershell does not register .ps1 to powershell... they get > registered to notepad. This is a security measure. Hmmm, interesting. Why not associate .ps1 files with powershell.exe, but set the default action to Edit instead of Open? This way, if a user double-clicks the file, it'll still open in Notepad, but if the user right-clicks the file they can still run the script by manually by selecting Open. Oh well...thanks for the info! |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Can you drag-n-drop a file on top of a PS script to run the script? Jen Taylor wrote: > With VBScript files, you can drag-n-drop another file on top of the VBScript > file. This executes the VBScript and then the path of the dropped file is > passed in as an argument to the script. > > You can also put VBScript scripts into your Send To folder in your local > profile, then "send" files to the script. > > Finally, wscript.exe can take a UNC path to a script in a remote shared > folder and run scripts from the share. > > Are these tricks possible with PowerShell too? > > Thanks! > Have you done this yet? I've tried dragging a file to a Powershell script shortcut on my desktop but it doesn't take it. |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: Can you drag-n-drop a file on top of a PS script to run the script? There may be a better way, but this worked for me so far: 1) Right-click/New Shortcut on desktop. 2) Enter the target like so: powershell.exe "&{c:\bin\testit.ps1 $args}" 3) Change testit.ps1 to be your target script you want to run. 4) The file name is passed as parms to the command, which is passed as first parm to the script. It gets funky to reason about. 5) When you drag another script onto this icon, it should pass the file name to the script and you can then do what you want with that file name. I don't think the first way of draging a script ontop of another script will work as that is like dragging a txt file onto another txt file which also does nothing unless there is some hack. testit.ps1 ----------------------------------------------------------------- param([string]$path = $(throw "Path name must be specified.")) echo "Len:" $args.length $args cat $path read-host -prompt "Hit Enter" -- William Stacey [C# MVP] PCR concurrency library: www.codeplex.com/pcr PSH Scripts Project www.codeplex.com/psobject "Jim Holcomb" <jim@example.net> wrote in message news:OYUi6n6dHHA.208@TK2MSFTNGP05.phx.gbl... | Jen Taylor wrote: | > With VBScript files, you can drag-n-drop another file on top of the VBScript | > file. This executes the VBScript and then the path of the dropped file is | > passed in as an argument to the script. | > | > You can also put VBScript scripts into your Send To folder in your local | > profile, then "send" files to the script. | > | > Finally, wscript.exe can take a UNC path to a script in a remote shared | > folder and run scripts from the share. | > | > Are these tricks possible with PowerShell too? | > | > Thanks! | > | | Have you done this yet? I've tried dragging a file to a Powershell | script shortcut on my desktop but it doesn't take it. |
My System Specs![]() |
| | #6 (permalink) |
| Guest | Re: Can you drag-n-drop a file on top of a PS script to run the script? Thanks, this works great and also works as a Send To item. JIm William Stacey [C# MVP] wrote: > There may be a better way, but this worked for me so far: > > 1) Right-click/New Shortcut on desktop. > 2) Enter the target like so: powershell.exe "&{c:\bin\testit.ps1 $args}" > 3) Change testit.ps1 to be your target script you want to run. > 4) The file name is passed as parms to the command, which is passed as first > parm to the script. It gets funky to reason about. > 5) When you drag another script onto this icon, it should pass the file name > to the script and you can then do what you want with that file name. > > I don't think the first way of draging a script ontop of another script will > work as that is like dragging a txt file onto another txt file which also > does nothing unless there is some hack. > > testit.ps1 > ----------------------------------------------------------------- > param([string]$path = $(throw "Path name must be specified.")) > echo "Len:" $args.length > $args > cat $path > read-host -prompt "Hit Enter" > |
My System Specs![]() |
| | #7 (permalink) |
| Guest | Re: Can you drag-n-drop a file on top of a PS script to run the script? cool. Glad is worked. It should also work with paths with spaces in the name. -- William Stacey [C# MVP] PCR concurrency library: www.codeplex.com/pcr PSH Scripts Project www.codeplex.com/psobject "Jim Holcomb" <jim@example.net> wrote in message news:eYz439EeHHA.320@TK2MSFTNGP03.phx.gbl... | Thanks, this works great and also works as a Send To item. | | JIm | | William Stacey [C# MVP] wrote: | > There may be a better way, but this worked for me so far: | > | > 1) Right-click/New Shortcut on desktop. | > 2) Enter the target like so: powershell.exe "&{c:\bin\testit.ps1 $args}" | > 3) Change testit.ps1 to be your target script you want to run. | > 4) The file name is passed as parms to the command, which is passed as first | > parm to the script. It gets funky to reason about. | > 5) When you drag another script onto this icon, it should pass the file name | > to the script and you can then do what you want with that file name. | > | > I don't think the first way of draging a script ontop of another script will | > work as that is like dragging a txt file onto another txt file which also | > does nothing unless there is some hack. | > | > testit.ps1 | > ----------------------------------------------------------------- | > param([string]$path = $(throw "Path name must be specified.")) | > echo "Len:" $args.length | > $args | > cat $path | > read-host -prompt "Hit Enter" | > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| problem passing args to script 'There is no script engine for file extenstion' | VB Script | |||
| Drag and Drop to execute file | Vista General | |||
| Script file has 'OS Handle' error when run from script | PowerShell | |||
| Can't drag & drop TXT file from Explorer to Notepad ??? | Vista General | |||
| Cannot drag & drop a file | Vista General | |||