Announcement

Collapse
No announcement yet.

Map network drive and check every 10 mins

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Map network drive and check every 10 mins

    Hi is there a way i can sript a batch file to map a network drive and then check every 10 minuties it is mapped, if not remap again

    i can do the 1st part which is easy, stuck on the second part which check every so often and remaps if not connected

    Many thanks in advance

  • #2
    Re: Map network drive and check every 10 mins

    If there is a way to do it in a batch file it is listed on this site:

    http://www.robvanderwoude.com/batchfiles.html

    I use it a lot as a reference for batch, vbscript, ...


    On the other hand, I would think about using vbscript, and the task scheduler.
    With vbscript, you can check for the existance of the mapping, and if not, map it.
    And with the task scheduler you will be able to, ...ehm, schedule the script to run every 10 minutes.

    Hope this helps...
    Semper in faecibus sumus, sole profundum variat

    Comment


    • #3
      Re: Map network drive and check every 10 mins

      What could be the course of mapped drives get disconneted?
      [?]


      If you want to check every 10 minutes, use task scheduler.
      Code:
      ::::::::::::::::::::::::::::::::::::::::::
      Set "DriveLetter=q:"
      Set "sUNC=\\server\folder"
      
      If Not exist %DriveLetter% (
        Net Use %DriveLetter% %sUNC%  /persistent:no
      )
      ::::::::::::::::::::::::::::::::::::::::::
      To be sure the driveletter (q:) is connectected to the right unc-path, you can create a checkfile in the location: [* see EDIT !]
      Code:
      ::::::::::::::::::::::::::::::::::::::::::
      Set "DriveLetter=q:"
      Set "sUNC=\\server\folder"
      
      If Not exist %DriveLetter%\checkfile (
        If Not exist %DriveLetter% (
            Net Use %DriveLetter% %sUNC%  /persistent:no
        ) Else (
            cd/d %SystemDrive%\
            Net Use %DriveLetter% /Delete /Yes &&(
            Ping 127.0.0.1 -n 3 >Nul
            Net Use %DriveLetter% %sUNC%  /persistent:no
            )||(
            cls & echo Warning, %DriveLetter% is not! available to make the drive mapping
            pause >Nul
            )
        )
      )
      ::::::::::::::::::::::::::::::::::::::::::
      \Rems


      -=EDIT=-

      Here is a batch that also can check if the driveletter is in use and whether it is mapped to the correct folder - This batch does not use a "checkfile", instead it checks the current state of the drive.

      Code:
      ::::::::::::::::::::::::::::::::::::::::::
      Set "DriveLetter=q:"
      Set "sUNC=\\server\folder"
      
      (Net Use %DriveLetter% |Find/i "%sUNC%")>Nul,2>&1,||(
        If Not exist %DriveLetter% (
            Net Use %DriveLetter% %sUNC%  /persistent:no
        ) Else (
            cd/d %SystemDrive%\
            Net Use %DriveLetter% /Delete /Yes &&(
              Ping 127.0.0.1 -n 3 >Nul
              Net Use %DriveLetter% %sUNC%  /persistent:no
            )||(
              cls & echo Warning, %DriveLetter% is not! available to make the drive mapping
              pause >Nul
            )
        )
      )
      ::::::::::::::::::::::::::::::::::::::::::
      Last edited by Rems; 21st May 2008, 16:20.

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment


      • #4
        Re: Map network drive and check every 10 mins

        Maybe this script will also help:

        Code:
        Option Explicit
        
        '==========================================================================
        ' Change Values Here
        '==========================================================================
        Dim sPath : sPath = "\\ServerName\ShareName"
        Dim sDriveLetter : sDriveLetter = "X:"
        '==========================================================================
        
        Dim i
        Dim oNetwork: Set oNetwork = CreateObject("WScript.Network")
        Dim oMappedDrives: Set oMappedDrives = oNetwork.EnumNetworkDrives
        
        For i = oMappedDrives.Count-1 To 0 Step -2
        	If oMappedDrives.Item(i) = sPath Then
        		If oMappedDrives.Item(i-1) = sDriveLetter Then
        			MsgBox "Mapping Is Correct", vbOKOnly, "TestMapping"
        			WScript.Quit
        		Else
        			MsgBox "Mapping Exists, but on different driveletter. ( " & oMappedDrives.Item(i-1) & ")", vbOKOnly, "TestMapping"
        			WScript.Quit
        		End If
        	End If
        Next
        ' Correct mapping not found; Creating desired mapping
        On Error Resume Next
        oNetwork.MapNetworkDrive sDriveLetter, sPath
        If Err.Number <> 0 Then
        	MsgBox "There was an error creating the mapping." & VbCrLf & _
        		   "ErrorCode: " & Err.Number & VbCrLf & _
        		   "Description: " & Err.Description, vbOKOnly, TestMapping
        Else
        	MsgBox "Mapping Created successfully", vbOKOnly, "TestMapping"
        End If
        Semper in faecibus sumus, sole profundum variat

        Comment


        • #5
          Re: Map network drive and check every 10 mins

          Originally posted by SaMaLaKo View Post
          Maybe this script will also help:

          Code:
          ...vbs...
          Yes, you could also schedule a vbscript if you prefere.

          here are more examples:
          - http://forums.petri.com/showthread.php?t=14394
          - http://forums.petri.com/showthread.php?t=19170

          \Rems

          This posting is provided "AS IS" with no warranties, and confers no rights.

          __________________

          ** Remember to give credit where credit's due **
          and leave Reputation Points for meaningful posts

          Comment

          Working...
          X