Jump to content

get the path of a mapped drive?


Recommended Posts

I'm having to re-map all of someone's network drives, and (having to do it for 5 drives on average for 20+ people) I want to make a script to get a list of their drives, then re-map them to the same location... I could use DriveGetDrive to get a list of all the networked drives, but how would I get the path?

asking the question just reminded me, these are kept in the registry, aern't they?

... going to look there ...

any ideas though?

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

Hi,

I did it with 'piping' through "net use > netuse.log".

Then I read this file with 'stringfiltering' to an array and that was it...

oh man... if you've got that, I'd be eternally grateful! string manipulation's still a bit od to me (I'm so happy with myself for the stringinstring on the path deal) :D

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

Oh, I don't know what you mean exactly, I did it (I think...script is at work and I'm at home) like this, simply:

Global $drivearray[25][2]
Global $logfile = @TempDir & "\netuse.log"

RunWait(@Comspec & " /c net use | find /i ""\\"" >" & $logfile,"",@SW_HIDE)

$file = FileOpen($logfile,0)
$idx = 0
While 1
   $line = FileReadLine($file)
   If @error = -1 Then ExitLoop
   $driveletter = StringMid($line,StringInStr($line,":") - 1,1)
   $drivepath = StringMid($line,StringInStr($line,"\\"),StringInStr($line,"Microsoft Windows-Netzwerk") - StringInStr($line,"\\"))
   $idx = $idx + 1
   $drivearray[0][0] = $idx
   $drivearray[$idx][0] = $driveletter
   $drivearray[$idx][1] = $drivepath
   msgbox(0,"",$driveletter & @LF & $drivepath)
Wend
FileClose($file)
FileDelete($logfile)
Edited by Holger
Link to comment
Share on other sites

ok, so, had a little word-wrap error, and a difference in the "Microsoft Windows Network"

now to make it re-map the drives... funny, I'd tried to look in the registry for the mapped drives, and didn't find several of the drives I'd manually mapped... f'in windows. I'll be using your method, hopefully it'll help me understand the world of string manipulations.

Global $drivearray[25][2]
Global $logfile = @TempDir & "\netuse.log"

RunWait(@ComSpec & " /c net use | find /i ""\\"" >" & $logfile, "", @SW_HIDE)

$file = FileOpen($logfile, 0)
$idx = 0
While 1
   $line = FileReadLine($file)
   If @error = -1 Then ExitLoop
   $driveletter = StringMid($line, StringInStr($line, ":") - 1, 1)
   $drivepath = StringMid($line, StringInStr($line, "\\"), StringInStr($line, "Microsoft Windows Network") - StringInStr($line, "\\"))
   $idx = $idx + 1
   $drivearray[0][0] = $idx
   $drivearray[$idx][0] = $driveletter
   $drivearray[$idx][1] = $drivepath
   MsgBox(0, "", $driveletter & @LF & $drivepath,1)
   RunWait("NET USE " & $driveletter & ": " & $drivepath & "/PERSISTENT:YES", "", @SW_HIDE)
Wend
FileClose($file)
FileDelete($logfile)

Just a little edit to the code, it now maps each drive as persistant, exactly what I need this for! Thank you Holger!

Edited by emmanuel

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

yah know what's funny? running a script to remap your network drives while mapped to the drive that you're running it off... gave me this error

---------------------------
AutoIt
---------------------------
Error reading the file:

S:\ErrorStdOut
---------------------------
OK   
---------------------------

hmmm... that doesn't seem to be the cause...

what's going on?

---------------------------

AutoIt

---------------------------

Error reading the file:

\\spseprt1\windist\ErrorStdOut

---------------------------

OK

---------------------------

I'm sure I need to talk to JdeB about this...

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

I love talking to myself... :D found an interesting (I want to smack someone for this one) problem... my username has a & in it... so using the @tempdir creates a path with a & in it... and as Valik recently pointed out, any filename with a & in it needs quotes around it... pain in the ass beurocracy that doesn't know about computers... anyways, yeah. just a minor fix to make it work with any of those symbols... fun with quotes... a bit of error handling for the case that the logfile can't be read...

If MsgBox(4, "Remap Network Drives v.01", "Would you like to remap all existing drives as persistant?") = 7 Then
   Exit
EndIf

Global $DRIVEARRAY[25][2]
Global $LOGFILE = @TempDir & "\netuse.log"
; C:\DOCUME~1\&eplesh\LOCALS~1\Temp\netuse.log

RunWait(@ComSpec & ' /c net use | find /i "\\" > "' & $LOGFILE & '"', "c:\")

$FILE = FileOpen($LOGFILE, 0)
If $FILE = -1 Then 
   MsgBox(0, "Remap Network Drives v.01", "Error opening " & $LOGFILE)
   Exit
EndIf
$IDX = 0
While 1
   $LINE = FileReadLine($FILE)
   If @error = -1 Then ExitLoop
   $DRIVELETTER = StringMid($LINE, StringInStr($LINE, ":") - 1, 1)
   $DRIVEPATH = StringMid($LINE, StringInStr($LINE, "\\"), StringInStr($LINE, "Microsoft Windows Network") - StringInStr($LINE, "\\"))
   $IDX = $IDX + 1
   $DRIVEARRAY[0][0] = $IDX
   $DRIVEARRAY[$IDX][0] = $DRIVELETTER
   $DRIVEARRAY[$IDX][1] = $DRIVEPATH
   MsgBox(0, "", $DRIVELETTER & @LF & $DRIVEPATH, 1)
   RunWait(@ComSpec & " /c NET USE " & $DRIVELETTER & ": " & $DRIVEPATH & "/PERSISTENT:YES", "", @SW_HIDE) 
Wend

FileClose($FILE)

If MsgBox(4, "Remap Network Drives v.01", "Would you like to view the list of remapped drives?" & @LF & "The logfile will be deleted at the end of the script, so if you want to keep it, save it somewhere else.") = 6 Then
   RunWait('notepad.exe "' & $LOGFILE & '"')
EndIf

FileDelete($LOGFILE)
and a few other niceties as well... may or may not remove the

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

  • 1 year later...

I know this is an old topic, but I was searching for something else and found this topic

Anyway, I decided to add a way to do this with the new network drive features of AutoIt

Func _Remap()
$drv = DriveGetDrive("NETWORK")
If @error Then Exit
For $i = 1 to $drv[0]
    $share = DriveMapGet($drv[$i])
    DriveMapDel($drv[$i])
    DriveMapAdd($drv[$i], $share)
Next
EndFunc

We have enough youth. How about a fountain of SMART?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...