#72245 - 2002-12-18 08:21 PM
Using $variable with the USE command
|
YaleCoder
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
|
|
|
|
#72261 - 2002-12-18 09:49 PM
Re: Using $variable with the USE command
|
Howard Bullock
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 ]
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1821 anonymous users online.
|
|
|