Sign in to follow this  
Followers 0
beato

Check network resource / drive mapping probs

3 posts in this topic

I’m making a start program to kick off an application (pretend its MS Word) but before it starts the Word EXE, I’m performing a bunch of pre-checks – like networking resources fist. This start program could be run many times throughout the day. Sometimes for whatever reason a user might have a flakey network connection or while at they stepped away from their computer something happened on the network but has been restored.

However, in explorer it will display a red tick for example, but “DriveStatus” can’t decipher this and doesn’t know what to do - how can I string together as many verifications and re-try’s on the status of a network resource, if there is an error put up a msgbox otherwise continue on and kick off the main EXE. I'm not getting how to use @error in this as well. I see many different ways people use @error (with or w/o codes) but its not clicking.

So, I need to map \\server1\folder1 as drive X:

  • Check the status of URL and if it is “invalid” then map it
  • If its already mapped (it should be as its in the domain log in script) then move on and kick off the second EXE
  • If the network gets disconnected during the day and user launches the start program the drive letter is already mapped (has a red tic mark) e.g. “in use” but sometimes you need to click it in order to re-instate it => so the status is kind of in between => as a test, I log in and the drive is mapped. Launch the application and all is good. Close the application, unplug my network cable and now the drives are red. Reconnect network cable and if I run my script, but “DriveMapAdd” still cannot “re-connect” drives
This is what I have, or am trying to get working.

While 1
   For $i = 13 To 15
    If DriveStatus (Chr($i) & ":") = "INVALID" then
;~    GUICtrlSetData($progressbar1, (20 - $p))
     DriveMapAdd("X:", "\\Server1\folder1")
     DriveMapAdd("Z:", "\\Server1\folder2")
    EndIf
     If Not @error Then
     ShellExecuteWait('X:\Server1\folder2\start2.exe')
     Else
     $var = DriveGetDrive("NETWORK")
     If @error Then
      For $i = 1 To $var[0]
       If StringUpper($var[$i]) = "XO:" Then
;~       GUICtrlSetData($StatusLabel, "Network Mapping Problems...")
;~       GUICtrlSetData($progressbar1, (40 - $p))
        MsgBox (0, "Network Mapping Problem", "Unable to Map X Drive...Contact Admin.")
        Sleep(3000)
        Exit
       EndIf
      Next
     EndIf
   Next
   ExitLoop
  WEnd

Share this post


Link to post
Share on other sites



You could add a check like this. You could perform so many checks that the code could be quite long. You could perform a Ping check and if @error = 0 , then the machine cannot connect to the server.

While 1
For $i = 13 To 15
  If DriveStatus(Chr($i) & ":") = "INVALID" Then
;~    GUICtrlSetData($progressbar1, (20 - $p))
   DriveMapAdd("X:", "\\Server1\folder1")
   DriveMapAdd("Z:", "\\Server1\folder2")
   $DriveXChk = DriveStatus("X:")
   $DriveZChk = DriveStatus("Z:")
   If $DriveXChk <> "READY" Then
    MsgBox(0,"Problem","Attempting to remap X Drive")
    DriveMapAdd("X:", "\\Server1\folder1")
    If @error = 6 Then
     MsgBox(0,"Problem","Your credentials are incorrect")
     $username = InputBox("Username","Enter username")
     $password = InputBox("Password","Enter your password","","*")
     DriveMapAdd("X:", "\\Server1\folder1",0,$username,$password)
    EndIf
   EndIf
  EndIf
  If Not @error Then
   ShellExecuteWait('X:\Server1\folder2\start2.exe')
  Else
   $var = DriveGetDrive("NETWORK")
   If @error Then
    For $i = 1 To $var[0]
     If StringUpper($var[$i]) = "XO:" Then
;~     GUICtrlSetData($StatusLabel, "Network Mapping Problems...")
;~     GUICtrlSetData($progressbar1, (40 - $p))
      MsgBox(0, "Network Mapping Problem", "Unable to Map X Drive...Contact Admin.")
      Sleep(3000)
      Exit
     EndIf
    Next
   EndIf
  Next
  ExitLoop
WEnd

Share this post


Link to post
Share on other sites

You could add a check like this. You could perform so many checks that the code could be quite long. You could perform a Ping check and if @error = 0 , then the machine cannot connect to the server.

While 1
For $i = 13 To 15
  If DriveStatus(Chr($i) & ":") = "INVALID" Then
;~  GUICtrlSetData($progressbar1, (20 - $p))
   DriveMapAdd("X:", "\\Server1\folder1")
   DriveMapAdd("Z:", "\\Server1\folder2")
   $DriveXChk = DriveStatus("X:")
   $DriveZChk = DriveStatus("Z:")
   If $DriveXChk <> "READY" Then
    MsgBox(0,"Problem","Attempting to remap X Drive")
    DriveMapAdd("X:", "\\Server1\folder1")
    If @error = 6 Then
     MsgBox(0,"Problem","Your credentials are incorrect")
     $username = InputBox("Username","Enter username")
     $password = InputBox("Password","Enter your password","","*")
     DriveMapAdd("X:", "\\Server1\folder1",0,$username,$password)
    EndIf
   EndIf
  EndIf
  If Not @error Then
   ShellExecuteWait('X:\Server1\folder2\start2.exe')
  Else
   $var = DriveGetDrive("NETWORK")
   If @error Then
    For $i = 1 To $var[0]
     If StringUpper($var[$i]) = "XO:" Then
;~     GUICtrlSetData($StatusLabel, "Network Mapping Problems...")
;~     GUICtrlSetData($progressbar1, (40 - $p))
      MsgBox(0, "Network Mapping Problem", "Unable to Map X Drive...Contact Admin.")
      Sleep(3000)
      Exit
     EndIf
    Next
   EndIf
  Next
  ExitLoop
WEnd

Hey Thanks - I'm checking your example. I'll report back.

Share this post


Link to post
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
Sign in to follow this  
Followers 0