Page 1 of 1 1
Topic Options
#130473 - 2004-12-02 04:02 PM Delete drive mappings to shares on only one server
misty Offline
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
#130474 - 2004-12-02 04:05 PM Re: Delete drive mappings to shares on only one server
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I guess you reap what you sow.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#130475 - 2004-12-02 05:39 PM Re: Delete drive mappings to shares on only one server
Howard Bullock Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#130476 - 2004-12-02 07:13 PM Re: Delete drive mappings to shares on only one server
NTDOC Administrator Online   content
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Misty, please try Howard's suggestion, but what Les is eluding to is that you should not be mapping NEXT AVAILABLE drives in the first place. A good common practice is to have defined drives mapped to defined shares for all specific systems in the first place. Then you would know when and what to unmap if needed. Users that moved around would always know which drive went where. Using next available is not a good solution to use in general.

Top
#130477 - 2004-12-02 07:46 PM Re: Delete drive mappings to shares on only one server
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
There was never any mention of deleting persistent drives in Misty's original post. If they are not persistent in the first place, then just edit the script and that is that. Non-persistent drives are mapped on every logon. I don't understand where the problem is.

Persistent drives can also be enumerated from the registry.

...and yes, musical drives are a really bad idea.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#130478 - 2004-12-02 08:00 PM Re: Delete drive mappings to shares on only one server
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
exactly.

Edited by Jooel (2004-12-02 08:16 PM)
_________________________
!

download KiXnet

Top
#130479 - 2004-12-03 12:53 AM Re: Delete drive mappings to shares on only one server
Howard Bullock Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#130480 - 2004-12-03 01:27 AM Re: Delete drive mappings to shares on only one server
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Since the line, USE "*" /DELETE does not have the persistent switch, it would only delete non-persistent drives so one has to wonder why misty does not want to delete all non-persistent drives. This whole topic is based on that statement and the avoidance of conditional checks.

If misty maps some drives as persistent, the USE "*" /DELETE line would not delete them. Why would someone map drives as persistent? What is wrong with deleting non-persistent drives? I mean, they would get mapped again on every logon anyway. If they are mapped as persistent, misty now reaps what misty sowed.

Mapping musical drives is a lazy alternative to good planning. Again, you reap what you sow.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#130481 - 2004-12-03 04:08 AM Re: Delete drive mappings to shares on only one server
tjcarst Offline
Hey THIS is FUN

Registered: 2003-09-08
Posts: 243
Loc: USA
How about trying this

Code:

if @wksta = "corpsrv"
use * /del
else

...rest of login

endif


http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Board=UBB14&Number=128822&Forum=All_Forums&Words=if%20%40wksta&Match=And&Searchpage=0&Limit=25&Old=allposts&Main=128806&Search=true#Post128822


Top
#130482 - 2004-12-03 09:04 AM Re: Delete drive mappings to shares on only one server
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
eh?
now, that would match if you logged on to the server and elsewhere fails.
thus, has no relation to the issue.
_________________________
!

download KiXnet

Top
#130483 - 2004-12-03 11:41 AM Re: Delete drive mappings to shares on only one server
Richard H. Administrator Offline
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
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1471 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.068 seconds in which 0.031 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org