Remove all mapped drives on all machines in the txt file.

Hi,

Remove all mapped drives on all machines in the txt file.
Any way to disconnect all mapped drives.

REgards
Sharath
LVL 11
bsharathAsked:
Who is Participating?
 
yehudahaConnect With a Mentor Commented:
try this

change log file and list file path

Set objlist = objfso.OpenTextFile("c:\list.txt", ForReading)
Set objlog = objfso.CreateTextFile("c:\log.txt", ForWriting)

download psexec from here:
http://download.sysinternals.com/Files/PsTools.zip

and change toll path here:
strTool = "\\server\share\psexec.exe"
Const ForReading = 1
Const ForWriting = 2
  
Set objfso = CreateObject("Scripting.FileSystemObject")
Set objlist = objfso.OpenTextFile("c:\list.txt", ForReading)
Set objlog = objfso.CreateTextFile("c:\log.txt", ForWriting)
 
strTool = "\\server\share\psexec.exe"
 
Do Until objlist.AtEndOfStream
strComputer = objlist.ReadLine
If Reachable(strComputer) Then
   If per(strComputer) then
strCommand = strTool & " \\" & strComputer & " net use * /delete /y"
objshell.Run(strCommand)
   Else
     objlog.WriteLine "You Don't Have Permission On " & strComputer & vbCrLf
   End if
Else
objlog.WriteLine strComputer & " Isn't Reachable" & vbCrLf
End if
Loop
 
 
Function Reachable(strComputer)
 
 strCmd = "ping -n 1 " & strComputer
 
 Set objShell = CreateObject("WScript.Shell")
 Set objExec = objShell.Exec(strCmd)
 strTemp = UCase(objExec.StdOut.ReadAll)
 
 If InStr(strTemp, "REPLY FROM") Then
 Reachable = True 
 Else
 Reachable = False
 End If
End Function
 
Function per(computer)
	strcomputer = computer
	On Error Resume Next
	Set objWMIService = GetObject("winmgmts:" _
	& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	If err.number <> 0 Then
		err.Clear
		per = False
		On Error goto 0
	Else
		per = True
		On Error goto 0
	End If
End Function

Open in new window

0
 
GuruGaryCommented:
I am not sure what you mean by "in the txt file".  But a simple command to remove all network share drive mappings in a command prompt or BAT/CMD file is:
net use * /delete
@echo off
net use * /delete

Open in new window

0
 
bsharathAuthor Commented:
Ok..

I need to do this for a lot of different computers . Whose names are in a txt file...

Machinename1
machinename2
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
bsharathAuthor Commented:
Ok..

I need to do this for a lot of different computers . Whose names are in a txt file...

Machinename1
machinename2
0
 
yehudahaCommented:
why don't do it with a logon script ?
0
 
bsharathAuthor Commented:
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Map drives removal.vbs
Line:      6
Char:      1
Error:      Permission denied
Code:      800A0046
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
0
 
bsharathAuthor Commented:
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Map drives removal.vbs
Line:      6
Char:      1
Error:      Permission denied
Code:      800A0046
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
0
 
yehudahaCommented:
sorry the script have other problems try to figure it how
0
 
bsharathAuthor Commented:
Ok thanks
0
 
bsharathAuthor Commented:
Ok thanks
0
 
yehudahaCommented:
i don't have a way

sorry
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.