Newsgroup: it.comp.appl.access
Titolo: Cartelle protette da nome utente e password

Come potrei fare per accere a dei files presenti in un server Win2000, 
protetto con nome utente e password, senza comunicare la password gli 
operatori, e senza farla memorizzare a WinXP?

 operatori, e senza farla memorizzare a WinXP?
Brutto affare....
Io ho trovato come soluzione solo quella di Mappare temporaneamente le
Cartelle come USER(abilitato)
solo all'esigenza e l'immediata rimozione della Mappatura appena terminato
l'utilizzo.
Ti dico questo sapendo che è una porcata... da non fare ma alla quale non ho
trovato alternative.
-- 
@Alex (Alessandro Baraldi)
---------------------------------------------------------------------------
http://www.sitocomune.com/
http://www.alessandrobaraldi.it
---------------------------------------------------------------------------


Ho notato che la funzione Rnd(-1) genera sempre lo stesso numero decimale a
6 cifre.
Da qui a ricavare un'altro numero che generi la tua password non dovrebbe
essere difficile.
E una volta nascosto il codice ....
Ciao

 ha scritto nel messaggio 
news:fnknb0$uuv$1...@aioe.org...

E' vero, è veramente un brutto affare...
o le mappo, o non so come evitare che qualcuno cancelli queste immagini dal 
server...
Per mapparle come dovrei fare? 

 Per mapparle come dovrei fare?
Guarda ti passo il codice che provai a suo tempo ...
Hai 2 tipi di metodo:
1) API
2) WMI
Per il 1° credo abbia problemi con VISTA considerando che UAC blocca le
chiamate a basso livello
Per il 2° c'è un problema di sicurezza visto che per usare WMI serve
abilitare DCOM, e se ci sono FireWall
di mezzo sono dolori...!
QUESTO E' TUTTO IL CODICE(l'ho usato 3 anni fà, ma ho il vizio di mettere
molti commenti
quindi dovresti essere in grado di comprendere....):
Option Compare Database
Option Explicit
'
http://support.microsoft.com/?kbid=173011
'===========================================================================
==================
'                       MAPPING DRIVES WITH API
'===========================================================================
==================
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2005 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce
'               or publish this code on any web site,
'               online service, or distribute as source
'               on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Type NETRESOURCE
   dwScope       As Long
   dwType        As Long
   dwDisplayType As Long
   dwUsage       As Long
   lpLocalName   As String
   lpRemoteName  As String
   lpComment     As String
   lpProvider    As String
End Type
'----------------------------------------------
'WNetAddConnection2
'Allows the caller to redirect (connect) a local
'device to a network resource. It is similar to
'WNetAddConnection, except that it takes a pointer
'to a NETRESOURCE structure to describe the network
'resource to connect to. It also takes the addition
'parameters lpUserID and dwFlags.
'lpNetResource
'Specifies the network resource to connect to.
'The following fields must be set when making a
'connection, the others are ignored.
'  lpRemoteName: Specifies the network resource
'                to connect to. This is limited
'                to MAX_PATH.
'  lpLocalName: This specifies the name of a local
'               device to be redirected, such as "F:"
'               or "LPT1". The string is treated in a
'               case insensitive manner, and may be
'               the empty string (or NULL) in which
'               case a connection to the network resource
'               is made without making a redirection.
'  lpProvider: Specifies the NP to connect to. If NULL
'              or empty string, Windows will try each
'              NP in turn. The caller should set
'              lpProvider only if it knows for sure
'              which network it wants. Otherwise, it
'              is preferable to let Windows determine
'              which NP the network name maps to.
'              If this is non NULL, Windows will try
'              the named NP and no other.
'  dwType: Specifies the type of resource to connect to.
'          It must be RESOURCETYPE_DISK or RESOURCETYPE_PRINT
'          if lpLocalName is not the empty string. It may
'          also be RESOURCETYPE_ANY if lpLocalName is the
'          empty string.
'lpPassword
'Specifies the password to be used in making the
'connection, normally the password associated with
'lpUserID. A NULL value or string may be passed in
'to indicate to the function to use the current
'default password.
'
'lpUserID
'This specifies the identity of the user needed to
'make the connection. If NULL, a default will be
'applied. This is used when the user wishes to connect
'to a resource, but has a different user name or
'account assigned to him for that resource. This
'identification represents a security context, and
'is NP specific.
'
'dwFlags
'This is a bit mask which may have any of the
'following bits set:
'
'  CONNECT_UPDATE_PROFILE: If the connection should
'                          be made persistent. If set,
'                          Windows automatically restores
'                          this connection when the user
'                          logs on to the network. A connection
'                          is only made persistent if the
'                          connection was successful.
Private Declare Function WNetAddConnection2 Lib "mpr" _
    Alias "WNetAddConnection2A" _
   (lpNetResource As NETRESOURCE, _
    ByVal lpPassword As String, _
    ByVal lpUserName As String, _
    ByVal dwFlags As Long) As Long
