Jump to content

If Network Drive Exist Before Mapping


Recommended Posts

Newbie question. How in Auotit do you check if a drive is already mapped before trying to map it? Looking thru the Forms and looking thru the Help files I see the DriveMapGet function and see that it will return a @error value. My question I guess is how do you write the If/Then statement to check if it is there then either map the drive or go on to the copy the files? I am cleaning up some logon scripts that have VBscript, Bat files, and some Exes and want to do it all in AutoIt so they can be compiled into one exe. Any help would be appriciated. Thank you.

Link to comment
Share on other sites

Okay, here's some untested code that may help out:

$drives = DriveGetDrive("all")
 If NOT @error Then
 ; Performs check on each drive listed within system
   For $DriveNum = 1 to (Ubound($drives) - 1)
     $stat = DriveStatus($drives[$DriveNum])
     MsgBox(4096, "Drive Status", "Drive " & $drives[DriveNum] & " is " & $stat)

   ; Only proceed if drive is readable
     If $stat == "READY" Then 
      ; Do checks for active drives here
     EndIf

   Next
 EndIf
EndFunc

...I don't have AutoIt installed on this box (it's not mine), so I can't check if there are any bugs in the script.

Also, keep in mind that most Windoze based systems have a "net use" command that lists the currently mapped drive names/locations.. You could also parse the output from this command if you wanted.

Link to comment
Share on other sites

...I don't have AutoIt installed on this box (it's not mine), so I can't check if there are any bugs in the script.

<{POST_SNAPBACK}>

You mean you don't have the AutoIt files on a CD or floppy or memory stick to use when you're on the go? :ph34r:

:(

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

You mean you don't have the AutoIt files on a CD or floppy or memory stick to use when you're on the go?  :(

Of course I had a copy of AutoIt! :lol:

I was just working on a test machine, and didn't want to deal with all of the Corporate BS that goes along with installing unapproved software on a test box. :ph34r:

Link to comment
Share on other sites

if the goal is to make sure a user has a certain drive mapped, say Q: to a certain server, but to not remap if it's already mapped to something else, maybe something like this:

$Idrive = DriveMapGet ("q:")
if $idrive == "" then;drive not in use, so free to map it
   DriveMapAdd("q:", "\\server\share", 1);use your own option flags of course.
Else
   MsgBox(0, "whatup?", "q: drive already in use by " & $Idrive)
 ;so do what you want to do.  Do you want to disconnect it and change it to a new server?
   if $idrive = "\\olderserver\share" Then;say that \\olderserver was just replaced with \\server and you moved the share
      DriveMapDel("q:")
      DriveMapAdd("q:", "\\server\share", 1)
   EndIf
EndIf
Edited by emmanuel

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

Link to comment
Share on other sites

What I am doing is cleaning up some log on scripts, and combining them into 1 Auotit exe. (if I can). I need to see if the I: drive is mapped and if it is not then map it. I want this to be done with out user intervention and silently. I am using AutoIt v3. Thanks for the responses and help.

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...