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 - Can you drag-n-drop a file on top of a PS script to run the script?

Reply
 
Old 03-27-2007   #1 (permalink)
Jen Taylor
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 SpecsSystem Spec
Old 03-28-2007   #2 (permalink)
Brandon Shell
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 SpecsSystem Spec
Old 03-28-2007   #3 (permalink)
Jen Taylor
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 SpecsSystem Spec
Old 04-05-2007   #4 (permalink)
Jim Holcomb
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 SpecsSystem Spec
Old 04-06-2007   #5 (permalink)
William Stacey [C# MVP]
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 SpecsSystem Spec
Old 04-06-2007   #6 (permalink)
Jim Holcomb
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 SpecsSystem Spec
Old 04-06-2007   #7 (permalink)
William Stacey [C# MVP]
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 SpecsSystem Spec
Reply

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


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