Private Declare Function WNetCancelConnection2 Lib "mpr" _
    Alias "WNetCancelConnection2A" _
   (ByVal lpName As String, _
    ByVal dwFlags As Long, _
    ByVal fForce As Long) As Long
Private Const ERROR_SUCCESS = 0
Private Const CONNECT_UPDATE_PROFILE = &H1
' The following includes all the constants defined for NETRESOURCE,
' not just the ones used in this example.
Private Const RESOURCETYPE_DISK = &H1
Private Const RESOURCETYPE_PRINT = &H2
Private Const RESOURCETYPE_ANY = &H0
Private Const RESOURCE_CONNECTED = &H1
Private Const RESOURCE_REMEMBERED = &H3
Private Const RESOURCE_GLOBALNET = &H2
Private Const RESOURCEDISPLAYTYPE_DOMAIN = &H1
Private Const RESOURCEDISPLAYTYPE_GENERIC = &H0
Private Const RESOURCEDISPLAYTYPE_SERVER = &H2
Private Const RESOURCEDISPLAYTYPE_SHARE = &H3
Private Const RESOURCEUSAGE_CONNECTABLE = &H1
Private Const RESOURCEUSAGE_CONTAINER = &H2
' Error Constants:
Private Const ERROR_ACCESS_DENIED = 5&
Private Const ERROR_ALREADY_ASSIGNED = 85&
Private Const ERROR_BAD_DEV_TYPE = 66&
Private Const ERROR_BAD_DEVICE = 1200&
Private Const ERROR_BAD_NET_NAME = 67&
Private Const ERROR_BAD_PROFILE = 1206&
Private Const ERROR_BAD_PROVIDER = 1204&
Private Const ERROR_BUSY = 170&
Private Const ERROR_CANCELLED = 1223&
Private Const ERROR_CANNOT_OPEN_PROFILE = 1205&
Private Const ERROR_DEVICE_ALREADY_REMEMBERED = 1202&
Private Const ERROR_EXTENDED_ERROR = 1208&
Private Const ERROR_INVALID_PASSWORD = 86&
Private Const ERROR_NO_NET_OR_BAD_PATH = 1203&
Private Declare Function GetLogicalDriveStrings Lib "kernel32" _
   Alias "GetLogicalDriveStringsA" _
  (ByVal nBufferLength As Long, _
   ByVal lpBuffer As String) As Long
Public Function ConnectNextFreeNetworkDrive(sServer As String) As String
   ' Questa funzione cerca di Mappare una risorsa del SERVER
   ' ciclando le lettere da C÷Z nella speranza di trovare una Risorsa
   ' libera.
   '
   '----------------------- ESEMPIO DI CHIAMATA ------------------------
   '
   '  Call ConnectNextFreeNetworkDrive("\\Server\SharedFolder"
   '
   '--------------------------------------------------------------------
   Dim NETR As NETRESOURCE
   Dim errInfo As Long
   Dim x As Long
   Dim testDrv As String
  ' Imposta la prima lettera disponibile a C (ASCII 67) in realtà da 68
  ' come si vedrà poi, quindi se già esistente incrementa di uno
  ' fino alla Z (ASCII 90).
  ' Ne troverà uno libero....!!!
   x = 67
   Do
     ' Incrementa la Lettera del DRIVE di 1 ma partiremo da "D"
      x = x + 1
      testDrv = Chr$(x) & ":"
      With NETR
         .dwScope = RESOURCE_GLOBALNET
         .dwType = RESOURCETYPE_DISK
         .dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
         .dwUsage = RESOURCEUSAGE_CONNECTABLE
         .lpRemoteName = sServer
         .lpLocalName = testDrv
      End With
      ' Impostare la PASSWORD e lo USERNAME
      ' La PWD può essere passata come vbNullstring
      errInfo = WNetAddConnection2(NETR, _
                                   "Password", _
                                   "username", _
                                   CONNECT_UPDATE_PROFILE)
   Loop Until x = 90 Or errInfo = ERROR_SUCCESS   '90 = "z"
   ' Se avrà successo verrà restituita la lettera del DRIVE
   If errInfo = ERROR_SUCCESS Then
      ConnectNextFreeNetworkDrive = testDrv
   Else
      MsgBox "ERRORE: " & errInfo & " - Connessione di Rete Falita !",
