Page 1 of 1 1
Topic Options
#72245 - 2002-12-18 08:21 PM Using $variable with the USE command
YaleCoder Offline
Getting the hang of it

Registered: 2001-12-18
Posts: 61
Loc: Jelenia Gora, Poland
[Moderator (Sealeopard): Moved thread from 'General' to 'Scripts' forum]
I am attempting to re-map existing network drives on windows machines. I need to set the existing drive letter to a variable and then use that variable in conjunction with two others as the parameters in the USE command. Below is a copy of my code. I can not get the existing drive to be deleted nor the new drive to be mapped.

;Calls Windows Host Scripting function to enumerate drives
Function WshEnumDrives()
Dim $fso
$WshEnumDrives = ""
$fso = CreateObject("scripting.filesystemobject")
If $fso
$WshEnumDrives = $fso.drives
EndIf
Exit @error
EndFunction

;Loops through enumerated drives and determines drive letter, type of drive and Share Name
For Each $drive in WshEnumDrives()
If $drive.drivetype = "3"
$w=InStr($drive.sharename,"med1")
If $w=0
Goto end
EndIf

$v="\\med1\home\"
$x=Left($drive.drivetype,1)
$y=SubStr($drive.sharename,8)
$z=$drive.driveletter
? $y
? $z
If Exist ($v+$y)
use $z: /del /persistent
Use $z: $v+$y
If @error = 0
Goto end
Else
MessageBox("You do not have the correct permissions to map a drive to "+$v+"\"+$y+". If you believe you should have access to this folder, please notify your business manager.","Folder not accessible",16)
EndIf
EndIf
EndIf

:end
Next

[ 18. December 2002, 21:24: Message edited by: sealeopard ]
_________________________
"When fascism comes to America, it will be wrapped in the flag, carrying a cross."
Sinclair Lewis

Top
#72246 - 2002-12-18 08:23 PM Re: Using $variable with the USE command
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
first question, why you want to re-map already mapped drive?
can't you just leave it be?
_________________________
!

download KiXnet

Top
#72247 - 2002-12-18 08:29 PM Re: Using $variable with the USE command
YaleCoder Offline
Getting the hang of it

Registered: 2001-12-18
Posts: 61
Loc: Jelenia Gora, Poland
Files in \\server\share are being migrated to \\server\home\share and I am attempting to script an easy solution for re-mapping users drives to the new UNC
_________________________
"When fascism comes to America, it will be wrapped in the flag, carrying a cross."
Sinclair Lewis

Top
#72248 - 2002-12-18 08:38 PM Re: Using $variable with the USE command
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
if the sharename is the same, there is nothing changed, right?
_________________________
!

download KiXnet

Top
#72249 - 2002-12-18 08:43 PM Re: Using $variable with the USE command
YaleCoder Offline
Getting the hang of it

Registered: 2001-12-18
Posts: 61
Loc: Jelenia Gora, Poland
Well the path changes from \\server\share to \\server\home\share. In my script I attempt to identify all networked drives with the string "med1" in it. Then I search the \\server\home directory for the existence of the newly migrated data. If it is not found, no changes are made to the mapping. If the new folder is found, I need to change the mapped connection to reflect the new UNC path while maintaining the same drive letter.
_________________________
"When fascism comes to America, it will be wrapped in the flag, carrying a cross."
Sinclair Lewis

Top
#72250 - 2002-12-18 08:44 PM Re: Using $variable with the USE command
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ok, got it.
so actually it is:
\\server\homeshare to \\server\share\homedir

[ 18. December 2002, 20:45: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#72251 - 2002-12-18 09:13 PM Re: Using $variable with the USE command
YaleCoder Offline
Getting the hang of it

Registered: 2001-12-18
Posts: 61
Loc: Jelenia Gora, Poland
Thats right. Do you know why I can't get the variables to function properly in the USE command?
_________________________
"When fascism comes to America, it will be wrapped in the flag, carrying a cross."
Sinclair Lewis

Top
#72252 - 2002-12-18 09:19 PM Re: Using $variable with the USE command
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You might want to start printing your variables to the console to see the contents and/or use DEBUG ON.
_________________________
There are two types of vessels, submarines and targets.

Top
#72253 - 2002-12-18 09:22 PM Re: Using $variable with the USE command
YaleCoder Offline
Getting the hang of it

Registered: 2001-12-18
Posts: 61
Loc: Jelenia Gora, Poland
I have tried that. All the variables return what I expected. The script returns an error on the USE command and continues on to the next drive. How can I pipe the results of the USE command to the console or a file?
_________________________
"When fascism comes to America, it will be wrapped in the flag, carrying a cross."
Sinclair Lewis

Top
#72254 - 2002-12-18 09:25 PM Re: Using $variable with the USE command
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Use
code:
? 'Error '+@ERROR+' - '+@SERROR

to display error codes.

Oh, and just in case:
Deep mapping does not work at all under Windows 9x. Deep mapping requires the use of the external utility SUBST under Windows NT.

[ 18. December 2002, 21:26: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#72255 - 2002-12-18 09:27 PM Re: Using $variable with the USE command
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
thanks for move, here is my reply which didn't get trhough:
------------------------
eh?
if it returns an error, it seems to pop the messagebox...
if you want it on console just echo it:
@error
_________________________
!

download KiXnet

Top
#72256 - 2002-12-18 09:39 PM Re: Using $variable with the USE command
YaleCoder Offline
Getting the hang of it

Registered: 2001-12-18
Posts: 61
Loc: Jelenia Gora, Poland
The system returns an "Operation completed successfully" message yet nothing changes. Neither the original drive is deleted nor the new connection mapped. Does the USE command take variables for the parameters? If so, does anyone know what I am doing wrong?
_________________________
"When fascism comes to America, it will be wrapped in the flag, carrying a cross."
Sinclair Lewis

Top
#72257 - 2002-12-18 09:40 PM Re: Using $variable with the USE command
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, I would shoot for del "*"

this way at least deletion would go.
_________________________
!

download KiXnet

Top
#72258 - 2002-12-18 09:43 PM Re: Using $variable with the USE command
YaleCoder Offline
Getting the hang of it

Registered: 2001-12-18
Posts: 61
Loc: Jelenia Gora, Poland
But that would delete all the networked drives, correct? I just need to delete the drives that I am remapping. Or do I? Will the USE command simply re-map the existing drive letter? (assuming I can get it to work) I can get it to function if I write out the full UNC as opposed to the variables.
_________________________
"When fascism comes to America, it will be wrapped in the flag, carrying a cross."
Sinclair Lewis

Top
#72259 - 2002-12-18 09:44 PM Re: Using $variable with the USE command
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, if you anyway re-map them, why don't you delete all, and re-map all needed?
_________________________
!

download KiXnet

Top
#72260 - 2002-12-18 09:46 PM Re: Using $variable with the USE command
YaleCoder Offline
Getting the hang of it

Registered: 2001-12-18
Posts: 61
Loc: Jelenia Gora, Poland
I only need to re-map drives that are connected to a particular share on a particular server, not all networked drives. Does the command work with variables?
_________________________
"When fascism comes to America, it will be wrapped in the flag, carrying a cross."
Sinclair Lewis

Top
#72261 - 2002-12-18 09:49 PM Re: Using $variable with the USE command
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I am currently very busy at the moment and did not read the thread carefully. Does this work for you?

MapDrive("I:", "bullpup", "c$")
code:
 Function MapDrive($Drive, $Server, $Share)
Dim $Drive, $Server, $Share
Color c+/n
If $Drive<>"" and $Server<>"" and $Share<>""
$LogText="Connecting $Drive to \\$Server\$Share"
? $LogText
USE $Drive /Delete /Persistent
USE $Drive "\\$Server\$Share"
If @error=0
color g+/n
$x=" - Success"
"$x"
Else
color r+/n
$x=" - Failed: Error @error"
"$x"
$ErrorState=1
Endif
WriteLog ($LogText + $x)
Color w+/n
Else
WriteLog ("Function 'MapDrive' called with invalid parameters: '$Drive', '$Server', '$Share'")
Endif
Endfunction



[ 18. December 2002, 21:50: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

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 931 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.072 seconds in which 0.027 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