Windows Script Host cannot find the file on startup - windows

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

Related

VBS Command "launch.run" no longer executing

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).

Windows %CD% environment variable not being updated

I have this simple batch file (test.bat):
echo %CD%
pause
No matter where I run this .bat file from (i.e. C:\some\dir\test.bat), my system tells me that I'm in C:\ . This is obviously neither the intended nor the desired behavior, and if I try the exact same script on a different machine, it behaves as expected, giving me current directory of the .bat file. I've been googling for hours now and haven't been able to find anything relevant to my issue. Perhaps I missed up a windows setting somewhere? I have no idea, anyone have any ideas?
Found the issue: there was an AutoRun registry entry that would change directory to C:\ whenever a shell was opened. facepalm

issues in exe files from bat files

ok...Im a new member here and I can express how jolly I am...back to subject
I made a bat file, lets call it 1.bat and I used iexpress to make it an exe file, lets call it 1.exe.
So, in the batch file I added the command line to add a vbs file ( call it 1.vbs ) which is also included in the exe package (1.bat and 1.vbs are in 1.exe) but it installs 1.bat, so in the command I typed:
copy "1.vbs" "C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
If I run the bat file it copies the vbs file to start up, but if I make the 1.exe file in iexpress by including 1.bat and 1.vbs and when I click the 1.exe file, it doesnt work, it doesn't copy the vbs file to startup, it says something about too many parameters.
I'm sorry if my post is too long or my question have been posted before, but I couldn't found any thread solves my issues, if there is, i'd be glad to be enlightened.
Thanks.
Never use "Batch to EXE" converter, they often do not work as expected. Simply use the batch script.
Just a note, this file actually only acts as a wrapper for your script, and the script itself actually gets executed in a temp folder created on execution (and deleted afterwards), so make sure you don't use any relative paths.
source
When running a batch file in IExpress, you need to call it like:
cmd /c 1.bat
If you don’t, variables like %username%, long file names, etc, will likely not work.
I suspect you are using short file names. Put in your bat dir then pause and you'll see it's 1~1.vbs or similar.

Scheduling automated scripts suite run from schedular

So I tried and tried but couldn't figure out this one for some reason.
how can I run a task from a desired directory instead of System32 directory where cmd.exe is.
so, when I schedule a task and try to run it ..
command prompt suppose to go to "c:\users\aaa\bbb\ccc" and then pass the argument.
Instead, It's starts at c:\Windows\System32 and fails.
Could anybody help me with this please?
I really appreciate it.
Thank you.
EDIT --
so, now I have a run.bat file with following content in it ...
C:\Users\aaa\bbb\ccc\dd (location to my testrunner.bat file)
testrunner.bat Scripts/all.suite website-address ie (command for the task I wanna perform)
net stop schedule (since window is poping up and going away way to fast, I added this to stop it (not working))
type run.bat
#echo off
cd C:\Users\aaa\bbb\ccc\dd
rem this will show all files in dir
rem is the file you're expecting listed?
dir
rem notice how you can make comments with a leading rem(ark)
#echo starting scripts\all.suite
rem you have to change this to have the full path using Windows X:\dir\dir conventions
c:\home\Scripts\all.suite website-address
#echo done running scripts\all.suite website-address
#echo shutting down
net stop schedule
So its still not clear exactly to me your goal. The reason I added the cd c:\... command is that will **C**hange **D**irectory to the path specified.
This is what you need so you can "run a task from a desired directory instead of System32".
Copy everything from the first #echo off to the last net stop and using notepad, paste it into a file, fix command names and paths website-urls, etc, then save that file to c:\temp\testrunner.bat.
Open a cmd.exe window and test that the script works. Just paste c:\temp\testrunner.bat on to cmd-line and hit enter. If that works, then made an entry in the scheduler to run c:\temp\testrunner.bat . I don't know the specifics of running a script for scheduler, so look for clues on the input screen. Is the an option to run 'now'?
If the .bat file doesn't work from the command-line, then you have to fix the file before you try running it in the scheduler. As your command Scripts/all.suite website-address is a little vague, you'll do better to post a new question asking for help to fix the .bat file and use a sample command that people will be able to use on their PCs at home.
IHTH.

Task Scheduled not running batch file

I have file which does somethings and it works fine if I run the file manually but it doesn't run when set up in task scheduler.
Batch file is in a folder on desktop on windows 7.
Any feedback will be helpful.
I've even tried this link solution didn't work.
Most likely in this case you need to make sure that the directory the script runs in ("Start in") is set correctly. Usually this is the same directory that contains your script. You can set this in the Scheduled Task's properties.
As a test, try moving the .bat file to a directory with basic permissions (maybe a shared directory for example).
I had the same problem as you. My .bat file was located in a folder with some restrictive permissions on it, so that only my user account could access it. Even though I had set up the task scheduler to use my credentials it still failed. Moving the .bat file to another directory sorted the issue.
I don't know if this will help, but in bashing my head against one problem after another for far too many hours, I finally got my own batch file to work properly as a scheduled task. Some of the things I learned in the process:
If you are the user who has created the scheduled task, you must also be a user who has logged into the system using a password.
Any reference to a file name, inside the batch file, needs to be the last part of fully qualified path, starting with drive letter.
If you do a comparison, like [%flag%] EQU [0], be aware that the "[" and "]" symbols are string literals that are included in the data that gets compared.
If part of your batch file sets a variable and includes a "FOR" loop that calls a subroutine in which you expect to change the variable, you need to make sure that the variable is originally initialized as early as possible in the batch file. That is, something like this:
IF ... (
SET %flag=0
FOR ... (CALL :subr)
IF [%flag%] EQU [1] ( main scheduled-task command goes here)
)
GOTO :eof
:subr
IF ... (SET %flag=1)
:eof
--worked from the command line, but not as a Scheduled Task. I had to move the initialization of %flag to be done before that very-first IF.

Resources