Windows Vista Forums

Findout shortcut from which script was launched ?
  1. #1


    jm.almeras Guest

    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

  2. #2


    Richard Mueller [MVP] Guest

    Re: Findout shortcut from which script was launched ?

    Jean-Marie wrote:

    > 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

  3. #3


    Al Dunbar Guest

    Re: Findout shortcut from which script was launched ?


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

    > 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.

    > 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

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


      My System SpecsSystem Spec

  4. #4


    Csaba Gabor Guest

    Re: Findout shortcut from which script was launched ?

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

    > 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

  5. #5


    jm.almeras Guest

    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

  6. #6


    jm.almeras Guest

    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...

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

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

  7. #7


    Csaba Gabor Guest

    Re: Findout shortcut from which script was launched ?

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

    > 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

    > 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.

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

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

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

Findout shortcut from which script was launched ? problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
script to create shortcut on user desktop Huang PowerShell 2 11 Mar 2009
IE8 Beta1 Launched dmex Vista News 41 02 Apr 2008
Script Host Client launched from Windows Service DavidRF Vista security 4 27 Jun 2007
Creating a shortcut for Powershell script Frank PowerShell 3 03 Apr 2007
When new MS keyboards will be launched? EdricFilho Vista hardware & devices 2 13 Dec 2006