Some years ago I wrote this routine (in VB 6 at the time). It should be fairly simple to re-write it using .Net Framework.
Alex. ' ----------------------------------------------------------------------- ' returns local path to a share ' given Server and Share NAMES Option Explicit Public Declare Function NetShareGetInfo Lib "netapi32" ( _ ByVal lpServerName As Long, _ ByVal lpShareName As Long, _ ByVal dwLevel As Long, _ lpBuffer As Any) As Long Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long) Public Declare Function lstrlenW Lib "kernel32" (ByVal PointerToString As Long) As Long Public Function GetShareLclPath(ByVal srvName As String, ByVal shrName As String) As String On Error GoTo ErrHandler Dim ret As Long Dim lpBuffer As Long ret = NetShareGetInfo(StrPtr(srvName), StrPtr(shrName), 2, lpBuffer) If ret <> 0 Then Err.Raise Err.Number GetShareLclPath = PointerToStringW(PointerToDWord(lpBuffer + 24)) Exit Function ErrHandler: MsgBox "Either server or share is not found or you have insufficient permissions.", vbExclamation End Function Public Function PointerToStringW(ByVal lpStringW As Long) As String Dim Buffer() As Byte Dim nLen As Long If lpStringW Then nLen = lstrlenW(lpStringW) * 2 If nLen Then ReDim Buffer(0 To (nLen - 1)) As Byte CopyMemory Buffer(0), ByVal lpStringW, nLen PointerToStringW = Buffer End If End If End Function Public Function PointerToDWord(ByVal lpDWord As Long) As Long Call CopyMemory(PointerToDWord, ByVal lpDWord, 4) End Function ' ----------------------------------------------------------------------- -----Original Message----- From: Discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Graeme Taylor Sent: 09 February 2007 11:59 To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM Subject: [ADVANCED-DOTNET] Retrieve Disk Space on Server Share I am currently writing a small application that checks various Hi All, I am currently writing a small application that checks various servers (e.g. can be pinged / db can be connected to / heartbeat files are being written etc). I would also like to check for free disk space (if this isn't possible then disk space used) on a server, using a share name (e.g. \\myServer\MyShare). I think I'm safe to assume that all servers (that my app will run on and that it's monitoring) will be Windows Server 2003. My application will not run on the server I'm checking and the account will not have permission to read any of the perforanace counters on the server (This rules out the System.Management classes?). I've been asking my mate Google for a day or so but haven't come up with anything! Does anyone have a sample or at least a steer in the right direction? Grateful for any advice, Graeme PS Using c# / VS 2005 ___________________________________________________________ New Yahoo! Mail is the ultimate force in competitive emailing. Find out more at the Yahoo! Mail Championships. Plus: play games and win prizes. http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk =================================== This list is hosted by DevelopMentorR http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com