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 > VB Script

Vista - Findout shortcut from which script was launched ?

Reply
 
Old 05-05-2009   #1 (permalink)
jm.almeras


 
 

Findout shortcut from which script was launched ?

Hello,

In a VBScript I wish to know if the script was called from a shortcut and if
so what is the path of this shortcut. Is this possible ?

In case you wish to know, here is why : i have a script which renames files
in a folder.
Currently i do the renames in the folder where the script itself is
situated.
I would like this to work also with a shortcut to the script file : the
rename should apply to the folder where the shortcut is situated, not the
folder where the script file is situated.

Any idea ?

Thanks a lot

Jean-Marie



My System SpecsSystem Spec
Old 05-05-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: Findout shortcut from which script was launched ?

Jean-Marie wrote:
Quote:

> In a VBScript I wish to know if the script was called from a shortcut and
> if so what is the path of this shortcut. Is this possible ?
>
> In case you wish to know, here is why : i have a script which renames
> files in a folder.
> Currently i do the renames in the folder where the script itself is
> situated.
> I would like this to work also with a shortcut to the script file : the
> rename should apply to the folder where the shortcut is situated, not the
> folder where the script file is situated.
>
> Any idea ?
I don't believe there is any way for a script to know that it was launched
by a shortcut, or the location of the shortcut. Wscript.ScriptPath returns
the name and path of the script file itself, not any shortcut that launched
it.

However, objFSO.GetAbsolutePathName(".") returns the current directory. You
can modify the "Start in" property of the shortcut so this returns the value
you want:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Wscript.Echo objFSO.GetAbsolutePathName(".")

You would need to modify this property of the shortcut for each folder. It
actually would not matter where the shortcut is saved.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 05-05-2009   #3 (permalink)
Al Dunbar


 
 

Re: Findout shortcut from which script was launched ?


"jm.almeras" <nospam@xxxxxx> wrote in message
news:ecaJQ8czJHA.1716@xxxxxx
Quote:

> Hello,
>
> In a VBScript I wish to know if the script was called from a shortcut and
> if so what is the path of this shortcut. Is this possible ?
No.
Quote:

> In case you wish to know, here is why : i have a script which renames
> files in a folder.
> Currently i do the renames in the folder where the script itself is
> situated.
> I would like this to work also with a shortcut to the script file : the
> rename should apply to the folder where the shortcut is situated, not the
> folder where the script file is situated.
Change your script to accept the name of a folder as its only parameter.
Then run it by dragging the desired folder onto either the script itself, or
a shortcut to the script.

/Al
Quote:

> Any idea ?
>
> Thanks a lot
>
> Jean-Marie
>

My System SpecsSystem Spec
Old 05-07-2009   #4 (permalink)
Csaba Gabor


 
 

Re: Findout shortcut from which script was launched ?

On May 6, 12:15 am, "jm.almeras" <nos...@xxxxxx> wrote:
Quote:

> In a VBScript I wish to know if the script was called from a shortcut and if
> so what is the path of this shortcut. Is this possible ?
>
> In case you wish to know, here is why : i have a script which renames
> files in a folder. Currently i do the renames in the folder where the script
> itself is situated.
> I would like this to work also with a shortcut to the script file : the
> rename should apply to the folder where the shortcut is situated, not the
> folder where the script file is situated.
This is a slippery problem, but it does have a solution...
if you ask the question in the right way. I have a more
complex situation because I want to apply the .vbs
script only to the selected files of a given directory.

There are two situations. The first, which I never use
anymore, is that I have a shortcut. The shortcut needs
to know what directory it was started in. But that's
not good enough. It actually needs to know what
Explorer window is active so for that I had to make
a mini .OCX file which uses the winAPI
GetForegroundWindowHandle() and then I run through
the .windows collection of the Shell.Application
object to see if there's a match on the .HWND.
Richard Meuller's suggestion probably suffices
for your situation.

The other thing that I do (independent of the prior
paragraph) is to make a change in the registry
so that for all .jpg files, I get a context
menu item (ie. when I right click) that will
execute my script when it's selected. The
script gets passed the name of the file
that it was started on, from which it knows
the directory.

Csaba Gabor from Vienna
My System SpecsSystem Spec
Old 05-08-2009   #5 (permalink)
jm.almeras


 
 

Re: Findout shortcut from which script was launched ?

Thank you Richard, Al, urkec and Csaba for your advice.

Richard's solution works but i find it inconvenient, because editing the
shortcut property to write the folder path as startin directory is
cumbersome (i have tested, it does not work if i put "." as startin
property)

I took Al's suggestion and introduced the possibility of dropping a folder
on the script. It works fine. Also, urkec's idea to put the script in the
SendTo Folder is good.


My System SpecsSystem Spec
Old 05-08-2009   #6 (permalink)
jm.almeras


 
 

Re: Findout shortcut from which script was launched ?

Your answer is interesting to me because i also wish to make it possible to
apply the script to selected files. It works with a small number of files
which i drop on the script (or its shortcut), but there is a limit : the
maximum size of the command line (pity !)

I would be interested in knowing what change you make in the registry. But
is this solution not equivalent to putting the script in the SendTo Folder
and when selecting a file or several, selecting Send To the script in the
contextual menu ?

Thank you

Jean-Marie

"Csaba Gabor" <danswer@xxxxxx> a écrit dans le message de news:
32a8e31d-e8f8-4be2-809f-69e170270593@xxxxxx...
Quote:

> On May 6, 12:15 am, "jm.almeras" <nos...@xxxxxx> wrote:
Quote:

