Les Snippets

Connexion

Retrouver le chemin UNC d'un lecteur réseau.

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 26/02/2007 20:46:51 et initié par Willi [Liste]
Date de mise à jour : 26/02/2007 20:51:48
Vue : 12764
Catégorie(s) : Fichier / Disque
Langages dispo pour ce code :
- C# 1.x, C# 2.x
- VB6, VBA



Langage : C# 1.x , C# 2.x
Date ajout : 26/02/2007
Posté par Willi [Liste]
DateMAJ : 26/02/2007
[DllImport("shlwapi.dll", SetLastError = true, CharSet = CharSet.Auto)] 
public static extern bool PathIsNetworkPath([MarshalAs(UnmanagedType.LPTStr)]string pszPath);
[DllImport("mpr.dll", SetLastError = true, CharSet = CharSet.Auto, EntryPoint = "WNetGetConnectionW")] 
public static extern int WNetGetConnection([MarshalAs(UnmanagedType.LPWStr)]string lpLocalName, StringBuilder lpRemoteName, ref int lpnLength);

public string GetUNCPath(string NetworkPath) 
{

  string szRoot = NetworkPath.Substring(0, 2);
  string szPath = NetworkPath;
  if (PathIsNetworkPath(szPath)) 
  {

     StringBuilder szbUNC = new StringBuilder(260);
     int iLength = 260;
     if (WNetGetConnection(szRoot, szbUNC, ref iLength) == ERROR_SUCCESS)
    {
       szPath = Path.Combine(szbUNC.ToString(), Path.GetFileName(szPath)); 
    }

  }
   return szPath;
}





Remarque :
ajoutez les directives
using System.Text;
using System.Runtime.InteropServices
Langage : VB6 , VBA
Date ajout : 23/04/2008
Posté par PCPT [Liste]
Private Const NO_ERROR As Long 0&
Private Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName As StringByVal lpszRemoteName As String, cbRemoteName As Long) As  Long
Function GetUNCPath(ByVal sDrive As String) As String
    Dim sBuffer As String
    sBuffer = String(255&, vbNullChar)
    
    If WNetGetConnection(sDrive, sBuffer,  Len(sBuffer)) = NO_ERROR  Then
        GetUNCPath = Left$(sBuffer, InStr(1, sBuffer,  vbNullChar) - 1)
    Else
        GetUNCPath = vbNullString
    End If
End Function


Snippets en rapport avec : Chemin, Unc, Reseau



Codes sources en rapport avec : Chemin, Unc, Reseau

{Visual Basic, VB6, VB.NET, VB 2005} DISTRIBUTED FILE SYSTEM EXPLORER : PARCOURIR LA CONFIGURATION DE VOS PARTAGE DE FICHIERS UNIFIÉS
Ce code permet de lister les partages DFS (Distributed File System) du domaine de l'utilisateur. DFS...

{C# / C#.NET} DISTRIBUTED FILE SYSTEM EXPLORER : PARCOURIR LA CONFIGURATION DE VOS PARTAGE DE FICHIERS UNIFIÉS
Ce code permet de lister les partages DFS (Distributed File System) du domaine de l'utilisateur. DFS...

{Visual Basic, VB6, VB.NET, VB 2005} SHARE MONITOR : LISTER LES PARTAGES RÉSEAUX D'UNE MACHINE, LES FICHIERS OUVERTS ET LES FERMER
Ce code permet pour un serveur donné de : -> lister drive mapping (lecteur mappés) (http://msdn.mic...

{C# / C#.NET} SHARE MONITOR : LISTER LES PARTAGES RÉSEAUX D'UNE MACHINE, LES FICHIERS OUVERTS ET LES FERMER
Ce code permet pour un serveur donné de : -> lister drive mapping (lecteur mappés) (http://msdn.mic...

{JAVA / J2EE} ALGORITHME DE DIJKSTRA
Il s'agit de l'implémentation de l'algorithme de Dijkstra à partir d'un graphe orienté à valuation p...

{C / C++ / C++.NET} MINI SERVEUR HTTP [WINDOWS]
Ce serveur http(s) multi clients gère les méthodes GET, HEAD et POST du protocole http, il gère égal...

{PHP} EXEMPLE D'APPLICATION DE L'ALGORITHME DE DIJKSTRA EN PHP
Comme je n'ai pas trouvé d'exemple qui implémente Dijkstra en php je me suis créé un petit programme...

{JAVA / J2EE} PROGRAMME DE PARTAGE DE FICHIER EN RESEAUX
ce programme de s’échanger les des fichiers en réseaux. Il suffit d'indiquer les adresses IP ...

{C / C++ / C++.NET} SECURE REMOTE SHELL [WIN32]
Programme client/serveur (multi-clients) pour exploiter a distance, via le réseau, un processus cmd....

{C / C++ / C++.NET} COPIE DE FICHIERS PAR RESEAU LOCAL
Ce petit logiciel d'à peine 100 ko permet de copier vos fichier et vos dossiers d'un endroit à un au...