Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Make variable shortcut in windows explorer  (Read 11146 times)

0 Members and 1 Guest are viewing this topic.

Roely

    Topic Starter


    Rookie
    • Experience: Familiar
    • OS: Windows 7
    Make variable shortcut in windows explorer
    « on: April 26, 2017, 03:23:38 AM »
    Hi

    Hope someone can help!

    Situation:
    We have template-folder, which we copy when we want to make a new project.
    In this folder there are a few subfolders; Folder A, Folder B, Folder C

    Problem:
    I need a shortcut in 'Folder C', to 'Folder A'

    I can't make a shortcut in the template folder, because the projectname is different every time.
    E.g.:
    Project 1:
    Path Folder A = C:\MyProjects\Project1\FolderA
    Path Folder C = C:\MyProjects\Project1\FolderC

    Project 2:
    Path Folder A = C:\MyProjects\Project2\FolderA
    Path Folder C = C:\MyProjects\Project2\FolderC

    'Folder C' is always in the same project (path) as the 'Folder A' I need a shotcut to.

    Is it possible to make the shortcut variable so I can put this in my template-folder?

    Thx!

    grtz
    Roely

    DaveLembke



      Sage
    • Thanked: 662
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Make variable shortcut in windows explorer
    « Reply #1 on: April 26, 2017, 09:38:49 PM »
    Hello.... Just wanted you to know that I coded up code for this tonight, but Windows is not happy with the .lnk shortcut. I asked for someone with more knowledge of Windows shortcuts to point out what I am missing in .lnk shortcut generation.

    Here is what I have for code, but the shortcut created doesnt function yet. Its going to need some fixing. So to let you know that someone is working on this and here is what has been worked on so far:

    http://www.computerhope.com/forum/index.php/topic,160554.0.html

    Roely

      Topic Starter


      Rookie
      • Experience: Familiar
      • OS: Windows 7
      Re: Make variable shortcut in windows explorer
      « Reply #2 on: April 27, 2017, 01:47:41 AM »
      Hi DaveLembke

      Many many thanks already.
      I'm very happy someone is willing to help, and even more excited that you'll probably find a solution for my problem!

      greetings
      Roely

      DaveLembke



        Sage
      • Thanked: 662
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: Make variable shortcut in windows explorer
      « Reply #3 on: April 28, 2017, 10:49:01 AM »
      Please read BC_Programmers response to issues I had in shortcut generation, and specify if you want to go with powershell or vbscript as a method. Link below you will find BC_Programmers response with methods for generating shortcuts. For years I thought it was as simple as putting a path into a text file and renaming the text file from .TXT to .LNK but there is more to it than that.

      So once I know your preference, I should be able to put this together for you.

      http://www.computerhope.com/forum/index.php/topic,160554.0.html

      Roely

        Topic Starter


        Rookie
        • Experience: Familiar
        • OS: Windows 7
        Re: Make variable shortcut in windows explorer
        « Reply #4 on: May 02, 2017, 05:56:09 AM »
        Hmm, I'm not familiar with Powershell.
        I can program a bit in vb, but I'm definitly not a pro...

        So, I would prefer the easiest way in use.
        Are there any differences in the result? Or in the handling to use it?

        Hackoo



          Hopeful
        • Thanked: 42
        • Experience: Expert
        • OS: Windows 10
        Re: Make variable shortcut in windows explorer
        « Reply #5 on: May 02, 2017, 08:05:32 AM »
        Hi  ;)
        I don't know if this what you want or not?
        Just copy and paste this code with your notepad and save it as CreateShortcut.bat and execute it by double click on it !
        Code: [Select]
        @echo off
        Set "MyShortcutName=C:\MyProjects\Project1\FolderC\Shortcut2FolderA.lnk"
        Set "Target=C:\MyProjects\Project1\FolderA"
        Call :CreateShortcut
        Set "MyShortcutName=C:\MyProjects\Project2\FolderC\Shortcut2FolderA.lnk"
        Set "Target=C:\MyProjects\Project2\FolderA"
        Call :CreateShortcut
        pause & Exit
        ::***********************************************************************
        :CreateShortcut
        echo(
        echo            Creating the shortcut is in progress .....
        ::***********************************************************************
        :: Partie Powershell
        Powershell ^
        $s=(New-Object -COM WScript.Shell).CreateShortcut('%MyShortcutName%'); ^
        $s.TargetPath='%Target%'; ^
        $s.Save()
        Exit /b
        ::***********************************************************************

        DaveLembke



          Sage
        • Thanked: 662
        • Certifications: List
        • Computer: Specs
        • Experience: Expert
        • OS: Windows 10
        Re: Make variable shortcut in windows explorer
        « Reply #6 on: May 03, 2017, 05:27:26 AM »
        Hi Hackoo .... they would need to be able to specify whatever Project1 is Project1 is... so that is dynamic and could be named anything. So it looks like what you put together would work if you concatenated the path with static prepend of path and used user input for actual project name from user concatenated and then appended the rest of the path as static. I did this in my C++ project for this and ran into an issue in not fully understanding .lnk shortcut constructions. If you can pull this off in batch it would  be cleaner than me adding it in as a system call in C++.

        Tried out what you put together with Windows 7 and saw that powershell doesnt need to be added like in past versions of windows. My last use of it was back in the days of XP SP2 and I had to add it. Its nice that its a part of windows now.

        Quote
        PowerShell 2.0 is integrated with Windows 7 and Windows Server 2008 R2[50] and is released for Windows XP with Service Pack 3, Windows Server 2003 with Service Pack 2, and Windows Vista with Service Pack 1

        Here is my C/C++ to see how I had asked for user input on project name and it creates a concatenated path from user input with prepend then insertion of project name with concatenation and then appended rest of the pathing. I am weak with batch, but I think you might be able to ask for user input and be able to concatenate the path to make what you have work. This will save them from having to compile a C++ program.  :)

        #include <iostream>
        #include <string>
        #include <fstream>
        int main() {
          std::string Project_Name;
          std::cout<<"Enter Project Name\n";
          std::cin>>Project_Name;

          std::string filepath = "C:\\MyProjects\\";
         
          std::ofstream outfile;
          outfile.open((filepath.append(Project_Name+"\\FolderC\\Goto_FolderA.lnk")).c_str(),std::ios_base::trunc);
          outfile <<"C:\\MyProjects\\"<<Project_Name<<"\\FolderA\\\n";

          outfile.close();
          return 0;
        }


        Roely

          Topic Starter


          Rookie
          • Experience: Familiar
          • OS: Windows 7
          Re: Make variable shortcut in windows explorer
          « Reply #7 on: May 03, 2017, 06:14:17 AM »
          Hi Hackoo

          Thanks for your help!
          I tried it, but it didn't work, so I can't say if it did what I want...


          I'll try to clear up a bit more (hope it doesn't confuse you more):

          First, you need to know I have several projects, all given a 6-digit-number (e.g. 101456).
          These projects are divided in subfolders '100000', '101000', '102000'...
          (Project '101456' is in subfolder '101000')

          All these subfolders are on path:
          "C:\Mydocuments\Work\Projects\All"
          So, Project '101456' is path:
          "C:\Mydocuments\Work\Projects\All\101000\101456"


          Second, I have a template-folder on the same path as the subfolders:
          "C:\Mydocuments\Work\Projects\All\Template"

          When I have a new project I copy this template-folder and paste it in the right subfolder.

          This is the background info.
          Now the problem!  :)

          In the template-folder, there are several  subfolders; Folder A, Folder B, Folder C
          I need a shortcut in Folder C to Folder A

          So, shortcut from "C:\Mydocuments\Work\Projects\All\Template\Folder C" to "C:\Mydocuments\Work\Projects\All\Template\Folder A"
          (That's easy to make with a regular shortcut).

          For project '101456' this would be from "C:\Mydocuments\Work\Projects\All\101000\101456\Folder C" to "C:\Mydocuments\Work\Projects\All\101000\101456\Folder A"

          Now, when I copy the template, paste it in the subfolder and rename it to my projectnumber, a regular shortcut won't refer to the right subfolder anymore.
          The regular shortcut in this project will still be the same as the one in the template:
          "C:\Mydocuments\Work\Projects\All\Template\Folder A"

          The shortcut should be to:
          "C:\Mydocuments\Work\Projects\All\101000\101456\Folder A"

          Resume: I need a way to simply copy the template folder and adapt the shortcut to the new location.


          Hope this clears a bit more...


          DaveLembke



            Sage
          • Thanked: 662
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 10
          Re: Make variable shortcut in windows explorer
          « Reply #8 on: May 03, 2017, 11:31:39 AM »
          Noticed that your folder structure changed between starting request for help and current update on what you need. So which information is dynamic ( as in needs to have input from you to specify the different project and is a variable in the path? ) Static information is information that is always named as such and dynamic is naming that changes from project to project and will require user interaction to specify where this shortcut is to be created.

          You started with a structure of this:
          Quote
          Quote
          I can't make a shortcut in the template folder, because the projectname is different every time.
          E.g.:
          Project 1:
          Path Folder A = C:\MyProjects\Project1\FolderA
          Path Folder C = C:\MyProjects\Project1\FolderC

          Project 2:
          Path Folder A = C:\MyProjects\Project2\FolderA
          Path Folder C = C:\MyProjects\Project2\FolderC

          And now I see its different with this:

          Quote
          In the template-folder, there are several  subfolders; Folder A, Folder B, Folder C
          I need a shortcut in Folder C to Folder A

          So, shortcut from "C:\Mydocuments\Work\Projects\All\Template\Folder C" to "C:\Mydocuments\Work\Projects\All\Template\Folder A"
          (That's easy to make with a regular shortcut).

          For project '101456' this would be from "C:\Mydocuments\Work\Projects\All\101000\101456\Folder C" to "C:\Mydocuments\Work\Projects\All\101000\101456\Folder A"

          Now, when I copy the template, paste it in the subfolder and rename it to my projectnumber, a regular shortcut won't refer to the right subfolder anymore.
          The regular shortcut in this project will still be the same as the one in the template:
          "C:\Mydocuments\Work\Projects\All\Template\Folder A"

          The shortcut should be to:
          "C:\Mydocuments\Work\Projects\All\101000\101456\Folder A"

          Resume: I need a way to simply copy the template folder and adapt the shortcut to the new location.


          Hope this clears a bit more...


          Guessing most recent is the way the structure will be and the initial post was incorrect?  :-\

          Roely

            Topic Starter


            Rookie
            • Experience: Familiar
            • OS: Windows 7
            Re: Make variable shortcut in windows explorer
            « Reply #9 on: May 09, 2017, 08:25:29 AM »
            Ow... sorry if I wasn't totally clear...

            In my last post I tried to explain a bit more about the handlings I do and used the real structure of the paths.
            I understand that confuses you.

            But I can confirm: The explanation in the last post, is correct.

            Please forgive me  |V| O:)

            Hope you still can help me!

            BC_Programmer


              Mastermind
            • Typing is no substitute for thinking.
            • Thanked: 1140
              • Yes
              • Yes
              • BC-Programming.com
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 11
            Re: Make variable shortcut in windows explorer
            « Reply #10 on: May 09, 2017, 04:07:56 PM »
            Quote
            Resume: I need a way to simply copy the template folder and adapt the shortcut to the new location.
            Unfortunately, this is not possible. Shortcuts cannot be used this way. In your example you want your shortcut to point at "..\Folder A" (eg. Up one level,  at Folder A folder) but Shortcuts cannot point at relative paths.

            This means you have to change that shortcut, either with a script file, batch file, or other program when you copy it in order to have the shortcut now point at the intended new location rather than the old one.




            I was trying to dereference Null Pointers before it was cool.

            Geek-9pm


              Mastermind
            • Geek After Dark
            • Thanked: 1026
              • Gekk9pm bnlog
            • Certifications: List
            • Computer: Specs
            • Experience: Expert
            • OS: Windows 10
            Re: Make variable shortcut in windows explorer
            « Reply #11 on: May 09, 2017, 05:27:39 PM »
            There are a number of ways to create shortcuts in Powershell.
            One of many:

            command line - How to create a shortcut using Powershell ...
            Stackoverflow › questions › 9701840

            Mar 12, 2015 · I want to create a shortcut with Powershell for this executable: C:\Program Files (x86)\ColorPix\ColorPix.exe How can this be done?

                Code sample
                param ( [string]$SourceExe, [string]$ArgumentsToSourceExe, [string]$DestinationPath )
                $WshShell = New-Object -comObject WScript.Shell
                $Shortcut = $WshShell.CreateShortcut($DestinationPath)
                $Shortcut.TargetPath = $SourceExe
                $Shortcut.Arguments = $ArgumentsToSourceExe...

            http://stackoverflow.com/questions/9701840/how-to-create-a-shortcut-using-powershell
            Maybe that could help.  :)

            Geek-9pm


              Mastermind
            • Geek After Dark
            • Thanked: 1026
              • Gekk9pm bnlog
            • Certifications: List
            • Computer: Specs
            • Experience: Expert
            • OS: Windows 10
            Re: Make variable shortcut in windows explorer
            « Reply #12 on: May 09, 2017, 09:03:57 PM »
            Also, Roely needs to clarify why he needs a 'variable' LNK file.
            Who or what will use the file? The LNK visual thing for the user to use. Why is it needed?
            One can edit and modify a LNK file, but not in the usual way.

            One approach is to alter a LNK file that already is there.
            You would have a skeleton directory with a empty directory and a LNK to that directory. You copy both to another place and rename the directory and then populate the directories.






            Roely

              Topic Starter


              Rookie
              • Experience: Familiar
              • OS: Windows 7
              Re: Make variable shortcut in windows explorer
              « Reply #13 on: May 10, 2017, 03:19:08 PM »
              Users must simply click on the 'shortcut'.
              Why is it needed?
              I need all the information of the different folders in one folder.
              Copying the files would make different version of the files in case of changes.
              That's why we decided to make a shortcut in that one folder.
              If we want it, we need to make the shortcut manually, every time, for every project.

              Geek-9pm


                Mastermind
              • Geek After Dark
              • Thanked: 1026
                • Gekk9pm bnlog
              • Certifications: List
              • Computer: Specs
              • Experience: Expert
              • OS: Windows 10
              Re: Make variable shortcut in windows explorer
              « Reply #14 on: May 10, 2017, 03:46:20 PM »
              Quote
              If we want it, we need to make the shortcut manually, every time, for every project.
              Is that hard to do? Os it time-consuming? How much time would yuo save it you had a software tool  that does it for you?
              If you had a software tool that did that, how would it work? Describe is plain English, not symbols. Does each project have a unique name?
              Is the shortcut only a link to a folder location? Or is it sometimes a link to a file?

              How many projects are active at one time? Do you ever re-use project names?