Connect Network Drive with Remote Autentication (VBA or Shell)

  • Nel caso di utilizzo shell

    :: Se esiste network drive F:
    if exist F:\ (
    :: Eliminazione network drive, forzato nel caso di file aperti (/y)
        net use /delete /y F:
    )
    
    :: Creazione network drive
    :: net use F: \\192.168.5.210\diskQ /user:acme\tom 67y3nhde
    net use F: \\192.168.5.210\sharename /user:dom\username password
    
    pause
    
  • Di seguito uno script per il collegamento dei network drive, con autenticazione di un utente remoto.

    '*** MAPPING NETWORK DRIVES ********************************************************************
    
    'Chiamata di funzione, disconnessione di TUTTI i network drives.
    
    Call DisconnetAllNetworkDrives
    
    
    ' Chiata di funzione, collegamento network drive. 
    '(Attenzione utilizzare l'indirizzo IP del server, altrimenti con il nome host si genera errore 800704C3 connessioni multiple)
    ' http://answers.microsoft.com/it-it/windows/forum/windows_8-files/errore-di-windows-8-le-connessioni-multiple-a-un/f72f529f-450c-41a0-8f18-8f67d2317571?msgId=1f2f4dc3-8553-49d0-898d-721eb170462b
    
    Call Connectdrive("R:","\\192.168.1.5\share1","nome_utente","password")
    
    
    MsgBox "Unità di rete mappate.", vbInformation
    
    
    'Funzione che rimuove tutti i network drives.
    'http://blogs.technet.com/b/heyscriptingguy/archive/2005/09/15/how-can-i-use-a-logon-script-to-remove-all-mapped-drives.aspx
    
    Function DisconnetAllNetworkDrives
    
      Set objNetwork = CreateObject("Wscript.Network")
    
      Set colDrives = objNetwork.EnumNetworkDrives
    
      For i = 0 to colDrives.Count-1 Step 2
    
          'object.RemoveNetworkDrive Device [, Force] [, UpdateProfile] 
    
          objNetwork.RemoveNetworkDrive colDrives.Item(i), True, False
      Next
    
    End function
    
    'Funzione che connette il drive
    'http://ss64.com/vb/drivemap.html
    
    Function Connectdrive(strDrive,strPath, strUser, strPassword)
      Dim objNetwork 
    
      Set objNetwork = CreateObject("WScript.Network") 
      objNetwork.MapNetworkDrive strDrive, strPath, False, strUser, strPassword
    
      Set objNetwork = nothing
    End function
    
This entry was posted in Operating Systems, Programming Languages, VBScript, Windows. Bookmark the permalink.