>> In a VBScript I wish to know if the script was called from a shortcut and
>> if
>> so what is the path of this shortcut. Is this possible ?
>>
>> In case you wish to know, here is why : i have a script which renames
>> files in a folder. Currently i do the renames in the folder where the
>> script
>> itself is situated.
>> I would like this to work also with a shortcut to the script file : the
>> rename should apply to the folder where the shortcut is situated, not the
>> folder where the script file is situated.
>
> This is a slippery problem, but it does have a solution...
> if you ask the question in the right way. I have a more
> complex situation because I want to apply the .vbs
> script only to the selected files of a given directory.
>
> There are two situations. The first, which I never use
> anymore, is that I have a shortcut. The shortcut needs
> to know what directory it was started in. But that's
> not good enough. It actually needs to know what
> Explorer window is active so for that I had to make
> a mini .OCX file which uses the winAPI
> GetForegroundWindowHandle() and then I run through
> the .windows collection of the Shell.Application
> object to see if there's a match on the .HWND.
> Richard Meuller's suggestion probably suffices
> for your situation.
>
> The other thing that I do (independent of the prior
> paragraph) is to make a change in the registry
> so that for all .jpg files, I get a context
> menu item (ie. when I right click) that will
> execute my script when it's selected. The
> script gets passed the name of the file
> that it was started on, from which it knows
> the directory.
>
> Csaba Gabor from Vienna

My System SpecsSystem Spec
Old 05-12-2009   #7 (permalink)
Csaba Gabor


 
 

Re: Findout shortcut from which script was launched ?

On May 8, 12:02 pm, "jm.almeras" <nos...@xxxxxx> wrote:
Quote:

> Your answer is interesting to me because i also wish to make it possible to
> apply the script to selected files. It works with a small number of files
> which i drop on the script (or its shortcut), but there is a limit : the
> maximum size of the command line (pity !)
Here's an example:
In HKCR\*\shell\ place:
Cmd (REG_SZ): &Cmd window in this directory

Then make a subkey: In HKCR\*\shell\Cmd\ place command (REG_SZ):
cmd /K cd "%0\.." & title Context Menu Cmd Window & mode con lines=60
cols=100
or
cmd "c:\phplib\Context Cmd window.lnk"

If you do the second one (which is preferable for me) my
Context Cmd window.lnk shortcut has the following properties set:
under General: Context Cmd window
under Shortcut:
Target: %windir%\system32\cmd.exe
Shortcut key: None
Run: Normal window
under Options:
Cursor size: Small
Display options: Window
Edit options: QuickEdit mode, Insert mode
under Layout:
Screen buffer size: Width: 90, Height: 300
Window size: Width: 90, Height: 70
Window position: Let system position window

If you have a custom editor you like, you could do something like:
\HKCR\*\shell\Edit2: &Edit (with emacs)
\HKCR\*\shell\Edit2\command: C:\Program Files\emacs\bin\runemacs.exe -
geometry 155x59 "%1"

For a specific file type it's a bit more involved. Let's say .jpg
Go to
\HKCR\.jpg\(Default) and see the value listed there. It's jpegfile
Now make
\HKCR\jpegfile\shell\Resize: Res&ize
\HKCR\jpegfile\shellResize\command: c:\phpdir\php-win.exe "C:\Photo
\Util\Resize.php" "%1" %*

That %0 and %1 are the file that you are right clicking on.
The quotes (") are because of possible spaces in file names
%* means any remaining arguments
Quote:

> I would be interested in knowing what change you make in the registry. But
> is this solution not equivalent to putting the script in the SendTo Folder
> and when selecting a file or several, selecting Send To the script in the
> contextual menu ?
I've never worked with "SendTo" and I don't know the answer to that.
Quote:

> Thank you
>
> Jean-Marie
>
> "Csaba Gabor" <dans...@xxxxxx> a écrit dans le message de news:
> 32a8e31d-e8f8-4be2-809f-69e170270...@xxxxxx
>
Quote:

> > On May 6, 12:15 am, "jm.almeras" <nos...@xxxxxx> wrote:
Quote:

> >> In a VBScript I wish to know if the script was called from a shortcut and
> >> if
> >> so what is the path of this shortcut. Is this possible ?
>
Quote:
Quote:

> >> In case you wish to know, here is why : i have a script which renames
> >> files in a folder. Currently i do the renames in the folder where the
> >> script
> >> itself is situated.
> >> I would like this to work also with a shortcut to the script file : the
> >> rename should apply to the folder where the shortcut is situated, not the
> >> folder where the script file is situated.
>
Quote:

> > This is a slippery problem, but it does have a solution...
> > if you ask the question in the right way. I have a more
> > complex situation because I want to apply the .vbs
> > script only to the selected files of a given directory.
>
Quote:

> > There are two situations. The first, which I never use
> > anymore, is that I have a shortcut. The shortcut needs
> > to know what directory it was started in. But that's
> > not good enough. It actually needs to know what
> > Explorer window is active so for that I had to make
> > a mini .OCX file which uses the winAPI
> > GetForegroundWindowHandle() and then I run through
> > the .windows collection of the Shell.Application
> > object to see if there's a match on the .HWND.
> > Richard Meuller's suggestion probably suffices
> > for your situation.
>
Quote:

> > The other thing that I do (independent of the prior
> > paragraph) is to make a change in the registry
> > so that for all .jpg files, I get a context
> > menu item (ie. when I right click) that will
> > execute my script when it's selected. The
> > script gets passed the name of the file
> > that it was started on, from which it knows
> > the directory.
>
Quote:

> > Csaba Gabor from Vienna
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
script to create shortcut on user desktop PowerShell
IE8 Beta1 Launched Vista News
Script Host Client launched from Windows Service Vista security
Creating a shortcut for Powershell script PowerShell
When new MS keyboards will be launched? Vista hardware & devices


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