+ Post New Thread
Results 1 to 5 of 5
Windows Thread, deleting mapped drives in .vbs that are mapped with .bat in Technical; Hi, Im new here... We have moved our scripts to .vbs as we were running .bat log ons, so now ...
  1. #1
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    3,031
    Thank Post
    305
    Thanked 292 Times in 202 Posts
    Rep Power
    120

    deleting mapped drives in .vbs that are mapped with .bat

    Hi,

    Im new here...


    We have moved our scripts to .vbs as we were running .bat log ons, so now when the scripts run, we get this drive is already in use. The only way to get rid of this is to delete the local profile on the computer, but with over 1000 clients we dont want to do that so..... is there any way that we can put in the first part of the vbscript a script that will automatically delete these mapped drives that are stored on the local computer???

    This is what is running now... and we get the error this drive is already in use

    Const Pupils = "cn=pupils"

    set wshNetwork = CreateObject("WScript.Network")

    Set ADSysInfo = CreateObject("ADSystemInfo")
    Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
    strGroups = LCase(Join(CurrentUser.MemberOf))

    If InStr(strGroups,pupils) Then
    wshNetwork.MapNetworkDrive "p:","\\hades\upublic"
    wshNetwork.MapNetworkDrive "s:","\\hades\business"
    wshNetwork.MapNetworkDrive "v:","\\hades\uapps"

    End If

    ive aslo got this

    These are supposed to delete the drives, but it doesnt work...

    Sub DeleteDriveMapping(s"p:")
    ' This will remove the mapped drive sDriveLetter
    CreateObject("WScript.Shell").Run "net.exe use " _ & sDriveLetter & " /delete", 0, True
    WScript.Sleep 250
    End Sub

    or

    Option Explicit
    Dim objShell, objNetwork, DriveLetter1

    DriveLetter1 = "P:"

    Set objShell = CreateObject("WScript.Shell")
    Set objNetwork = CreateObject("WScript.Network")

    objnetwork.removenetworkdrive DriveLetter1

    wscript.quit

    Any ideas???

    Cheers

    Tim

  2. #2

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    London
    Posts
    7,599
    Thank Post
    109
    Thanked 765 Times in 596 Posts
    Rep Power
    181

    Re: deleting mapped drives in .vbs that are mapped with .bat

    you need to enumerate all the network drives and then iterate through and delete them.

    I don't know if this is correct but give it a bash...

    Code:
    Set objNetwork = WScript.CreateObject("WScript.Network")
    Set colDrives = objNetwork.EnumNetworkDrives
    For i = 0 to colDrives.Count-1 Step 2
       objNetwork.RemoveNetworkDrive colDrives.Item(i)
    Next
    Hope it works - more info at http://www.microsoft.com/technet/scr..._wsh_peht.mspx

  3. #3
    timbo343's Avatar
    Join Date
    Dec 2005
    Location
    Leeds/York area, North Yorkshire
    Posts
    3,031
    Thank Post
    305
    Thanked 292 Times in 202 Posts
    Rep Power
    120

    Re: deleting mapped drives in .vbs that are mapped with .bat

    thanks for the reply....

    Ive looked at the microsoft site and used this one

    Set objNetwork = WScript.CreateObject("Wscript.Network")
    objNetwork.RemoveNetworkDrive "G:"

    now, it says it has disconnected the drive, but since the drive has been mapped on the local computer with the .bat logon using the command net use l: "....." it is still present and when i double click on the so called disconnected drive it connects again.

    Does the scirpt in green above delete the local profile of the user and then creates it again, thats what im looking to do

    Tim

  4. #4
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    5,011
    Thank Post
    120
    Thanked 282 Times in 260 Posts
    Rep Power
    108

    Re: deleting mapped drives in .vbs that are mapped with .bat

    If you want to delete local profiles then you need Delprof

  5. #5

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    London
    Posts
    7,599
    Thank Post
    109
    Thanked 765 Times in 596 Posts
    Rep Power
    181

    Re: deleting mapped drives in .vbs that are mapped with .bat

    to delete the local profile simply add the following line to a startup batch file:

    Code:
    delprof /q /i
    or in VBScript try...

    Code:
    Set objShell = Wscript.CreateObject("Wscript.Shell")
    CMDLine = "delprof /q /i"
    objShell.Run CMDLine
    check out http://www.microsoft.com/technet/scr..._wsh_pkoy.mspx

SHARE:
+ Post New Thread

Similar Threads

  1. Hide mapped network drives
    By timbo343 in forum Windows
    Replies: 11
    Last Post: 2nd April 2012, 09:06 AM
  2. Unmapping Mapped Drives
    By Grommit in forum Windows
    Replies: 12
    Last Post: 28th January 2008, 03:15 PM
  3. Slow mapped drives.
    By proby1 in forum Windows Vista
    Replies: 2
    Last Post: 15th November 2007, 10:39 AM
  4. SuccessMaker Mapped Drives
    By marco84 in forum Educational Software
    Replies: 11
    Last Post: 8th June 2007, 11:21 AM
  5. Replies: 5
    Last Post: 25th January 2007, 11:22 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •