Solved Can't run vbscript at the beginning of a batch file.

August 17, 2012 at 10:28:06
Specs: Windows 7
I have been working on this batch file and I want to run a vbscript at the begining to pull some printer info, then export it out to txt file.

The vbscript works file outside of the text file but when I try to call it to run within the bat it never runs. Any help is appreciated.


See More: Cant run vbscript at the beginning of a batch file.

Report •

✔ Best Answer
August 17, 2012 at 10:58:14
Find /C /I "Label" c:\findname.txt
Replace with:
Find /C /I "Label" PrinterName.txt

How To Ask Questions The Smart Way



#1
August 17, 2012 at 10:30:17
I mean the vbscript works outside of the batch file, just not when i'm calling it from the batch file.

Report •

#2
August 17, 2012 at 10:30:28
What do you mean it "never runs?" Why not? How are you calling it?

How To Ask Questions The Smart Way


Report •

#3
August 17, 2012 at 10:34:11
start c:\myscript.vbs

Report •

Related Solutions

#4
August 17, 2012 at 10:35:35
That'll start the script, but your batch file will continue to run while that script runs. Remove the "start" part if you want your batch file to wait for the vbscript.

How To Ask Questions The Smart Way


Report •

#5
August 17, 2012 at 10:40:00
it still doesn't seem to be writing the output from the vbscript out to a text file. The batch file runs then tells me that it can't find the text file.

So when I click the vbscript outside of the text file it will output to a txt file but when i run it within the bat there is no output.


Report •

#6
August 17, 2012 at 10:49:19
That's not how either batch files nor vbscript works. How do you look for the output file? Where do you write the output file in VBScript? Have you tried using WScript.StdOut instead of a file?

Really, if you just posted both scripts, I can see what's going on and we can skip the game of 20 questions.

How To Ask Questions The Smart Way


Report •

#7
August 17, 2012 at 10:57:12
Here is the begginning of my batch file.

@echo off
echo finding printers
c:\findname.vbs

echo looking for printer name
Find /C /I "Label" c:\findname.txt
IF NOT ERRORLEVEL 0 gotto LABELX

Here is my findname.vbs

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("PrinterName.txt", True)

Set objNetwork = CreateObject("WScript.Network")


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer '")
For Each objPrinter in colInstalledPrinters
objFile.WriteLine "Name: " & objPrinter.PrinterName
Next

Maybe this helps...


Report •

#8
August 17, 2012 at 10:58:14
✔ Best Answer
Find /C /I "Label" c:\findname.txt
Replace with:
Find /C /I "Label" PrinterName.txt

How To Ask Questions The Smart Way


Report •

#9
August 17, 2012 at 11:28:25
I think that did it! I really appreciate your help!

I'm not really sure that I understand why that is so. So why isn't it writing the text files out when I run the batch file? and if it is running it where is it putting it?


Report •

#10
August 17, 2012 at 11:44:37
One more question...

I want to now run this batch file invisibly. This is what I have so far.

invisible.vbs

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

launch.bat

wscript.exe "C:\invisible.vbs" "C:\myscript.bat"

So now my batch file works properly when I run myscript.bat but when I run launch.bat to run the script invisibly nothing happens. Any Ideas?


Report •

#11
August 17, 2012 at 12:08:26
where is it putting [the output]?
It saves it to the current directory. This is probably the same directory as your calling batch file.

Any Ideas?
Is "myscript.bat" in the root of C:?

How To Ask Questions The Smart Way


Report •

#12
August 17, 2012 at 12:44:08
yes it is.

Report •

#13
August 17, 2012 at 12:50:56
I understand the first part:

where is it putting [the output]?
It saves it to the current directory. This is probably the same directory as your calling batch file.

That was what I thought it would do but i watch the folder the txt files are suppose to be written to while the batch file is running and none of the txt files appear.

Maybe i'm not understanding your last post...but what do you think is the cause of the issue with running the file invisibly?


Report •

#14
August 17, 2012 at 12:56:59
In which directory does your batch file live?

How To Ask Questions The Smart Way


Report •

#15
August 17, 2012 at 13:03:14
It lives in c:\

Report •

#16
August 17, 2012 at 13:08:50
Without an error message, it's hard to tell, but I assume this'll fix it.

Replace:
CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
With:

CreateObject("Wscript.Shell").Run WScript.Arguments(0), 0, False

How To Ask Questions The Smart Way


Report •

#17
August 17, 2012 at 13:16:23
That works!! Thank You very much for all your help!!

Report •

Ask Question