Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing a connection after employing MapNetworkDrive method 1

Status
Not open for further replies.

adamrobert

Programmer
Oct 15, 2003
5
GB
Hi,

Initially a big thanks to 'spazmann' for his earlier assistance.

I am employing the MapNetworkDrive method to connect to a server using the code below but I can't find a method which will close the connection once my file transfer process has completed.

Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "P:","\\SERVER\myshare", false, "username", "password"

Any advice would be really appreciated.

Cheers.
 
Hello adamrobert,

It is .RemoveNetworkDrive method.
Code:
Dim WshNetwork
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemoveNetworkDrive "P:"
Note options avail
Code:
object.RemoveNetworkDrive(strName, [bForce], [bUpdateProfile])
regards - tsuji
 
Hi tsuji,

Where do I need to include the RemoveNetworkDrive method in my code?

Is VBScript executed in a top-down fashion and if so then should I include the method at the end of my code?

Cheers,

adamrobert
 
adamrobert,

Sure. Something like...
Code:
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive "P:","\\SERVER\myshare", false, "username", "password"

'do all the necessary thing
'make avail for all the necessary time

'If WshNetwork instance had been dereferenced
'else spare the following line
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemoveNetworkDrive "P:"
Set WshNetwork = Nothing
regards - tsuji
 
Addendum

Also, should add that, if the above might mislead, you do not need to map and remove in one single vbs, obviously.

- tsuji
 
do you need to map a drive for a file transfer?? cant you just use a url instead?
 
Thanks for clarifying that tsuji.

Cheers for all your help.

adamrobert
 
Guys
I am new to this scripting thing.
Let me explain what I am trying to do.
I am trying to send a report which is in flat ASCII
format to a file on a network drive.
Then I want it also to print out on a high speed
dot matrix printer connected to a print server.

Any sample scripts I can get started on?
All help is greatly appreciated.
Thanks..AC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top