View Single Post
Old 04-06-2007   #5 (permalink)
William Stacey [C# MVP]


 
 

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 SpecsSystem Spec