Page 1 of 1 1
Topic Options
#197824 - 2010-02-19 04:56 PM Removing a mapped network drive
MaryHumphrey Offline
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
#197825 - 2010-02-19 05:08 PM Re: Removing a mapped network drive [Re: MaryHumphrey]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
Welcome to KORG, Mary!

SetDrive is not a built-in function in KiX, and it is not listed in the UDF library here. Can you post your SetDrive function? We can then be in a better position to either recommend a change or alternate function that will support your Disconnect requirement.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197826 - 2010-02-19 05:24 PM Re: Removing a mapped network drive [Re: Glenn Barnas]
MaryHumphrey Offline
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 Offline
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:

 Code:
Function setDrive(...)
some code
EndFunction


Can you show us that?

Regards,

Brad

Top
#197828 - 2010-02-19 05:39 PM Re: Removing a mapped network drive [Re: MaryHumphrey]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
I understand.. That is not the function, but the "function call".

Somewhere in your script is a
 Code:
Function SetDrive(list of args...)
 bunch of commands here...
EndFunction
Can you locate that section of code and post it here? The function "SetDrive"is not part of KiXtart, so must be defined in your script as a User Defined Function. Once you post that code, we can review it and determine if we can add an option "2" to disconnect.

Since you tell us that the USE * /Delete is disconnecting and not deleting, seeing the SetDrive function code will identify how your drives are being mapped.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197829 - 2010-02-19 05:42 PM Re: Removing a mapped network drive [Re: BradV]
MaryHumphrey Offline
Just in Town

Registered: 2010-02-19
Posts: 4
Loc: Plymouth, MN
Sorry, didn't quite get it. See below:

 Code:
===================================================================
; $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
#197830 - 2010-02-19 05:52 PM Re: Removing a mapped network drive [Re: MaryHumphrey]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
OK - try this simple mod:
 Code:
===================================================================
; $Function: setDrive
;  $Purpose: Map a drive letter (optionally remove previous)
; ===================================================================
Function setDrive($Letter,$Path,$Desc, $Unmap)

  Dim $UnMapCmd

  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
    $UnMapCmd = "net use "+$Letter+" /delete /Persistent:no"
    If $Debug
      ? ">Unmap: "+$UnMapCmd
    Endif
    ? " "
    shell $UnMapCmd
    If $UnMap = 2 Exit 0 EndIf
  Endif

  ;use $Letter "$Path"
  Dim $Map
  $Map="net use "+$Letter+" "+chr(34)+$Path+chr(34)+" /persistent:yes"
  shell $Map
 
EndFunction
The changes are simple - instead of recycling the $UnMap variable, we declare $UnMapCmd. That is the command string we execute to unmap if the last argument is NOT ZERO.

The second change is the "If $UnMap = 2 Exit 0 EndIf" line. Now, if the last parameter is 0, it simply maps a drive. If it is 1, it will unmap and then map the new connection. If it is 2, it will unmap the current connection and then exit.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197831 - 2010-02-19 05:55 PM Re: Removing a mapped network drive [Re: MaryHumphrey]
BradV Offline
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:

 Code:
===================================================================
; $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
#197832 - 2010-02-19 06:07 PM Re: Removing a mapped network drive [Re: BradV]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
It could also be because the drives are being mapped with persistent option but being unmapped without it.
Top
#197833 - 2010-02-19 06:16 PM Re: Removing a mapped network drive [Re: BradV]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
You missed the original intent, Brad.. The design was to unmap then map, or just map - not Map OR Unmap. ;\)

Your change will impact the way the rest of the code is implemented. NOT that it isn't a potentially better implementation..

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197834 - 2010-02-19 06:50 PM Re: Removing a mapped network drive [Re: BradV]
MaryHumphrey Offline
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
#197835 - 2010-02-19 07:46 PM Re: Removing a mapped network drive [Re: Glenn Barnas]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
Yea, I thought it was odd to set a parameter to unmap and then map it right back again. But then I thought about it, and modified my post. It should be consistent with the original?
Top
#197838 - 2010-02-21 03:47 PM Re: Removing a mapped network drive [Re: BradV]
Glenn Barnas Administrator Offline
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
 Code:
SetDrive('D:','\\server\share','my share', 1)
to
 Code:
SetDrive('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
 Code:
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! \:D

Top
Page 1 of 1 1


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

Who's Online
0 registered and 601 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.137 seconds in which 0.087 seconds were spent on a total of 13 queries. Zlib compression enabled.

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