Computer Hope
Software => Computer software => Topic started by: Roely 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
-
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
-
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
-
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
-
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?
-
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 !
@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
::***********************************************************************
-
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.
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;
}
-
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...
-
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:
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:
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? :-\
-
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!
-
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.
-
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. :)
-
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.
-
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.
-
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?
-
Some more information found.
Thee is an utility called 'mkshortcut.exe' and is available.
Link:
http://www.mediafire.com/file/gzkgthmjhyv/mkshortcut.zip
D:\BIN>mkshortcut /?
Creates a shortcut with advanced properties for use by Window 7's new Taskbar.
mkshortcut -output <filename> -target <filename> [-parameters <parameters>]
[-workingdir <directory>] [-appid <string>] [-relaunchcmd <command>]
[-relaunchname <name>]
-output <filename> Where to save the shortcut.
-target <filename> Target of the newly created shortcut, not
necessarily an executable: files will be opened
by the program associated with their extensions.
-parameters <parameters> Parameters to be passed to the shortcut's target.
Wrap all of them in a single pair of quotes if
passing multiple switches.
-workingdir <pathname> Working directory used by the target program.
-appid <string> String used by Windows 7's Taskbar to identify
applications.
-relaunchcommand <command> Command to be used when relaunching this shortcut
using Windows 7's Taskbar, whether through Middle
Click/Shift+Click, or after being pinned.
-relaunchname <string> User-friendly name displayed for the relaunch
command.
You may use a translatable resource by preceding
its name with an '@' character.
The following is only meaningful if you are using Windows 7 (or newer).
The ApplicationUserModelID (AppID in short), controls grouping of different
windows in the taskbar. Windows sharing a common AppID (inherited from a
process-wide value by default) are grouped together.
I have not tested this.
-
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?
Q: Is that hard to do?
A: No, making a shortcut is easy. Only you can have the problem you forget to make it, you don't make it right, you misplace it...
Q: Os it time-consuming?
A: For one project I need several shortcuts. I will do it faster than others, so let's say an average of 2 minutes.
Q: How much time would yuo save it you had a software tool that does it for you?
A: 2 minutes per project
Q: If you had a software tool that did that, how would it work?
A: As user you shouldn't see any differences comparing to a normal shortcut. Click it, and that takes you to the right folder.
Q: Describe is plain English, not symbols. Does each project have a unique name?
A: Each project has a unique number. No symbols, no letters
Q: Is the shortcut only a link to a folder location? Or is it sometimes a link to a file?
A: Yes, not to files, just to folders. Always the same folder, but every time in a different project.
Q: How many projects are active at one time?
A: We have +/- 750 projects every year
Q: Do you ever re-use project names?
A: No, it's always a new unique name (number)
I hoped there maybe was a relative easy solution for the problem. For what I hear now, it seems to be impossible or maybe with loads of work.
____________
To be sure you get the point of my question, I'll try to clear it one more time, but short and simple (I hope):
You have a template folder '100' with 2 subfolders 'A' and 'B'.
In subfolder 'A' there's a shortcut to subfolder 'B'
If I copy the the main folder and rename that to '200', the shortcut from subfolder 'A' to 'B' will be broken.
Is it possible to solve that, without manually changing this every time?
____________
Thank you Geek-9pm! I will definitely take a look and try it!
-
EDIT:
Ignore this. I am having a senior moment. I somehow got to thining you were using the command line.
You said:
You have a template folder '100' with 2 subfolders 'A' and 'B'.
In subfolder 'A' there's a shortcut to subfolder 'B'
If I copy the the main folder and rename that to '200', the shortcut from subfolder 'A' to 'B' will be broken.
Is it possible to solve that, without manually changing this every time?
Exactly! A Windows shortcut is always absolute reference that sticks to the original item. **
What you want is a relative link to a directory in a relative potion.
The CD (change directory) command can be either absolute or relative and might be what you want. Of course, CD can only change folders. It can not start a program.
CD only works at the command line.
** But others have found a workaround for this.
How to create a shortcut with relative path (https://answers.microsoft.com/en-us/windows/forum/windows_vista-files/how-to-create-a-shortcut-with-relative-path/3e1b0ede-1e18-4ecd-937b-66756d3409d3)
Also:
https://www.sevenforums.com/tutorials/400257-shortcut-create-relative-path.html
Both of these seem to be more trouble that it is worth.
Here is some information about the CD command.
https://www.computerhope.com/jargon/c/cd.htm
CD (Change Directory) is a command used to switch directories in MS-DOS and the Windows command line.
Some examples:
cd\ ... go to root
cd.. .. go back one level
cd /d e:\pics ... go to pics on e: but don't change position of current drive.
cd ..\job2 ... go one and find the job2 directory
A batch program sound contain the relative path to find a nearby directory.
By using only relative paths, the batch file only needs to be available on the current path.
That means only only batch file is needs to
-switch to Project B\relative while in Project A\relative.
SEE-B.bat
CD ..\ProjectB
If you were in D:\jogs\DoctorJones\ProjectA
It will flip you to:D:\jogs\DoctorJones\ProjectB
Still I do not understand if the user works with the commend line or i he uses the graphical display. CD command is only for command line.
I hope this might be of some help. :)
-
This is from dictation.
After getting some more thought to this, what you really want is the utility called startup.exe to create a set of Windows links when you create a new project for a client.
I assume you already have some kind of script or batch file that creates folders and populates the folders with basic information about how you work on a certain kind of project. The only item that is variable would be the client's name. All the items inside the project would have standard name did you use for the kind of work you do. So some kind of script file is what you are using to create a new project directory and populated with some stuff that is peculiar to your kind of work. The top folder apparently would be either the client's name or some kind of tag that references the client's name in a database.
Now that, the program utility called shortcut.exe would be used during the new project creation process to create the suitable links needed to all the relevant folders inside of the project. Of course, Windows links have to be absolute paths, with only a few exceptions for some of these system things.
Using a suitable script or batch program you can invoke the shortcut.exe program and give it the absolute parameters that is needed to create each shortcut. The script or batch program that you're using will be able to create the absolute paths based on the information you have provided at the beginning of a new project.
You might give a figure this out for yourself, or perhaps somebody else here wants to give you help with the syntax of the shortcut.exe program. The one I think you want is known as version 1.11. Here is a copy of the output from the command prompt when asking for help with the shortcut.exe program.
End of dictation.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
Shortcut.exe
S:\>shortcut
Shortcut [Version 1.11]
Creates, modifies or queries Windows shell links (shortcuts)
The syntax of this command is:
shortcut /F:filename /A:C|E|Q [/T:target] [/P:parameters] [/W:workingdir]
[/R:runstyle] [/I:icon,index] [/H:hotkey] [/D:description]
/F:filename : Specifies the .LNK shortcut file.
/A:action : Defines the action to take (C=Create, E=Edit or Q=Query).
/T:target : Defines the target path and file name the shortcut points to
/P:parameters : Defines the command-line parameters to pass to the target.
/W:working dir : Defines the working directory the target starts with.
/R:run style : Defines the window state (1=Normal, 3=Max, 7=Min).
/I:icon,index : Defines the icon and optional index (file.exe or file.exe,0)
/H:hotkey : Defines the hotkey, a numeric value of the keyboard shortcut
/D:description : Defines the description (or comment) for the shortcut.
Notes:
- Any argument that contains spaces must be enclosed in "double quotes".
- If Query is specified (/A:Q), all arguments except /F: are ignored.
- To find the numeric hotkey value, use Explorer to set a hotkey and then /A:
- To prevent an environment variable from being expanded until the shortcut
is launched, use the ^ carat escape character like this: ^%WINDIR^%
Examples:
/f:"%ALLUSERSPROFILE%\Start Menu\Programs\My App.lnk" /a:q
/f:"%USERPROFILE%\Desktop\Notepad.lnk" /a:c /t:^%WINDIR^%\Notepad.exe /h:84
/f:"%USERPROFILE%\Desktop\Notepad.lnk" /a:e /p:C:\Setup.log /r:3
An argument of /? or -? displays this syntax and returns 1.
A successful completion will return 0.
Copyright 2000-2005 Marty List, www.OptimumX.com
S:\>
http://www.optimumx.com/downloads.html
That is the best I can do for you. :)
-
Waaah!
Option 2 of this website you gave, did the trick for me!
https://www.sevenforums.com/tutorials/400257-shortcut-create-relative-path.html
For now it looks good... I'll test it a bit more, but, for now, it looks perfect for me!
Thank you, thank you, thank you!
(| (|
-
Glad I found this! I was looking for some sample code similar to this for something I am working on!
-
Glad you found something!
Perhaps the title to this thread ought to be:
How to Create Shortcut with Relative Path
Using that as a key phrase, you can Bing or Google for forums that consider this problem. As mentioned, relative shortcuts are the norm in HTML, but not Windows. A relative shortcut is a powerful tool, if you can get it.
The widows forum mentioned by Roely recommends:
Option One: Using a Symbolic Link
Option Two: Using a Shortcut of Window Explorer
Option Three: Using a Batch File
Option Four: Using a Visual Basic Script
Again, that Link:
https://www.sevenforums.com/tutorials/400257-shortcut-create-relative-path.html
I admit, this is very deep stuff for me. :-[
-
Glad you found something!
Perhaps the title to this thread ought to be:
How to Create Shortcut with Relative Path
Using that as a key phrase, you can Bing or Google for forums that consider this problem. As mentioned, relative shortcuts are the norm in HTML, but not Windows. A relative shortcut is a powerful tool, if you can get it.
Yes, sorry... I didn't know how to name the problem. That's probably why I couldn't find a good solution.
Glad this topic could already help another user. :)
We're very thankful for you're effort and time!