Rob Sanders
asked on
Problem Calling Bat File from VBS Script
I am trying to use a .vbs file to run a .bat file using the following:
"Set WshShell = WScript.CreateObject("WScr ipt.Shell" )
WSHShell.run "\\servername\folder\subfo lder\batfi le.bat"
but when I do it always tells me the following:
Line: 2
Char: 1
Error: The system cannot find the file specified
Code: 80070002
Source: (null)"
The location specified is definitely correct. If I change the script and location of the bat file to a local drive it runs without issue. I have no idea what is wrong and I'm not familiar with writing scripts. Any help would greatly be appreciated.
"Set WshShell = WScript.CreateObject("WScr
WSHShell.run "\\servername\folder\subfo
but when I do it always tells me the following:
Line: 2
Char: 1
Error: The system cannot find the file specified
Code: 80070002
Source: (null)"
The location specified is definitely correct. If I change the script and location of the bat file to a local drive it runs without issue. I have no idea what is wrong and I'm not familiar with writing scripts. Any help would greatly be appreciated.
try
Set WshShell = WScript.CreateObject("WScr ipt.Shell" )
dim myfile = "\\servername\folder\subfo lder\batfi le.bat"
WSHShell.run myfile
Set WshShell = WScript.CreateObject("WScr
dim myfile = "\\servername\folder\subfo
WSHShell.run myfile
or maybe
Set WshShell = WScript.CreateObject("WScr ipt.Shell" )
WSHShell.run "\\\\servername\\folder\\s ubfolder\\ batfile.ba t"
Set WshShell = WScript.CreateObject("WScr
WSHShell.run "\\\\servername\\folder\\s
ASKER
@NeilSr I can run the bat file manually as the user. Right now that is all I am trying to do before I attempt to run it from a GPO.
@HainKurt After implementing your change it is now saying the following when I run the .vbs file:
Line: 2
Char: 2
Error: The network path was not found.
Code: 80070035
Source: (null)
@HainKurt After implementing your change it is now saying the following when I run the .vbs file:
Line: 2
Char: 2
Error: The network path was not found.
Code: 80070035
Source: (null)
May I ask why you need to run both a vbscript AND a batch file at the same time? Can you not just have a script that does it all OR have more than one login script listed in the GPO?
ASKER
In this environment when we attempt to run a bat file directly upon logon the user receives a Windows security prompt asking if they want to run the file. I have previously worked around this issue by calling the .bat file from a .vbs file. That is what I would like to do here.
i am just guessing :)
maybe you have something in bat file which creates that message!!!
and you have this exactly in your vbs file
in your original post, you have " in front
maybe you have something in bat file which creates that message!!!
and you have this exactly in your vbs file
Set WshShell = WScript.CreateObject("WScript.Shell")
WSHShell.run "\\servername\folder\subfolder\batfile.bat"
in your original post, you have " in front
any log in event viewer?
ASKER
The " in front of the code is not in the actual .vbs file. The application and system event viewer logs do not show anything.
I supposed it is possible that something in the .bat file is causing the message, but again, they work when running them locally. The problem only happens when trying to run the script from a UNC or mapped drive path.
I supposed it is possible that something in the .bat file is causing the message, but again, they work when running them locally. The problem only happens when trying to run the script from a UNC or mapped drive path.
I did a test of your original post and it worked fine here, so I don't think it's a VBS problem per se. I suspect it's privilege related, etc.
~bp
~bp
ASKER
I logged on to the workstation as a domain administrator and ran the .vbs file and had the same problem just to make sure there wasn't a permissions issue.
any log in event viewer?
how do you run this vbs? double click, from cmd prompt?
how do you run this vbs? double click, from cmd prompt?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@HainKurt There was nothing in event viewer.
@Steve Knight Yes, there are spaces in the path. I tried adding the three sets of quotes around the path but it made no difference.
@Steve Knight Yes, there are spaces in the path. I tried adding the three sets of quotes around the path but it made no difference.
OK. can you simplify.
Make a short batch file,
Save that as \\server\share\batch1.cmd , i.e. short filename, no spaces in easy location on share.
Then try JUST this in a VBScript:
Start cmd.exe prompt and:
cscript yourtest.vbs
wscript yourtest.vbs
Any different? If that works try a file with space in the path or filename. If not how about if you run a local .cmd file.
Having just tested it like I thought earlier, I get specifically the error you mention when running a file with spaces in the name and they go away including the extra " at the beginning and end?
Steve
Make a short batch file,
@echo off
echo Running batch file %~f0
pause
Save that as \\server\share\batch1.cmd , i.e. short filename, no spaces in easy location on share.
Then try JUST this in a VBScript:
Set WshShell = WScript.CreateObject("WScript.Shell")
WSHShell.run """\\server\share\batch1.cmd"""
Start cmd.exe prompt and:
cscript yourtest.vbs
wscript yourtest.vbs
Any different? If that works try a file with space in the path or filename. If not how about if you run a local .cmd file.
Having just tested it like I thought earlier, I get specifically the error you mention when running a file with spaces in the name and they go away including the extra " at the beginning and end?
Steve
ASKER
With the simplified bat file I still encounter the same issue.
ASKER
wait, hold on. I didn't read your entire post. Let me try everything and get back with you.
ASKER
Set WshShell = WScript.CreateObject("WScr ipt.Shell" )
WSHShell.run """\\servername\folder\sub folder with spaces\batfile.bat"""
I guess in all the different things I tried, I never tried this specific combination.
WSHShell.run """\\servername\folder\sub
I guess in all the different things I tried, I never tried this specific combination.
ASKER
Whoops, meant to mention in the above post that I just made is that was the code that finally worked and we got this resolved now.
No problem... if you imagine what you type in the Wshshell.run command is what you would have to put in, say, the START command, e.g.
then it will run \\servername\folder\sub
so you would have to run it with quotes to run the whole correct path:
You have to add the title to START as the first item in " " is the title so without it the batch file does not run.
The first " starts the string, the next one escapes the one after it to include in the string which is why you end up with 3.
Steve
START \\servername\folder\sub folder\batch file.cmd
then it will run \\servername\folder\sub
so you would have to run it with quotes to run the whole correct path:
START "TITLE" "\\servername\folder\sub folder\batch file.cmd"
You have to add the title to START as the first item in " " is the title so without it the batch file does not run.
The first " starts the string, the next one escapes the one after it to include in the string which is why you end up with 3.
Steve
if you put your question like
WSHShell.run "\\servername\some folder\sub folder\batfile.bat"
or
WSHShell.run "\\SRV001273X\User Files\Test Files\batfile.bat"
or
just post the actual path, then you would get the answer immediately :)
WSHShell.run "\\servername\some folder\sub folder\batfile.bat"
or
WSHShell.run "\\SRV001273X\User Files\Test Files\batfile.bat"
or
just post the actual path, then you would get the answer immediately :)
Can you execute \\servername\folder\subfol
Is this called by a user or is it maybe in a GPO?