Author Topic: Shell Menu for Network Users (ie non HFS host computers)  (Read 1088 times)

0 Members and 1 Guest are viewing this topic.

Offline Edward-US

  • Occasional poster
  • *
  • Posts: 4
    • View Profile
Shell Menu for Network Users (ie non HFS host computers)
« on: August 23, 2012, 07:58:12 PM »
Hey came across this program the other day and have been very impressed.

I thought Id share a solution to add a shell menu (right click menu) to other computers on the same network so that they can right click on a file (located on a network drive and within a folder that HFS is sharing) to copy the public link for a file that HFS is hosting.

My Setup
My set up has HFS running on a subdomain of my site: ie
It runs on a Windows Storage Server 2008.
The storage server shares a folder called transfer that all users on the network can access via a mapped drive that is T: for them. Transfer has 2 folders: Download and Upload.
On HFS, it hosts the Transfers folder as a real folder. 
Thus when any user on the network places a file in t:\downlaods\ HFS shares it.

The point of this shell menu is to allow that user to right click on the file and copy its public web address. So if a network user right clicks on t:\downloads\TestFolder\testfile.txt they can click 'copy share link' and it will copy to their clipboard which can then be pasted in an email.

I got a bulk of the idea and coding from the great person who wrote an article on how they made a shell copy file path program. This guys program just copied the straight file path and I modified his code so that it replaced part of the file path with the http link.

So my .reg files to install the registry entries for the shell context menu were:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\Shell\Copy File SHARE Link\Command]
@="\"C:\\Program Files\\Copy Filename\\sharelink.exe\" \"%1\""

[HKEY_CLASSES_ROOT\Directory\Shell\Copy Folder SHARE Link\Command]
@="\"C:\\Program Files\\Copy Filename\\sharelink.exe\" \"%1\""

I downloaded VB express 2010 for free from microsoft and wrote my module like this: (note my module accounts for whther people access the share via the mapped drive t: or using the straight UNC path \\storage... the program allows notifies them if they are attempting to copy the share link for a file that isnt in a directory that HFS is serving which it determines based on the first 12 characters of the path)
Module Module1
    Sub Main()
        Dim strPathname As String
        Dim errCheck As String

        strPathname = Command()
      'sets this string variable to the full file path which contains " around it
        strPathname = Right(Command, Len(Command) - 1)
       'deletes the right "
        strPathname = Left(strPathname, Len(Command) - 2)
      'deletes the left quote leaving the string as just the straight file path
  errCheck = Left(strPathname, 12)   
'the following makes sure the user is using a file that is actually in the directory shared by HFS based on first 12 characters of the file path
  If (errCheck <> "T:\Downloads") Then
            If (errCheck <> "\\storage\tr") Then
                MsgBox("You have not placed this file or folder in the correct location. To make it publicly downloadable on,  you must place the file in a folder with in T:\downloads\ (aka \\storage\transfer\Downloads\ ).", MsgBoxStyle.Exclamation, "Share Error! " + errCheck)
            End If
        End If
'error check done- the program replaces the beginning of the actual file path and substitutes mysites public address.
strPathname = Replace(strPathname, "\\storage\transfer\Download", "")
        Replace(strPathname, "T:\Download", "")
'it then flips all the \ in the file path and makes them / for http addresses
        strPathname = Replace(strPathname, "\", "/")
'then it copies the string to the clipboard       
    End Sub
End Module

I then wrote this code on the form that loads first so that it invokes the module:
Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

Then compiled as sharelink.exe and placed it in C:\Program Files\Copy Filename\sharelink.exe (note it must be in this directory per the registry file I made) See the article I based my work on for more explanation on all this. I next plan to install the reg file and the exe via group policy to all the domain computers.

Let me know if you have any questions. I am a very basic programmer but I'll do my best to help.

Offline rejetto

  • Administrator
  • Insane programmer
  • *
  • Posts: 12844
    • View Profile
Re: Shell Menu for Network Users (ie non HFS host computers)
« Reply #1 on: August 26, 2012, 07:57:45 AM »
nicely done, Ed.

Maybe i would have tried using a VBS instead of VB, so you wouldn't need the compiler and any change would be easier.