Mapping network drive for limited time

Home Forums Scripting General Scripting Mapping network drive for limited time

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    igor7
    Member
    #155201

    Hi, all!!
    I’m trying automating some task in our environment… We have Windows Server 2003 with special McAfee AV version for NetApp. We need scan Network Share using this AV at least 3 times in week. I’ve created scheduled On-Demand scan task in McAfee antivirus to run during night hours and scan particular network drive. Also I’ve created two scheduled tasks on the same Windows 2003 Server, – one running vbs script which map network drive, and another one for disconnect this network drive.
    So here is scenario:
    1. At 20:00 running first scheduled task on Server which map network drive
    2. At 20:15 starting McAfee scheduled network drive scan
    3. At 06:00 AM running second scheduled task on Server which disconnect network drive.

    My question, if it possible to create only one script which will map network drive and after given time (8 hours for example) disconnect this network drive automatically? If it possible it will require less administrative effort so I can run McAfee each night and not only 3 times at week…

    Here are scripts codes:

    Mapping network drive:

    ‘ —————————————————-‘
    Option Explicit
    Dim objNetwork
    Dim strDriveLetter, strRemotePath, strDriveAlias, oShell
    strDriveLetter = “Z:”
    strRemotePath = [URL=”file://server/Share”]\ServerShare[/URL]
    strDriveAlias = “My Share”
    Set objNetwork = CreateObject(“WScript.Network”)
    Set oShell = CreateObject(“Shell.Application”)
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
    If Err.Number = 0 Then
    oShell.NameSpace(strDriveLetter).Self.Name = strDriveAlias
    End IF
    ‘ —————————————————-‘
    [/CODE]

    Disconnect Network Drive:

    [CODE]
    ‘ —————————————————-‘
    Option Explicit
    Dim objNetwork, strDriveLetter
    strDriveLetter = “Z:”
    Set objNetwork = CreateObject(“WScript.Network”)
    ‘ Section which removes strDriveLetter
    objNetwork.RemoveNetworkDrive strDriveLetter
    Wscript.Quit
    ‘ —————————————————‘

    [/CODE][CODE]



    Option Explicit
    Dim objNetwork
    Dim strDriveLetter, strRemotePath, strDriveAlias, oShell
    strDriveLetter = “Z:”
    strRemotePath = [URL=”file://server/Share”]\ServerShare[/URL]
    strDriveAlias = “My Share”
    Set objNetwork = CreateObject(“WScript.Network”)
    Set oShell = CreateObject(“Shell.Application”)
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
    If Err.Number = 0 Then
    oShell.NameSpace(strDriveLetter).Self.Name = strDriveAlias
    End IF



    [/CODE]

    Disconnect Network Drive:

    ‘ —————————————————-‘
    Option Explicit
    Dim objNetwork, strDriveLetter
    strDriveLetter = “Z:”
    Set objNetwork = CreateObject(“WScript.Network”)
    ‘ Section which removes strDriveLetter
    objNetwork.RemoveNetworkDrive strDriveLetter
    Wscript.Quit
    ‘ —————————————————‘

    [/CODE][CODE]



    Option Explicit
    Dim objNetwork, strDriveLetter
    strDriveLetter = “Z:”
    Set objNetwork = CreateObject(“WScript.Network”)
    ‘ Section which removes strDriveLetter
    objNetwork.RemoveNetworkDrive strDriveLetter
    Wscript.Quit


    [/CODE]

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.