rejetto forum

Shell Menu for Network Users (ie non HFS host computers)

0 Members and 1 Guest are viewing this topic.

Offline Edward-US

  • Occasional poster
  • *
    • Posts: 4
    • View Profile
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 transfer.mysite.com
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 http://transfer.mysite.com/downloads/testfolder/testfile.txt which can then be pasted in an email.

Instructions
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. http://www.gnostice.com/nl_article.asp?id=168 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 transfer.mysite.com,  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", "http://transfer.mysite.com/download")
        Replace(strPathname, "T:\Download", "http://transfer.mysite.com/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       
        Clipboard.Clear()
        Clipboard.SetText(strPathname)
    End Sub
End Module

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

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Hide()
        Module1.Main()
        Me.Close()

    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
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
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.