Page 1 of 1 1
Topic Options
#142679 - 2005-06-29 08:52 PM Use of variables for drive letters in the use command.
tmclean Offline
Fresh Scripter

Registered: 2001-01-26
Posts: 18
Loc: Sault Ste. Marie Ontario
I'm trying to remap persistant drive mappings from various server shares to new ones. I start by enumerating the persistant drive mapping keys through the registry, reading the remote path and if the first part equals the name of the server I'm looking for, delete it and remap to the new server as the same drive letter using the the new server name followed by whatever path was read. The use command doesnt seem to like the use of variables. Can anyone help? I've included a sample of what I got. I'm using Case select because I will be remapping shares off various servers. Thx
***************************************************************


$Index = 0

:Loop1

$KeyName = ENUMKEY("HKEY_CURRENT_USER\Network\", $Index)

If @ERROR = 0

$MappedServer = ReadValue("HKEY_CURRENT_USER\Network\$KeyName", "RemotePath")
$Drive = ltrim(substr($MappedServer,1,14))
$Path = ltrim(substr($MappedServer,15,255))
$Drive1 = ltrim(substr($MappedServer,1,13))
$Path1 = ltrim(substr($MappedServer,14,255))

SELECT


Case $Drive = "\\oldserver"

use $KeyName: /delete /PERSISTENT
use $KeyName: "\\newserver\$Path" /persistent

ENDSELECT




$Index = $Index + 1
goto Loop1
Endif

Top
#142680 - 2005-06-29 09:04 PM Re: Use of variables for drive letters in the use command.
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
I have a UDF for this. Give fnRemapShare() a try.
Top
#142681 - 2005-06-29 09:28 PM Re: Use of variables for drive letters in the use command.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
The problem in your script is not that KiX will not accept vars as parms cuz it will. The problem is in how you craft your statements. It is also compounded by he fact you try to do it serially in a loop whilst you modify the keys you enum.

The first parm you malform by not providing quotes and the second you embed in quotes.
(untested)
use $KeyName+':' '\\newserver\'+$Path /persistent

Are you sure it is safe to hard code positions in your SubStr() functions?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#142682 - 2005-06-29 10:16 PM Re: Use of variables for drive letters in the use command.
tmclean Offline
Fresh Scripter

Registered: 2001-01-26
Posts: 18
Loc: Sault Ste. Marie Ontario
Thx, seems to be working. I'm hardcoding the character length of the machine names I'm looking for and rest I'm looking for a path up to 255 characters for UNC naming conventions.
Top
#142683 - 2005-07-03 02:37 AM Re: Use of variables for drive letters in the use command.
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
What seems to be working now? By modifying your code as Les suggested or by using the UDF that Chris suggested?
 
Perhaps a repost of the corrected code and using CODE TAGS to preserve formatting would be good for others to see your approach as well.
 

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 1046 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.052 seconds in which 0.024 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