My objective is to create a hyperlink that can function on various devices, not just my own. Here’s an example of a hyperlink that works for me:
C:\Users\bob\text.txt
Nonetheless, the hyperlink won’t operate for individuals utilizing a computer that lacks a user account with the name “bob.”
Is there a method to substitute the username with the presently logged-in user? Here’s an instance:
C:\Users\{current_user}\test.txt
I discovered the %USERPROFILE%
option, but it doesn’t function as a solution.
To provide some context, our SharePoint 365 is available to everyone, and I want to generate hyperlinks to folders within the SharePoint that they have permission to access. These hyperlinks would open the file or file explorer. Currently, we have to create a share link that opens the file in a browser, which isn’t the ideal solution.
2 Answers
As per the Fundamental theorem of software engineering, any problem can be solved by adding an additional layer of indirection. Now, let’s explore how we can redirect a Microsoft Office hyperlink to something that supports environment variables.
To do this, we’ll create a batch file that includes the following code:
%SystemRoot%\explorer.exe %userprofile%\test.txt
Save this file on the network in a location that all users can access. For instance, let’s assume that it’s been saved as N:\OpenProfile.bat
.
To generate the hyperlink, make it point to either N:\\OpenProfile.bat or file:///N://OpenProfile.bat
.
(However, this approach is not scalable as a separate batch file would be required for each target file.)