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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merge 2 scripts

Status
Not open for further replies.

heimly

Technical User
Jul 22, 2010
5
NO
I wish to disconect nettwork's path after the job is finiched.

I have make 2 scripts that work fine but i wish merge it.

The first is:
Dim WshNetwork
Dim objShell

Set WshNetwork.CreateObject ("WScript.Network")
WshNetwork.MapNetworkDrive "O:", "\\Servername\Shere",,"username", "Password"

Set objShell = CreateObject ("WScript.shell")
objShell.Run "%comspec% /c C: cd logs & dir dir >O:\text.txt
WScript.

The Second is:

Dim WshNetwork
Set WshNetwork.CreateObject ("WScript.Network")
WshNetwork.RemoveNetworkDrive "O:"

Is it posible to do it ?

Thanks for any help
Erik
 
Your command line looks wrong!? (apart from a closing quote.) Otherwise you can do it like that.
[tt]
Dim WshNetwork
Dim objShell

Set WshNetwork.CreateObject ("WScript.Network")
WshNetwork.MapNetworkDrive "O:", "\\Servername\Shere",,"username", "Password"

Set objShell = CreateObject ("WScript.shell")
[blue]dim scmd 'I isolate it because it looks wrong.
scmd="%comspec% /c C: cd logs & dir dir >O:\text.txt"[/blue]
objShell.Run scmd[red],,true[/red] 'make it synchronous
WshNetwork.RemoveNetworkDrive "O:"
[/tt]
 
Anyway, I'd replace this:
Set WshNetwork.CreateObject ("WScript.Network")
with this:
Set WshNetwork = CreateObject("WScript.Network")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks it works.

md="%comspec%, Can I use the following command on all cmd scripts
 
>...on all cmd scripts
As far as the .run is concerned, you can use %comspec% environment variable (and sure under the assumption that comspec environment variable is set to point to the cmd.exe or command.com - old os). That is normally so, until now, and I don't know any firm undertaking from ms to maintain this compatibility.

The command line looks wrong that I alluded to is, at least, the lack of concatination (&) between "c:" and "cd logs" that I don't see how it would work to settle in directory "logs" generally.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top