vbCritical, "AVVISO"
      ConnectNextFreeNetworkDrive = "NONE"
   End If
End Function
Public Function RemoveNetworkDrive(strDrive As String) As Boolean
   Dim errInfo As Long
   ' Questa funzione rimuove la risorsa mappata passando
   ' la lettera del DRIVE, e verificandone l'esistenza.
   '----------------------- ESEMPIO DI CHIAMATA ------------------------
   '
   '  Call RemoveNetworkDrive("H:")
   '
   '--------------------------------------------------------------------
   If DriveExists(strDrive) Then
      errInfo = WNetCancelConnection2(strDrive, vbNullString,
CONNECT_UPDATE_PROFILE)
      RemoveNetworkDrive = errInfo = ERROR_SUCCESS
   End If
End Function
Private Function DriveExists(SDrive As String) As Boolean
   ' Questa funzione verifica l'esistenza del DRIVE
   Dim tmp As String
   Dim nBuffersize As Long
  'Call the API with a buffer size of 0.
  'The call fails, and the required size
  'is returned as the result.
   nBuffersize = GetLogicalDriveStrings(0&, tmp)
  'pad a string to hold the results
   tmp = Space$(nBuffersize)
   nBuffersize = Len(tmp)
  'and call again
   If GetLogicalDriveStrings(nBuffersize, tmp) Then
     'if the drive letter passed is in
     'the returned logical drive string,
     'return True. Use vbTextCompare for
     'a case-insensitive match (remembering
     'that when a compare method is specified,
     'the start position must also be specified.
      DriveExists = InStr(1, tmp, SDrive, vbTextCompare)
   End If
End Function
'===========================================================================
==================
'     QUESTE FUNZIONI REALIZZANO LA STESSA PROCEDURA API SOPRACITATA MA CON
WMI
'                       MAPPING DRIVES WITH WMI
'===========================================================================
==================
' Mappa una Risorsa di RETE
Public Function MapNetworkDrive(sServer As String) As String
   Dim WshNetwork
   Dim allDrives
   Dim i                   As Integer
   Dim x                   As Integer
   Dim AlreadyConnected    As Boolean
   Dim mDrive              As String
   Set WshNetwork = CreateObject("WScript.Network")
   Set allDrives = WshNetwork.EnumNetworkDrives()
   ' Anche quì cicleremo le lettere Mappate con la speranza
   ' di trovarne una libera e partiremo da ASCII 68=D
   AlreadyConnected = False
   For x = 68 To 90
      mDrive = Chr(x)
      AlreadyConnected = DriveExist(mDrive)
      If AlreadyConnected = False Then
         ' Impostare la PASSWORD e lo USERNAME
         ' La PWD può essere passata come vbNullstring
         WshNetwork.MapNetworkDrive mDrive & ":", sServer, "Utente",
"password"
         'MsgBox "Drive " & DriveLetter & " connected successfully."
         MapNetworkDrive = mDrive
         Set WshNetwork = Nothing
         Set allDrives = Nothing
         Exit Function
      End If
   Next
   Set WshNetwork = Nothing
   Set allDrives = Nothing
   MapNetworkDrive = vbNullString
   MsgBox "Attenzione la risorsa Server non è mappata", vbCritical, "AVVISO"
End Function
Public Function RemoveMapNetwork() As Boolean
   Dim WshNetwork
   Dim allDrives
   Set WshNetwork = CreateObject("WScript.Network")
   Set allDrives = WshNetwork.EnumNetworkDrives
   ' Se non esiste nessuna risorsa mappata non proseguo
   If allDrives.Count = 0 Then
      MapDrive = vbNullString
   End If
   If DriveExist(MapLetter) Then WshNetwork.RemoveNetworkDrive MapDrive
Exit_Here:
   Set WshNetwork = Nothing
   Set allDrives = Nothing
End Function
Public Function DriveExist(strLetter As String) As Boolean
   Dim fso, d, dc
   DriveExist = False
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set dc = fso.Drives
   For Each d In dc
   Set d = fso.GetDrive(d.DriveLetter)
       If d.DriveLetter = strLetter Then
          DriveExist = True
          Exit Function
       End If
   Set d = Nothing
   Next
   Set d = Nothing
   Set dc = Nothing
   Set fso = Nothing
End Function
