#130473 - 2004-12-02 04:02 PM
Delete drive mappings to shares on only one server
|
misty
Fresh Scripter
Registered: 2004-10-14
Posts: 31
|
Hi all,
Currently in my login script, I have the following at the top, for security: USE "*" /DELETE
However, this is deleting all mappings from ALL file servers. What I really want to do is delete all mappings from \\corpsrv but leave the rest of them alone. Is there an easy way to do this, or do I have to do it by the drive mapping? I hope not because some of the mappings go to the next available drive, rather than a specific drive letter, and it would be difficult to script that with if/then.
|
|
Top
|
|
|
|
#130475 - 2004-12-02 05:39 PM
Re: Delete drive mappings to shares on only one server
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I would recommend that you investigate the UDF WSHPIPE(). I see you using this UDF to perform and capture the output of "Net Use". then examining each line to determine if the server name in question is present. If it is then parse the line to get the drive letter and "Use $drive /delete /persistent" it.
|
|
Top
|
|
|
|
#130479 - 2004-12-03 12:53 AM
Re: Delete drive mappings to shares on only one server
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Quote:
What I really want to do is delete all mappings from \\corpsrv
There was nothing stating that some of the drives mapped to the specified server were NOT persistently mapped. If they were persistent then the "/persistent" switch on the delete would be necessary to insure that they are removed.
|
|
Top
|
|
|
|
#130481 - 2004-12-03 04:08 AM
Re: Delete drive mappings to shares on only one server
|
tjcarst
Hey THIS is FUN
Registered: 2003-09-08
Posts: 243
Loc: USA
|
|
|
Top
|
|
|
|
#130483 - 2004-12-03 11:41 AM
Re: Delete drive mappings to shares on only one server
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
This sample interrogates drive mappings.
It should be trivial to delete the mapping you don't want:
Code:
Break ON $=SetOption("Explicit","ON") $=SetOption("WrapAtEOL","ON") Dim $sDriveMapping For Each $sDriveMapping in udfGetMappedDrives() $sDriveMapping=Split($sDriveMapping,":") "Drive '"+$sDriveMapping[0]+":' is mapped to '"+$sDriveMapping[1]+"'"+@CRLF Next Exit 0 ; Return an array of drive mappings Function udfGetMappedDrives() ; {{{ Dim $sLine For Each $sLine in Split(udfPipe("NET USE")[0],@CRLF) $sLine=Split(udfSqueeze($sLine)) If UBound($sLine)>2 If $sLine[0]="OK" AND Right($sLine[1],1)=":" Redim Preserve $udfGetMappedDrives[UBound($udfGetMappedDrives)+1] $udfGetMappedDrives[UBound($udfGetMappedDrives)]=$sLine[1]+$sLine[2] EndIf EndIf Next EndFunction ; }}} ; Execute a command and return output and error streams {{{ ; This code adapted from Chris S. WshPipe() http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=8257 Function udfPipe($sCommand, Optional $iTimeout,Optional $iInterval) Dim $oExec Redim $udfPipe[2] If Not $iTimeout $iTimeout=10.0 EndIf If Not $iInterval $iInterval=0.1 EndIf $iTimeout=CDbl($iTimeout) $iInterval=CDbl($iInterval) $oExec = CreateObject("WScript.Shell").Exec($sCommand) If Not VarType($oExec)=9 $udfPipe[1]=@SERROR Exit @ERROR EndIf $udfPipe[0] = $oExec.StdOut.ReadAll $udfPipe[1] = $oExec.StdErr.ReadAll ; Wait for process to complete to ensure correct exit status is returned While $oExec.Status=0 And $iTimeout > 0 Sleep $iInterval $iTimeout=$iTimeout-$iInterval Loop If Not ($iTimeOut>0) $udfPipe[1]=$udfPipe[1]+@CRLF+"TIMER EXPIRED" Exit 1460 EndIf Exit $oExec.ExitCode EndFunction ;}}} ; Remove repeated characters from string {{{ Function udfSqueeze($sString,Optional $sSqueeze) If $sSqueeze="" $sSqueeze=" " EndIf $udfSqueeze="" While NOT ($sString="") If NOT ((Left($sString,1)=Right($udfSqueeze,1)) AND InStr($sSqueeze,Left($sString,1))) $udfSqueeze=$udfSqueeze+Left($sString,1) EndIf $sString=SubStr($sString,2) Loop Exit 0 EndFunction ; }}} ; vim600: filetype=kix ai ts=4 sw=4 ai fdc=4 fdm=marker
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 1607 anonymous users online.
|
|
|