On boot, issues running a bat file through vbs script - windows

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.

Related

Is there a command in Shell scripting for executing .exe file and running commands automatically inside of it? replacing the user interaction

I have a .sh script file that I'm modifying which runs an .EXE file that opens the Windows command line prompt automatically.
This .exe asks the user for an input (name of the file in the folder workspace that it will read)
I want to automate this step in my shell script so my user doesn't have to interact with this, and run the commands automatically
I read a bit about the expect command but I think that is for Linux only.
Can someone help me, I'm pretty new to Shell scripting and I couldn't find any useful information elsewhere.
I'm assuming that your executable accepts command-line arguments. So, here we go.
You can use the "start" command in Windows Shell. For example:
start C:\path\to\program.exe -argument
If you want to make the script wait until the .exe file finishes running before continuing, you can use the "/wait" command:
start /wait C:\path\to\program.exe -argument
IF all of that doesn't work, please try:
start myprogram.exe /command1 /command2 /command3
Hope it helps,

VBScript file stops immediately after executing non local executable

I have two files in one folder, a vbs file called notify.vbs and an executable called foo.exe.
the foo.exe is a node.js pkg-bundled executable that triggers a native desktop notification with a random message from a local text file after 5 seconds from execution. Although pkg had one inconvencience which is that executing foo.exe launches a cmd interface, which doesn't suit my purpose. This is where notify.vbs come in handy as it can execute foo.exe while keeping the cmd interface hidden just like I wanted. notify.vbs looks like this:
Set oShell = CreateObject("Shell.Application")
oShell.ShellExecute "foo.exe", , , "runas", 1
It works fine. But then, when I change the location of foo.exe for example in a folder called bar directly in the C drive and change the path in the script to:
Set oShell = CreateObject("Shell.Application")
oShell.ShellExecute "C:\bar\foo.exe", , , "runas", 1
the script starts foo.exe and closes it immediately.
Basically notify.vbs only executes foo.exe when they're in the same folder. When I change the location of either of them it does that weird behaviour I mentioned. I verified the functionality of foo.exe in different locations. It always works. I even verified the path in script each time I tried a different location, it's always correct as it actually does execute foo.exe but it closes it immediately after.
I have no experience with VBScript as I copy pasted that script. Thanks in advance.

installation without showing command prompt

i have made a installer with installshield 2008 .
main problem is , while installation through setup.exe , command prompt appears several time in this procedure. for convenience of end user i need to remove command prompt during installation.
i read in previous threads i can call my batch file through a vbscript as a solution
and i have tried to use vbscript in installshield 2008 instead of my batch file to run my batch file indirectoly through vbscript, it did not worked for me as a solution ..
please tell me , if i use vbscript to run my batch file then how can i include this vbsript in installshield
or , an
You're on the right track with the VBS, but I don't believe it needs to be that complex.
All you need is a VBS file (let's call it hide.vbs). It contains CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False.
To activate it, put in the command wscript.exe "hide.vbs" "file_path" where file_path is the path to the batch file you want started.
Hope that helps.
Why execute a batch script via a vbscript when you could do it better via a vbscript custom action? Doesn't make sense to me. Run the setup.exe silently by creating an answer file:
setup.exe /r
Writes to response file 'C:\windows\setup.iss'.
setup.exe /r /f1"C:\windows\temp\setup.iss"
Writes to file 'C:\windows\temp\setup.iss'
Then all you need to do is install the setup.exe silently:
setup.exe /s /f1"C:\windows\temp\setup.iss"

Batch File calls VBScript which calls EXE that won't open

I have a VBS file 'migration.vbs' that runs a number of commands and then calls an AutoIt .exe file to begin the uninstall of a product. The entire script runs successfully when you call it by itself from the command line with 'cscript migration.vbs'
This script is going to be pushed out to a number of other machines where techs need to be able to double-click to run it. A lot of the machines don't execute VBS by default on a double click, so I've added a batch file to run it.
The problem is that when the batch file calls the VBS, it starts to run but never calls the exe. It just.. skips that step. I'm guessing there's an issue with nested system calls or something that I don't know about.
Anyways, any solutions? I'd rather not put the EXE call in the batch file due to logic checking the VBS does against registry keys (that'd be hard/impossible to duplicate in BAT).
Thanks again
start.bat
START /WAIT cscript .\data\migration.vbs
migration.vbs
WSHSHell.Run "uninstall.exe", 0, True
There is no nested system calls limit, I'm guessing that the path or current directory is wrong, try using a full path or monitor the filesystem calls with Process Monitor

How do I make a shortcut for a Perl program under Windows using a batch file?

I'm trying to "hide" some of my Perl program from the end user to make things easier on them. I'm doing what I can to keep them out of the command prompt. The program itself has a GUI designed in Perl/Tk, so they don't have to worry about the command prompt.
Could I write out a quick batch file that goes along the lines of:
START perl 'C:\[some path here]\myscript.pl'
with START to start a program, the Perl interpretor as my program, and the path/name of my Perl script as the parameter?
Would I have to specify where to find perl or would Windows just know because perl is in the computer's PATH variable?
I have a totally evil VBS script and batch file to deal with this kind of thing with Strawberry Perl Portable. The VBS script runs the batch file without spawning a cmd window. The batch file works out where it is, where perl.exe is relative to it, and runs the perl script. In this case it's to run a Catalyst server, but can be used for anything else too.
Here's the vbs (shudder):
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & fso.GetParentFolderName(wscript.ScriptFullName) & "\perlshell.bat"& Chr(34), 0
Set WshShell = Nothing
And here's the batch script (only slightly less shudder):
echo off
set bindir=%~dp0
set perlpath=%bindir%perl\bin
set buildpath=%bindir%\bin
set PATH=%PATH%;%perlpath%;%buildpath%
"%perlpath%\wperl.exe" "%bindir%MyPhp\script\myphp_server.pl" -p 35900
you don't need "start" for this. either add perl.exe from your path or specify the full path to the perl interpreter.
so ... put this in your batch file:
c:\program files\perl.exe "c:\whatever\myscript.perl"
-don
If the idea is to keep them away from the command line, why use a batch file at all? Why not just make a shortcut? (You could use Win32::Shortcut if you don't want to make one by hand.)
There's an easier way. For windows:
Go to the desktop -> right click -> create a shortcut
make your target look like (i.e. the path to the perl.exe file) something like the following - I'll show you what mine looks like
C:\Strawberry\perl\bin\perl.exe
In my case I have Strawberry Perl installed
right click desktop shortcut -> click properties
In the target input box, alter it to look something like mine:
C:\Strawberry\perl\bin\perl.exe D:\Developer\CustomTools\login.pl
where login.pl is the absolute path to my perl script
from there you should have a shortcut created to allow execution of a perl script.
In case you might be interested:
in the properties popup you can also assign this invocation of the perl script to a keyboard button press and assign it a shortcut key to launch anytime ^_^
For me, I chose to do:
ctrl+alt+i
to stand for login - to invoke the login.pl script I wrote. be aware of default system keyboard combinations
If you have any questions, let me know!
Thanks for you time!

Resources