Thursday, June 17, 2010

Remote Share

Introduction

Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares.
They application is written in VB.NET targeting the .NET framework 2.0.


Usage

Enter a computername, Share Name, Share Path and Share Description if needed

You can get a list of shares by pressing the Show button
You can Create a share if the necessary information has been filled in by pressing Create
You can Remove a share by selecting the share and pressing Remove
You can Open the share by dubbleclicking on the share listed in the listbox



Screenshots


GUI Version Remote Share






Commandline Version Remote Share

 


Main Functions
   Public Sub CreateShare(ByVal strShareName As String, ByVal strPath As String, ByVal computername As String, ByVal shareinfo As String)
        Try
            Dim objSWbemServices As Object
            Dim objSWbemObject As Object
            Dim colSWbemObject As Object
            Dim intRet As Integer
            Dim blnExists As Boolean
            Dim objSWbem As Object
 
            objSWbemServices = GetObject("winmgmts://" + computername + "/root/cimv2")
 
            colSWbemObject = objSWbemServices.InstancesOf("Win32_Share")
 
            For Each objSWbem In colSWbemObject
                If (objSWbem.name = strShareName) Then
                    blnExists = True
                    Exit For
                Else
                    blnExists = False
                End If
            Next
 
            If (blnExists = False) Then
                objSWbemObject = objSWbemServices.Get("Win32_Share")
                intRet = objSWbemObject.Create(strPath, strShareName, 0, 25, shareinfo)
            Else
                MsgBox("Folder aready shared")
            End If
        Catch ex As Exception
            MsgBox("Error occured while trying to create shares on remote pc." + vbCrLf + "Check if you have the necessary rights and/or that the pc is turned on." + vbCrLf + ex.ToString)
        End Try
 
    End Sub
    '
    Public Function ShowShares(ByVal ComputerName) As Boolean
        Try
            ListView1.Items.Clear()
            Dim objSWbemServices As Object
            Dim colSWbemObject As Object
            objSWbemServices = GetObject("winmgmts://" + ComputerName + "/root/cimv2")
            colSWbemObject = objSWbemServices.InstancesOf("Win32_Share")
            ' Loop through each share on the machine to see if it already exists 
            For Each objSWbem In colSWbemObject
                Dim lvitem As New ListViewItem
                With lvitem
                    .Text = objSWbem.name
                    .SubItems.Add(objSWbem.path)
                    .SubItems.Add(objSWbem.description)
                End With
                ListView1.Items.Add(lvitem)
            Next
        Catch ex As Exception
            MsgBox("Error occured while trying to show shares on remote pc." + vbCrLf + "Check if you have the necessary rights and/or that the pc is turned on." + vbCrLf + ex.ToString)
        End Try
 
    End Function
 
    Public Function RemoveShare(ByVal shareName As String, ByVal computername As String) As Boolean
        Try
            Dim objSWbemServices As Object
            Dim objSWbemObject As Object
            Dim colSWbemObject As Object
 
            objSWbemServices = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & computername & "\root\cimv2")
            colSWbemObject = objSWbemServices.ExecQuery("SELECT * FROM Win32_Share WHERE Name = '" + shareName + "'")
            For Each objSWbemObject In colSWbemObject
                objSWbemObject.Delete()
            Next
        Catch ex As Exception
            MsgBox("Error occured while trying to remove shares on remote pc." + vbCrLf + "Check if you have the necessary rights and/or that the pc is turned on." + vbCrLf + ex.ToString)
        End Try
 
    End Function


Files
Download Remote Share GUI
Download Remote Share

Source Files (VB.NET 2008)
Download Source Remote Share GUI
Download Source Remote Share

Posts
Article Posted on Expert Exchange
Article Posted on CodeProject



Sunday, June 13, 2010

UseFull Functions

UseFull VB.NET Functions : GetLongName

#Region " Short Path Name Conversion "
 
    Declare Function GetLongPathName Lib "kernel32" Alias "GetLongPathNameA" (ByVal lpszShortPath As String, ByVal lpszLongPath As String, ByVal cchBuffer As Integer) As Integer
 
    Public Function GetLongName(ByVal sShortFileName As String) As String
        Dim lRetVal As Long, sShortPathName As String, iLen As Integer
        'Set up buffer area for API function call return
        sShortPathName = Space(255)
        iLen = Len(sShortPathName)
        'Call the function
        lRetVal = GetLongPathName(sShortFileName, sShortPathName, iLen)
        'Strip away unwanted characters.
        Return Left(sShortPathName, lRetVal)
    End Function
#End Region

Just another day

Just another day has started.
Monday again, the whole week in front of me.
The weight of the days is noticeable pressing on my shoulders.
What can we expect this week? What will go wrong?
Shall I be able to do something meaningful?
Only time will tell, for the moment I'm hanging on.
Looking forward, never looking back.
Just hoping the week will pass me by as the weekend did, in the wink of an eye!

K.