#100391 - 2003-04-17 12:50 AM
Re-Map Drives using the same drive letter
|
MaestroG
Fresh Scripter
Registered: 2002-12-30
Posts: 28
Loc: Tulsa, OK
|
I am nothing but a novice KiXtart scripter. I need desperatly to find some code or a UDF that will help me do the following:
1) enumerate mapped network drives ...then... 2) Search for a mapping mapped to a specified UNC path ...then... 3) remember the drive letter in use if a mapping is in my search is found ...then... 4) delete that mapping ...then... 5) remap persistantly using the remembered drive letter to a new UNC.
We have Win95, WinNT, Win2K, and WinXP OSs. I am running Kix4.12.
Can anyone help!?!?!
|
|
Top
|
|
|
|
#100392 - 2003-04-17 02:18 AM
Re: Re-Map Drives using the same drive letter
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
check out driveEnum() DriveProp() and MapDrive() in the UDF forums
|
|
Top
|
|
|
|
#100393 - 2003-04-17 04:45 AM
Re: Re-Map Drives using the same drive letter
|
MaestroG
Fresh Scripter
Registered: 2002-12-30
Posts: 28
Loc: Tulsa, OK
|
I use DriveEnum() already, understand MapDrive(), and looked at DriveProp(), but I'm not savy enough yet to put it all together for the desired result.
Anyone care to provide some deeper coaching? I know it will take some time and thought...I could really use the help! ![[Frown]](images/icons/frown.gif) [ 17. April 2003, 04:46: Message edited by: MaestroG ]
|
|
Top
|
|
|
|
#100394 - 2003-04-17 05:10 AM
Re: Re-Map Drives using the same drive letter
|
MaestroG
Fresh Scripter
Registered: 2002-12-30
Posts: 28
Loc: Tulsa, OK
|
OK. Let me show you where I am in the process. I think you all would probably enjoy helping me with what I have wrong or with what I am missing...
Using DriveEnum(), I have the following code in my Kix script where $netdrives=DriveEnum(3):
code:
If InStr($netdrives,"\\server\sharename") $t = OpenFile("\\server\share\badmap.csv", "W", 1, 0) If @error = 0 WriteLine($t, "@WKSTA, $IP, @USERID, @FULLNAME, $os, $netdrives" + @CRLF) EndIf EndIf
My first problem is, I have three share names that have the same first 2 letters, but I need to detect each one separately (and remember what I found). Lets say the shares are 1) Win, 2) Window, 3) Windows. When I do the following code, it finds all three...\\server1\Win, \\server1\Window, and \\server1\Windows. How can I overcome this?
code:
If InStr($netdrives,"\\server1\Win") $t = OpenFile
My next problem is I don't know how to then remember the specific drive letter associated with the specific mapping I am looking for in the "If InStr()".
Once these problems are solved, I think I know how to delete that mapping using the remembered drive letter, and then re-map persistantly using MapDrive() to the new path.
Can you help me fill in the gaps, change my thinking, or fix my logic?
|
|
Top
|
|
|
|
#100395 - 2003-04-18 12:25 AM
Re: Re-Map Drives using the same drive letter
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
for each $drive in split(driveenum(3)) if driveprop($drive)[2]='\\server\share' use $drive: /del /persistent use $drive: \\newserver\newshare /persistent next
or something like that
|
|
Top
|
|
|
|
#100396 - 2003-04-17 04:43 PM
Re: Re-Map Drives using the same drive letter
|
MaestroG
Fresh Scripter
Registered: 2002-12-30
Posts: 28
Loc: Tulsa, OK
|
Thank you!!! This works beautifully:
code:
For Each $drive in Split(DriveEnum(3)) If driveprop($drive)[2]='\\server1\share' Use $drive /Del /PERSISTENT Use $drive "\\server2\share" /PERSISTENT EndIf Next
I will begin testing on each OS now. I like this Split() function. I'm just learning about how to use it. I really appreciate your assistance!
|
|
Top
|
|
|
|
#100397 - 2003-04-17 05:41 PM
Re: Re-Map Drives using the same drive letter
|
MaestroG
Fresh Scripter
Registered: 2002-12-30
Posts: 28
Loc: Tulsa, OK
|
Radimus, If there is an RPC to a share open with the same UNC, there is no drive letter associated (and since they are at the top of the list, they are enumerated first)...so instead of getting G: for $drive, I get \\server1\share. This probably should be addressed in the DriveEnum() function, but how? Also, I am noticing inconsistant behavior when I run the "For Each...Split" twice or three times for different share re-mappings. Any ideas about how to modify DriveEnum() to only acknowledge the mappings that actually have drive letters associated?
Also, this is a very good start, but I don't have WSH on every client for the DriveProp() to work. What should I do? Can WSH be used from a central location (don't think so), or is there another way to grab the drive letter from the For Each...Split?: ![[Confused]](images/icons/confused.gif) [ 17. April 2003, 18:01: Message edited by: MaestroG ]
|
|
Top
|
|
|
|
#100398 - 2003-04-17 10:12 PM
Re: Re-Map Drives using the same drive letter
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
If driveprop($drive)[2]='\\server1\share'and not left(driveprop($drive)[0],2)='\\' [ 17. April 2003, 22:13: Message edited by: Radimus ]
|
|
Top
|
|
|
|
#100399 - 2003-04-18 12:14 AM
Re: Re-Map Drives using the same drive letter
|
MaestroG
Fresh Scripter
Registered: 2002-12-30
Posts: 28
Loc: Tulsa, OK
|
Here's what I tried and it returned all drive mappings. I don't understand the driveprop() syntax enough to know what to modify: code:
For Each $drive in Split(DriveEnum(3)) If driveprop($drive)[2]='\\slayer\nt'OR'\\slayer\ntunix'OR'\\slayer\nt2'AND NOT Left(driveprop($drive)[0],2)='\\' ? $drive ? @SERROR EndIf Next
Here's what it produced...It should've returned G: J: and K: but it returned everything starting with the \\. DriveEnum() returns entries like this... G: \\slayer\nt2, J: \\slayer\nt, K: \\slayer\ntunix code:
G: The operation completed successfully. \\slayer\nt2,H: The operation completed successfully. \\usfile02\thogarr,I: The operation completed successfully. \\usdfs\AllGroups,J: The operation completed successfully. \\slayer\nt,K: The operation completed successfully. \\slayer\ntunix,L: The operation completed successfully.
[ 18. April 2003, 00:19: Message edited by: MaestroG ]
|
|
Top
|
|
|
|
#100400 - 2003-04-18 12:17 AM
Re: Re-Map Drives using the same drive letter
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
you can't do OR like that...
you have to use both comparators
|
|
Top
|
|
|
|
#100401 - 2003-04-18 12:23 AM
Re: Re-Map Drives using the same drive letter
|
MaestroG
Fresh Scripter
Registered: 2002-12-30
Posts: 28
Loc: Tulsa, OK
|
Hang on...Your code works! Sorry...the problem was my fault. I had modified the way your DriveEnum() function outputs data.
It still will not re-map 3 times in a row! Do you know why? BTW, what do I do about Win9x and WinNT clients without WSH?
code:
For Each $drive in Split(DriveEnum(3)); If driveprop($drive)[2]='\\server1\share'AND NOT Left(driveprop($drive)[0], 2)='\\' Use $drive+":" /Del /PERSISTENT Use $drive+":" "\\server2\share" /PERSISTENT EndIf Next
[ 18. April 2003, 00:59: Message edited by: MaestroG ]
|
|
Top
|
|
|
|
#100402 - 2003-04-18 02:15 AM
Re: Re-Map Drives using the same drive letter
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
I don't have win9x clients, but I'd install it and WMI as well.
regardless of how much work it is, it saves more work in the long run
|
|
Top
|
|
|
|
#100403 - 2003-04-18 02:18 AM
Re: Re-Map Drives using the same drive letter
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
btw.. I never map persistently.
If the script doesn't run, I want to know/// and the users not having their drives is the fastest way to find out
|
|
Top
|
|
|
|
#100405 - 2003-04-18 03:09 AM
Re: Re-Map Drives using the same drive letter
|
MaestroG
Fresh Scripter
Registered: 2002-12-30
Posts: 28
Loc: Tulsa, OK
|
We're working on getting rid of the Win9x clients. By the end of the year, all PCs will be WinXP. Unfortunately, I need to move our NFS shares to a different server ASAP and I'm trying harder than all get out to use the Infamous KiXtart to make the re-mapping happen at logon for our end-users without their intervention.
Is there no way to accomplish this (without WSH) only using KiXtart?
|
|
Top
|
|
|
|
#100407 - 2003-04-18 05:26 AM
Re: Re-Map Drives using the same drive letter
|
MaestroG
Fresh Scripter
Registered: 2002-12-30
Posts: 28
Loc: Tulsa, OK
|
I appreciate the ideas...I've been there already. The deal is our users have scripts and processes that are tied to the drive-letter on their workstation. It's one of those things where everyone has developed something that worked and now it is something that is relied upon and important.
I am restricted to a few rules in this situation:
1) Move NFS shares to a new server 2) Consolidate them on the new server 3) Users mappings must retain the same drive letter so their 'stuff' still works. 4) Complicating things...there isn't a driveletter that I can commandeer for NFS due to the possibility of overwriting a critical mapping of some user.
If you can't tell...our users get a lot of weight in the decisions MIS makes! I can obviously go to each PC an re-map manually (please NO!). I might be able to come up with a batch script to send out to each user but due to #4 above, I'd have to find a way to have the user type in the letter of their current NFS mappings and make that input a variable (don't know how to do this). Last, I can use a scripting language that is OS agnostic like KiXtart or Perl since this has to take place on Win95, WinNT, and up. I have used KiXtart and prefer it, obviously.
Now then...my problem remains:
- See if any specific mappings exist
- If so, record the drive letter as a variable
- Use the Variable to delete the mapping and re-map.
Without WSH and WMI, I'm stuck with just KiXtart's abilities. Anyone got anymore helpful ideas based on these rules and what I have to work with? Renew my faith in this powerful product!
|
|
Top
|
|
|
|
#100409 - 2003-04-18 11:55 PM
Re: Re-Map Drives using the same drive letter
|
MaestroG
Fresh Scripter
Registered: 2002-12-30
Posts: 28
Loc: Tulsa, OK
|
YES! I got it! Had to use what I learned from everyone, add in some good ole brain food (caffeine), and get even more desperate. Turns out it wasn't all that difficult.
This is how to re-map drives with KiXtart 4.12 for Win95, WinNT, Win2K, and WinXP...it may be crude, but it works beautifully. It includes the DriveEnum() function which was slightly modified to produce a specific output.
code:
;=============================================================================================== ;**** Created with KiXscripts Editor | http://KiXscripts.com **** ;**** Last Modified on 4/18/2003 @ 5:01:10 PM by "thogarr" **** ;**** Developed for KiXtart release 4.12 | www.KiXtart.org **** ;=============================================================================================== ; ; This code will Enumerate Mapped Drives, See If any specific ; mappings exist, and if so, Set the drive letter as a variable, and use the Variable ; to delete the existing mapping and map the drive to the specified UNC.
; You will need to modify the UNC to search for and the UNC to map. This worked for me ; because we had 3 shares on one server that started with the same 2 letters which I ; needed to consolidate into one new share on a different sever and get everyone remapped.
; For Each $drive in Split(DriveEnum(3)) If InStr($drive,"\\server1\share") $driveltr=Left($drive,2) Use $driveltr /Del /PERSISTENT Use $driveltr "\\server2\share" /PERSISTENT EndIf Next ; ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ; FUNCTIONS ;************************************************************ ;** ;** Enumerate Drives Function ;** ;** ;Function DriveEnum() ; ;Author Radimus ; ;Version 1 (06.20.2002) ; ;Action Returns a list of all connected drive letters (space seperated). ; ;Syntax DriveEnum(optional $filter) ; ;Parameters ; $filter- (to return specific types of drives. any combination of the numbers below) ; 0/"" - return all drives ; 1 - return removable drives ; 2 - return fixed drives ; 3 - return network drives ; 4 - return CD rom drives ; 5 - return RAM drives ; ; ;Remarks ; ; ;Returns ; -space seperated list of drive letters use split() to seperate ; ; ;Dependencies ; WSH - kix 4.02+ ; ;Examples ; $netdrives=DriveEnum(3) ; $localdrives=DriveEnum(124) ; $all=DriveEnum("") ; ;Source ;****************************************************************** Function DriveEnum(optional $filter) Dim $fso, $Drive
$fso=CreateObject("Scripting.FileSystemObject") If $fso For Each $Drive in $fso.Drives If InStr($filter,$Drive.DriveType) OR $filter="" $DriveEnum=$DriveEnum+$Drive.DriveLetter + ":" + $Drive.Sharename + ", " EndIf Next $DriveEnum=Left($DriveEnum,Len($DriveEnum)-1) $fso="" EndIf EndFunction
[ 19. April 2003, 00:03: Message edited by: MaestroG ]
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 1172 anonymous users online.
|
|
|