Home All Groups Group Topic Archive Search About

delay for consecutive commands



Author
17 Oct 2007 5:25 PM
Honza B.
I need to process two WshScripts methods consecutively, such as remove
network drive and map another network drive.
When I try process method RemoveNetworkDrive and MapNetworkDrive
consecutively then Error occured on MapNetwordDrive command because network
drive is still maped or the new RemotePath not apply. When I paste other
command between this two methods, , such as Echo or PopUp, then all is OK.

Which is the best way to delay script to process two consecutive commands
without unnecessary delay obstruction? Thanks.

Sample:
1. Assign drive letter I: to network drive (such as "\\server\folder1".
Network drive is mapped on "\\server\folder1".
2. Try to use this script:

Set objWshNetwork = CreateObject("WScript.Network") 
strDriveLetter = "I:"
strRemotePath = "\\server\folder2"
objWshNetwork.RemoveNetworkDrive strDriveLetter, True, True
'WScript.Echo "Delay"
objWshNetwork.MapNetworkDrive strDriveLetter, strRemotePath, True

Network drive is not mapped on "\\server\folder2", but is still mapped to
"\\server\folder1". When you allow Echo, then is network drive mapped on
"\\server\folder2". Nice.

Author
17 Oct 2007 6:34 PM
Richard Mueller [MVP]
Honza B. wrote:

Show quote
>I need to process two WshScripts methods consecutively, such as remove
> network drive and map another network drive.
> When I try process method RemoveNetworkDrive and MapNetworkDrive
> consecutively then Error occured on MapNetwordDrive command because
> network
> drive is still maped or the new RemotePath not apply. When I paste other
> command between this two methods, , such as Echo or PopUp, then all is OK.
>
> Which is the best way to delay script to process two consecutive commands
> without unnecessary delay obstruction? Thanks.
>
> Sample:
> 1. Assign drive letter I: to network drive (such as "\\server\folder1".
> Network drive is mapped on "\\server\folder1".
> 2. Try to use this script:
>
> Set objWshNetwork = CreateObject("WScript.Network")
> strDriveLetter = "I:"
> strRemotePath = "\\server\folder2"
> objWshNetwork.RemoveNetworkDrive strDriveLetter, True, True
> 'WScript.Echo "Delay"
> objWshNetwork.MapNetworkDrive strDriveLetter, strRemotePath, True
>
> Network drive is not mapped on "\\server\folder2", but is still mapped to
> "\\server\folder1". When you allow Echo, then is network drive mapped on
> "\\server\folder2". Nice.

I've never had this problem, or heard of anyone that did. However you can
use the Sleep method of the Wscript object, specifying milliseconds. For
example, to pause 0.1 second, use:

Wscript.Sleep 100

Most likely 1/10 second would do.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

AddThis Social Bookmark Button