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!

Finding a drive in a script

Status
Not open for further replies.

Cretin

Technical User
Jan 2, 2003
194
US
Hey, I am trying to run a .bat file in a script. I got that part but now it gets a tad more involved. is what I would like to do is have a .vbs file sitting on a drive lets call it the O drive. I would like this script to run either a .bat or .exe file on another drive lets call it the D drive. The following is the code I have.


Option Explicit
Dim strDriveLetter, strRemotePath, strNewName
Dim objNetwork, objShell
Dim CheckDrive, AlreadyConnected, intDrive

strDriveLetter = "D:"
strRemotePath = "\\SERVER\folder1\folder2"
strNewName = "Server_name"

dim shell
set shell=createobject("wscript.shell")
shell.run "strDriveLetter.strRemotePath.test.bat"
set shell=nothing


When i run the script I get the message cannot find the file specified. the file is in the correct folder. I did try to google for a solution to no avail. Any ideas would be very appreciated.

Cretin
 
Put a line like this instead of the .run line.
[tt] wscript.echo "strDriveLetter.strRemotePath.test.bat"[/tt]
What kind of path is it? see for yourself.
 
It just gives me a windows host script box that says:

strDriveLetter.strRemotePath.test.bat

Then I click ok I am not sure what that is trying to tell me.



Cretin
 
I am taking baby steps. I found the following code on Microsofts web site.

Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")
oShell.run "cmd /K CD C:\ & Dir"
Set oShell = Nothing

Howver when I run that it displays the directory the script resides on not the directory I am trying to change too.

Cretin
 
Why not simply this ?
oShell.run "cmd /K Dir C:\"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That worked thank you. Now the nnext thing I need to figure out how to do is execute the .bat file at a different directory thank you.

Cretin
 
Ok that displays the directory but I need to actually change directories so I can run a .bat file there.

Cretin
 
If you don't acquire the common sense of how to debug, you will busy all the time to look for scripts all over the net and find no one really suit your need. That's not the way to go.

What do you mean by dotting those variables? (double quote in vbs will not interpolate variables, and besides, even if it interpolates, and dot stands for concatination,
strDriveLetter.strRemotePath.test.bat
is not a correct path/unc to any resource.
 
I figured that was incorrect when i tested it. Is where I am at now is this code:

Dim oShell
Set oShell = WScript.CreateObject("WSCript.shell")
oshell.run "cmd /K CD @H:\ & dir"
Set oShell = Nothing

Instead of showing me the directory on the H drive it is showing me the directory of the current directory I am in.
O:\test\

Is wjhat I need to do is figure out how to change directories in a VB script and run a .bat file in the directory I changed too.

Cretin
 
oshell.run "cmd /K H: & CD \ & dir"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
>Instead of showing me the directory on the H drive it is showing me the directory of the current directory I am in. O:\test\
[tt]
Set oShell = WScript.CreateObject("WSCript.shell")
oShell.currentdirectory="H:\"
oshell.run "cmd /K dir"
[/tt]
 
Thanks thats what I needed for now.

Cretin
 
Cretin,

What tsuji was trying to get you to see is that you were sending the variables as text to the command interpreter.

tsuji said:
Put a line like this instead of the .run line.
wscript.echo "strDriveLetter.strRemotePath.test.bat"
What kind of path is it? see for yourself.

If you put
Code:
wscript.echo strDriveLetter & strRemotePath & "test.bat"
that should look more like you were expecting. Of course, the logic in that still needs some work, because your strRemotePath is a UNC and you would not need the strDriveLetter as part of it, and you would need a "\" between strRemotePath & "test.bat", so you could change "test.bat" to "\test.bat", then trim out the other unnecessary stuff making your code
Code:
Option Explicit

Dim strRemotePath
Dim objShell

strRemotePath = "\\SERVER\folder1\folder2"

Set objShell = CreateObject("WScript.Shell")
objShell.Run strRemotePath & "\test.bat"

Set objShell = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top