We have a vbs script that runs once a month. The script ran well for the most part but as a couple months ago one command stop working
The vbs script is executed by Windows Scheduler
Inside this script we set a variable called "launch"
Set launch = WScript.CreateObject( "WScript.Shell" )
and later in the program we use this command
launch.run("runthis.BAT")
We do not specify the full path in the command and to my knowledge we never have. This bat file resides in the same directory that the vbs script does. I guess this is why it was setup to run that way.
We are not sure what happened and the sys admins are not sure what could have changed to cause it to no longer work.
Please keep in mind we are not VBS specialists and this is something that has been in place for several years.
Any suggestions or resources to look at would be appreciated.
In order for us to provide a better answer, please update your question with the script you are having trouble with. We don't know what the launch object is - hopefully something other than WScript.Shell. Nevertheless you should be able to run a batch file this way:
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run "C:\your_folder\your_batch_file.bat"
Replace the launch.run part of your script with this code and update it with the correct path and name of your batch file (update "C:\your_folder\your_batch_file.bat" part).
Related
Scenario: We have some scheduled jobs (Control-M) running many proccesses and some of them execute a .VBS file (with parameters) that reads the configuration from an XML file and sends it to a company's software that interprets it and loads data onto tables.
I need help with the VBS file, that as stated above, only gets the instructions from the XML and send it to the software with these steps (also, logs each step):
Finds the XML;
Creates an object to login the software (with XML parameters);
Dim object
Set object = CreateObject("service.location.id")
Login into the Database (with XML parameters);
object.Login("DATABASE_NAME")
Select which Data base (XML...);
object.SelectDatabase("DATABASE_NAME")
Sends command to start load proccess
object.LoadRepositoryTable(XML)
The problem is that since the default interpreter is wscript, when executing the script, it runs on the background and the Job Scheduler thinks it finished executing and starts the next job.
Executing the script on CMD, if I start it as cscript SCRIPT.vbs it waits for the whole load proccess to finish (it doesn't run on background), and I want to do this when running as wscript - because since there are many jobs, editing how they calls the script is not an option right now. This includes creating an .bat file that calls the SCRIPT.vbs as cscript.
I also tried searching on "how to run another .vbs file inside a VB Script" to run as cscript, but didn't manage to make it work.
What can I do?
Is there a way to make wscript wait for the load?
Is there a way to call a .vbs in the same folder (without sending it as parameter) while passing 2 arguments?
Another option I'm not seeing?
Edit: Here is what I've come to so far, but I'm getting "expected end of statement".
Dim objShell
Dim arg_dir
arg_dir = Wscript.Arguments.Item(0)
Dim arg_xml
arg_xml = Wscript.Arguments.Item(1)
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "cmd /k cscript ""C:\Folder\Scripts\SCRIPT.vbs" &" "& arg_dir &" "& arg_xml"", 1, True
cscript is the solution for your problem. Either have your scheduler run each VBScript with cscript.exe, or (if that isn't possible for some reason) make cscript the default script host by running
wscript.exe //h:cscript
once as an administrator.
The script you have cobbled together won't resolve your problem, even if you fixed the syntax error in the last line, because as long as you run it with wscript.exe it will still return immediately. It doesn't matter that the code in that script is running other scripts synchronously as long as all of that is happening in the background.
I need to run a program (a python script made into an exe) on start up, without the console showing up.
In some question, I found the solution, i.e to execute the program. Right now, I'm testing it out with a simple python program filewriter.py that does -
while count != 1000:
f = open('test.txt','a+')
f.write(str(count))
f.close()
sleep 1
The bat file tool.bat :
#ECHO OFF
python "<absolute_path_here>\filewriter.py"
EXIT /B
The VBS file :
Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run Chr(34) & "<absolute_path_here>\tool.bat" & Chr(34), 0
Set WinScriptHost = Nothing
If I execute the VBS file (double-click it), everything works fine. The output file appears, without the console appearing. So I added it to registry under
HKCU\Software\Microsoft\CurrenVersion\Run
as WScript "path_to_the_vbs_file".
On Startup, the VBS file executes properly (verified it by adding a MsgBox which displayed the popup) but the call to the bat file is not being executed. How do I make this work?
In windows there are two python executables: python.exe, pythonw.exe. If you don't wish to see the terminal window you must use pythonw.exe.
I need to run a program (a python script made into an exe).
If you covert your script to .exe with help of py2exe it is simillar. You can assing your script to console or windows. Look to Py2exe Tutorial, the console variable can be replace forwindows.
You don't need to create EXE files from python. You can run pythonw.exe with path as argument to your script. Why do you need to create .bat which you run from vbscript ? Look here: Run on windows startup CMD with arguments
I forgot to say, that the Windows Python installer normally create following file association, so the script can run directly.
'.py' to python.exe
'.pyw' to pythonw.exe
Other way how you can run the the script on boot is to use Windows Scheduler. The big advantage is you can setup user rights or more events when start the script. You can run the script manually too and you will last status.
Create Python .exe is sometimes tricky. If you don't need to distribute your script to multiple computers I prefer don't use.
I am pretty new to all this VBS stuff because basically all I need to do is to make one simple VBS script, which I have possibly written, however, my problem is that it gives me 800A0035 or 800A004C error when I execute it for the first time on a particular PC, as soon as I execute it for the second time, it runs just OK and does what it is supposed to do. Incidentally, on my own computer it works OK even on the first execution.
I know that the errors have something to do with the wrong paths but I have checked my script several times and I am 100% positive that they are correct.
Here is the script:
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "rar.bat" , "rarp.bat"
'HideBat.vbs
CreateObject("Wscript.Shell").Run "rarp.bat", 0, True
What the script is supposed to do is to rename the rar.bat file to rarp.bat and run that batch file (rarp.bat) without popping up the command prompt. What the batch file does is not relevant, I guess, but anyway, it just runs WinRAR.
The rar.bat file and the VBS script are in the same folder, that's why I have used relative paths in the script. I cannot use absolute paths because I need to run the script on several computers.
I have read somewhere on the internet that by default VBS script first looks for the files in C:\Windows\System32 when relative paths are used. I have even tried using absolute paths in the script but it didn't work either. Here is how I need them to look like: %systemdrive%\users\%username%\appdata\roaming\rar.bat but this simply didn't work in the VBS script.
I really think that what I need is really a simple script but apparently it's pretty hard to get it working properly. I will be very grateful to those who help me.
Thank you a lot in advance.
Regards.
The only way your script - at least the part published - can give an error is by not finding the source file for renaming, you should have added full script and error message to be sure.
I suppose this is caused by a security setting on your pc that are more forgiving than on the rest of the pc's, eg UAC ? On the other pc's, try to put the files in a map like c:\test and then run it again after checking that the file rar.bat does exist in the same map. Do you have the same credentials (admin) on the other pc's ?
If you just want to run the bat file hidden, why the renaming ?
how do you download the bat ? and how then is invoked the script ? could be a timing issue that the second time is no longer a problem. In that case check in your script if the file is allready there and do a sleep in a loop while it doesn't
If you want to use the absolute path you could try this
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("PROCESS")
path = WshSysEnv("USERPROFILE") & "\appdata\roaming\rar.bat"
wscript.echo path
objFSO.MoveFile path , "rarp.bat"
CreateObject("Wscript.Shell").Run "rarp.bat", 1, True
I'm struggling to run a program from my VBScript .vbs file. Substituting the line for a MsgBox works fine, so I know its definitely the "open program" line (oShell.Run("Release\My Application.exe")).
Anyway, this is a VBscript called start.vbs which is run from the root directory of a USB drive. It checks to see if .net framework 4.0 is installed and if it is then it should run My Application.exe (note the space... it might make a difference). My Application.exe is in a folder called Release.
As it is a USB drive I can't use explicit drive letters, eg: oShell.run("e:\Release\My Application.exe") although trying this also doesn't appear to work. Typing "e:\Release\My Application.exe" into a cmd window works fine, and runs the program as it is meant to work.
In the vbscript it just doesn't appear to do anything. Any reason?
Here is my code:
Option Explicit
Dim oShell
Dim value
On Error Resume Next
Set oShell = CreateObject("WScript.Shell")
value = oShell.RegRead("HKLM\SOFTWARE\Microsoft\.NETFramework\Policy\v4.0\30319")
If Err.Number = 0 Then
'Here I am struggling
oShell.Run("Release\My Application.exe")
Else
MsgBox("Version 4.0 of the .NET Framework is NOT installed.")
End If
I have commented above the line that doesn't work.
Thank you.
Not quite sure if this is the best answer, but I tried it and it work, so I'll just go ahead and post my idea.
I just used explorer.exe as a mediator and was able to open the file.
So the line that you're stuck with should probably become something like:
oShell.Run("explorer ""Release\My Application.exe""")
I tried it if it'll work in folder that is not in the System path and was able to open the executable.
Note : There may be better approaches.
Update: Thomas reported that the following code worked for him (the approach is better), the idea behind both approaches however is to quote the path (as you would do this in the Command Prompt, so filenames / folders with spaces in the path are properly resolved):
oShell.run("""Release\My Application.exe""")
I am having here a vbs-file which starts a batch script. The batch should run invisible, so i use this vbs-script:
WScript.CreateObject( "WScript.Shell" ).Run "loop.bat",0,0
The vbs is registered to the run-key in the registry-
Everytime on startup it tells me that he cannot find the specified file.
Maybe the Windows Script Host is starting to late for my vbs-script?
What should I do?
vbs with delayed start? This needs another loop, but my script shall be invisible.
vbs in the startupfolder? Better taking the registry. For other reasons I cannot use the startupfolder.
Thanks for your answers :)
I know it's old... But i thought I'd put this in in case anyone stumbles here.
if you add something to run, when it starts unless otherwise specified it's working directory is C:\Windows\System32 so if you point to a file, "mybat.bat" it will assume it's in c:\windows\system32\mybat.bat
that's why you need to specify the whole path in the vbs.
if you are in a bat file then add this to the top of your file:
PUSHD %~dp0
Martyn