Hello,
Debugging scripts within AD can be fun (with some liberties taken in the definition of "fun").
There are several things that you can do. One would be to combine both scripts into one. That way there is no worry about asynchronicity (unless the situation in option two is happening).
Option two would be to use the DriveExists method on your second script. Sometimes it take a couple of bits for a drive to map or unmap (which could be why it sometimes works and sometimes does not). You could use the DriveExists method to wait until the drive does not exist (with a cutoff of a maximum number of seconds so you don't get stuck in a loop). You can look at this technet site for info about that method: http://msdn2.microsoft.com/en-us/library/t565x0f1.aspx
Here is the code that I made for that:
Set objFSO = CreateObject("Scripting.FileSystemObject")
strDrivePath = "q" 'Use drive letter or UNC path (does not seem to be case sensitive)
bolWait = True
While bolWait = True
WScript.Sleep 100 '1/10 of a second
intCounter = intCounter + .1
If objFSO.DriveExists(strDrivePath) Then
bolWait = False
End If
If intCounter >= 10 Then 'Waits for 10 seconds-adjust as needed
bolWait = False
End If
Wend
An another option, you could also have your two scripts write to a log file to see if they are indeed overlapping. Toss the following code into your scripts.
const txtDebugLogFile = "c:\DebugLog.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.opentextfile(txtDebugLogFile,8,true)
strStartTime = Time()
'
'Put the rest of your script here
'
strEndTime = Time()
objLogFile.writeline Wscript.ScriptFullName & "," & txtStartTime & "," & txtEndTime
objLogFile.close
There are probably more ways to look at this but hopefully this will help. Best of luck and feel free to respond with questions if needed.