#197824 - 2010-02-19 04:56 PM
Removing a mapped network drive
|
MaryHumphrey
Just in Town
Registered: 2010-02-19
Posts: 4
Loc: Plymouth, MN
|
We have a variety of mapped drives using the following protocol. $dc=setDrive("H:","\\servername\Users\%USERNAME%","User Folder",0) $dc=SetDrive("L:","\\servername\Share$","Share",1)
The 0 on the end maps the drive, the 1 disconnects and remaps the drive with new information. How can I remove a mapped drive completely?
I've tried the use * /delete function but that only disconnects the drive and doesn't remove it. I also noticed that at least in my instance it doesn't allow for remapping a drive with different information using the use L: "\\servername\Share$". It will keep the old mapping that was defined and not change it to the new information assigned.
Some times we no longer want to have a map drive or assigned to something new, we just want to remove it and I haven't found a way to do this. I also didn't find anything on the protocol that we are using which for the most part works pretty well. Any help would be appreciated. Thank you!
|
|
Top
|
|
|
|
#197826 - 2010-02-19 05:24 PM
Re: Removing a mapped network drive
[Re: Glenn Barnas]
|
MaryHumphrey
Just in Town
Registered: 2010-02-19
Posts: 4
Loc: Plymouth, MN
|
Hi Glenn:
Thanks for responding. The function is:
$dc=setDrive("H:","\\servername\Users\%USERNAME%","User Folder",0)
The 0 on the end maps the drive. If you use a 1 in it's place it will disconnect what was previously mapped and remap accordingly.
My main goal is to have a function for removing a drive. Say for instance I no longer want L to be mapped, how do I get rid of it?
Thanks!
Mary
|
|
Top
|
|
|
|
#197827 - 2010-02-19 05:38 PM
Re: Removing a mapped network drive
[Re: MaryHumphrey]
|
BradV
Seasoned Scripter
  
Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
|
Hi Mary,
What Glenn was saying is that setDrive is not a built in function to kixtart. So, are you sure you are using kixtart? If so, there should be a section in your script that says:
Function setDrive(...)
some code
EndFunction
Can you show us that?
Regards,
Brad
|
|
Top
|
|
|
|
#197829 - 2010-02-19 05:42 PM
Re: Removing a mapped network drive
[Re: BradV]
|
MaryHumphrey
Just in Town
Registered: 2010-02-19
Posts: 4
Loc: Plymouth, MN
|
Sorry, didn't quite get it. See below:
===================================================================
; $Function: setDrive
; $Purpose: Map a drive letter (optionally remove previous)
; ===================================================================
Function setDrive($Letter,$Path,$Desc, $Unmap)
If $Debug
? ">Mapping "+$Letter+" "+$Path+" ("+$Desc+")"
Endif
If $Unmap
; Because pre-existing persistent mapped drives are not removed with the below
; command, a shell command is used instead
;use $Letter /del
$UnMap="net use "+$Letter+" /delete"
If $Debug
? ">Unmap: "+$UnMap
Endif
? " "
shell $UnMap
Endif
;use $Letter "$Path"
Dim $Map
$Map="net use "+$Letter+" "+chr(34)+$Path+chr(34)+" /persistent:yes"
shell $Map
EndFunction
Edited by Glenn Barnas (2010-02-19 05:47 PM) Edit Reason: added code tags
|
|
Top
|
|
|
|
#197831 - 2010-02-19 05:55 PM
Re: Removing a mapped network drive
[Re: MaryHumphrey]
|
BradV
Seasoned Scripter
  
Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
|
Hi Mary,
That's because whomever wrote this didn't quite get the syntax correct. Try changing to:
===================================================================
; $Function: setDrive
; $Purpose: Map a drive letter (optionally remove previous)
; ===================================================================
Function setDrive($Letter,$Path,$Desc, $Unmap)
If $Debug
">Mapping "+$Letter+" "+$Path+" ("+$Desc+")" ?
Endif
If $Unmap = 1
Use $Letter /delete /persistent
If @ERROR = 0
"Drive letter, " + $Letter + ", was deleted." ?
Else
"There was a problem deleting drive letter, " + $Letter ?
EndIf
EndIf
;
Use $Letter $Path
If @ERROR = 0
"Drive letter, " + $Letter + ", was mapped successfully." ?
Else
"There was a problem mapping drive letter, " + $Letter ?
EndIf
EndFunction
Edited by BradV (2010-02-19 05:57 PM) Edit Reason: Well, Glenn beat me to it! :)
|
|
Top
|
|
|
|
#197834 - 2010-02-19 06:50 PM
Re: Removing a mapped network drive
[Re: BradV]
|
MaryHumphrey
Just in Town
Registered: 2010-02-19
Posts: 4
Loc: Plymouth, MN
|
That works PERFECTLY...Your the Man, Brad! Thank you for your help. I've been struggling with this for quite some time.
Thanks!
Mary
|
|
Top
|
|
|
|
#197838 - 2010-02-21 03:47 PM
Re: Removing a mapped network drive
[Re: BradV]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
|
Uh - not exactly..
The function that Mary requested should Map, Unmap & Map, or just Unmap. Your first one allowd Map or Unmap, but removed the Unmap & Map functionality. This could affect the operation of the original script. While it added the Unmap feature that Mary required, she would have to modify any calls from SetDrive('D:','\\server\share','my share', 1) toSetDrive('D:','','', 1)
SetDrive('D:','\\server\share','my share', 0) to unmap and then map. The modification I presented employes a new ActionID value that retains the original functionality (0=map, 1=unmap & map) and adds a new function (2=unmap). This means that no prior code needs to be modified, other than changing the action code to "2" for unmaps.
Of course, now that we've seen the SetDrive code, we know that Persistence is enabled. The easiest change would be to simply insert a use 'D:' /delete /persistent' to remove drives. This is why we have an option in our script to unmap all drives - start with an (almost) clean slate before mapping. Our script allows ignoring certain drive letters during the unmap process. This means that if users manually map drives to these reserved letters, they will not be affected by the login script.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 601 anonymous users online.
|
|
|