I cannot figure out what I'm doing wrong.
I have a batch file starting a vbs script.
The script just makes some operations in some files, like moving them, create, delete...
It works fine.
Executing the bat it starts the vbs script and everything work.
The bat file just makes a cscript file.vbs
The problem is that I've scheduled this bat file .
When the times come, it gets executed but I get the error "path not found" in the vbs script.
It's not a schedule task problem because I've 11 task running batch files and they run smootly, and the script is executed (I've put controllers on it).
But the vbs script returns always the same path not found error.
Again,if I execute the script manually, it runs without problems.
The task is scheduled with the same account I use to manual execute the file, so it's not a permission issue. I just doubleclick the batch and it runs, click on execute on the task schedule manager and it fails.
The system is windows server 2008 r2 standard.
I already tried to reboot, deleting and making a new task....
Thanks to everyone
[UPDATE]
I paste here part of the code
FILE: D:\scripts\conf.ini
[script1]
fileA=D:\Rep\exportA.csv
fileB=D:\Rep\exportB.csv
fileC=D:\Rep\exportC.csv
dirHistory=D:\Rep\history
FILE: D:\scripts\merge.vbs
Dim iniObj
Set iniObj=New ClsINI
If iniObj.OpenINIFile("D:\scripts\conf.ini") = False Then
wLog("Impossible to read file ini")
Set iniObj = Nothing
Chiudi()
End If
Dim errIni,tmpVal
Dim fileA,fileB,fileC,dirHistory
errIni = iniObj.GetINIValue("script1", "fileA", fileA)
tmpVal = iniObj.GetINIValue("script1", "fileB", fileB)
errIni = errIni+tmpVal
tmpVal = iniObj.GetINIValue("script1", "fileC", fileC)
errIni = errIni+tmpVal
tmpVal = iniObj.GetINIValue("script1", "dirHistory", dirHistory)
errIni = errIni+tmpVal
If errIni > 0 Then
wLog("Error loading file ini")
wLog(errIni)
iniObj.CloseINIFile()
Set iniObj = Nothing
Chiudi()
End If
wLog("File ini Caricato")
Dim objFso,posizioneFile,Fase
Dim arrElement,resArray,actionArray,cedoleArray,varArray ,i
Dim conn,rs,strCon
Dim maxPos,maxTemp
Dim objExcel, objSheet,cella
Set objFso = CreateObject("Scripting.FileSystemObject")
if objFso.FileExists(fileA) then
objFso.DeleteFile(posizione)
wLog("File posizione moved")
else
wLog("File posizione not found")
end if
At this line a get the error of "Path not found"
Set posizioneFile = objFso.OpenTextFile(fileA, 8, True)
If not objFso.FileExists(fileB) then
SendEmail("nego")
Fase=false
Else
Set tFile = objFso.OpenTextFile(fileB, 1)
strFile=tFile.ReadAll
tFile.Close
posizioneFile.WriteLine strFile
objFso.MoveFile fileB, dirHistory&"\Negoz_"& CreaId(2) & ".csv"
End If
posizioneFile.Close
FILE: D:\scripts\merge.bat
echo Start Merge %date% %time% >> Started.log
cscript D:\scripts\merge.vbs
Sorry if I didn't put it before, but I was thinking it was a windows issue, because I thought the code was fine.
Thanks
This sounds like an issue with the working directory although it's a bit difficult to tell, since you chose not to show the content of the batch script. If you start the script manually (by double-clicking), the working directory is the directory in which the batch script (and probably the VBScript as well) resides. If you run the batch script as a scheduled task, the working directory is %SystemRoot%\system32 unless you expressly set a working directory in the task's properties.
Now, if your batch script looks like this:
cscript.exe your.vbs
it will look for your.vbs in the working directory and won't find it if the working directory is not the directory containing your.vbs. If my assumption that both scripts are in the same directory is correct you could either set the working directory in the properties of the scheduled task or (better) change the batch script to something like this:
cscript.exe "%~dp0your.vbs"
%0 is the path to the batch script itself as it was called. %~dp0 expands %0 to the absolute path of the parent directory (including a trailing backslash).
Related
We have an old Windows Server 2003 r2 which is doing nothing but using the task scheduler and a VBS file to check and rename some regularly re-occurring data files. It is setup to run every hour using my credentials. If I "run" it while I'm logged on the task runs and completes correctly. When no one is logged on the task runs but completes with an 0x1 code, ie it failed.
I have checked the event logs and see nothing which I can identify as an error or failure. We believe that it was running successfully until about 6-8 months ago (yes, it was one of those set it up and forget it things and we have not been regularly checking it).
=================Additional Information===============
I ran assoc .vbs and got this output: .vbs=VBSFile
I'm not sure how to determine the user environment variables?
For the task I have tried both the vbs file and also a bat file containing the reference to the vbs file. Both run when I'm logged and both fail to complete successfully when I'm not.
Here is the vbs script:
Dim fso, file, recentDate, recentFile, theFile, myfolder, mypath
set fso = CreateObject("Scripting.FileSystemObject")
set recentFile = Nothing
mypath = "D:\TheFTP\Main\Camera\lobby"
set myfolder = fso.GetFolder(mypath)
For Each file in myfolder.Files
If (recentFile is Nothing) Then
set recentFile = file
ElseIf (file.DateLastModified > recentFile.DateLastModified) Then
set recentFile = file
End If
Next
fso.CopyFile mypath& "\" & recentFile.name, "D:\TheFTP\main\camera\cam3.jpg"
set recentFile = nothing
set fso = nothing
Here is the last bat file where I have piped the output to a file:
C:\windows\system32\cscript.exe c:\CopyWebCamFile.vbs > c:\debug.txt
Debug.txt output when I'm not logged on shows an error, see below, which is not there when I run it and am logged on:
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
CScript Error: Initialization of the Windows Script Host failed. (The system cannot find the file specified.
=====================================================
More information, I added several Wscript.Echo statements to my script, before the first line, after the FOR loop and before the "copyFile" command. When I'm logged on I see all of the output in C:\debug.txt. When NOT logged on I see the same above error message, ie no Wscript.Echo output. This would see to indicate that it can not find my vbs file when I'm not logged on.
===========================
Still no happiness here. I moved and modified the .bat file to also output the contents of the script file:
type H:\Task_Stuff\CopyWebCamFileTest.vbs > H:\Task_Stuff\debug2.txt
C:\windows\system32\cscript.exe H:\Task_Stuff\CopyWebCamFileTest.vbs > H:\Task_Stuff\debug.txt
As before I get output to both .txt files when it runs while I'm logged on and nothing in debug2.txt and the usual messages in debug.txt when I'm not.
I'll fiddle with the antivirus settings, but I need to ask about that first. We are using Symantec SEP.
How can I check on the user environment variables?
====================
Maybe this will clarify my problem or suggest a solution??
Can you offer any ideas...RDK
First off we would like to thank LeeHarvey1 for his time and suggestions as we searched for the cause of this issue. In the end it was one of his suggestions that fixed the problem, but we still have no idea what caused it.
A reboot of the system cleared up all of the issues surrounding the task scheduler and running VB Scripts! We had considered his early suggestion, but discounted it as this server had only been up for a little over 3 months. Not excessive in our experience. However, when all else failed we elected to do that and "voila" it fixed the issue. We wish we knew what caused it but are now just happy we can move on to other things.
Thanks again LeeHarvey1....
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).
I want to run .qvw file through Jenkins.
To Run a qlikview file I am using batch file it is working fine ,I am using below command in batch file
"path\qv.exe" /r "path\myapplication.qvw"
This command is reloading my application ,I want to do it by Jenkins.
Has anyone done this before.
When I am trying to run above batch command through jenkins job it is continuously running.
"path\qv.exe" /r "path\myapplication.qvw"
Probably it remains open. You can try to add trigger to run macro which close app after reload:
VBScript Macro to save and close app is:
sub SaveQuit
ActiveDocument.Save
ActiveDocument.GetApplication.Quit
end sub
If you are using QlikView server/publisher better use reload from QMC there.
One option may be to have VBS for opening, reloading, saving and closing, like OpenSaveClose.vbs provided below.
Then you can use it in CMD files: wscript OpenSaveClose.vbs QvDoc.qvw
REM OpenSaveClose.vbs
Dim MyApp, MyDoc
Set MyApp = CreateObject("QlikTech.QlikView")
Set MyDoc = MyApp.OpenDocEx(Wscript.Arguments.Item(0),0,False)
MyDoc.GetApplication.WaitforIdle
REM MyDoc.Reload or whatever
MyDoc.SaveAs(Wscript.Arguments.Item(0))
MyDoc.GetApplication.WaitforIdle
MyDoc.CloseDoc
MyApp.Sleep 2000
MyApp.Quit
Set MyDoc = Nothing
Set MyApp = Nothing
I have a batch file that I want to run silently.
So, i was goolging around and come up with following code...
invMybatchfile.vbs
Dim curPath
curPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
Set WshShell = CreateObject("WScript.Shell")
cmds=WshShell.RUN(sCurPath & "\Mybatchfile.bat", 0, True)
This code DOES work on my desktop (Window 7 32bit), but for some reason, this script does not work on server computer(Windows Server 2008 R2). When I click invMybatchfile.vbs, dos windows pops up and closes right away and Mybatchfile.bat is not executed at all. (If i just run Mybathfile.bat on server computer, it works fine, so batch file is not the problem here.)
So my question is, does anyone know why I am having this problem?
OR
is there any other ways to launch batch file silently(not minimized, i know this way) with out using .vbs file or installing other software?
Thanks for your help
JB
The code of your example never will run in any machine because you are declaring the variable name as "curPath" and assign the vlaue to "CurPath" but you are trying to use it with the name "sCurPath" (And that variable doesn't exist on your code).
Also you don't need to set the current working dir because when you launch a file, the shell searchs for the file in the working dir, so this is all the code what you need, in only one line:
CreateObject("WScript.Shell").RUN "Mybatchfile.bat", 0, True
But if you are interested to store or to use the current working directory for any strange reason you have a method that returns the current dir:
.CurrentDirectory
Then you can use the method this way:
Set Shell = CreateObject("WScript.Shell")
Shell.RUN Shell.CurrentDirectory & "\Mybatchfile.bat", 0, True
...Or store the current dir in a var this way:
Set Shell = CreateObject("WScript.Shell")
CurDir = Shell.CurrentDirectory & "\"
Shell.RUN CurDir & "Mybatchfile.bat", 0, True
MSDN: http://msdn.microsoft.com/en-us/library/3cc5edzd%28v=vs.84%29.aspx
EDIT:
About running silent files, you can do it too using NirCMD commandline application.
NirCMD exec hide "Path to Batch File\Batch File.bat"
Official site: http://www.nirsoft.net/utils/nircmd2.html
I think you need to run it through cmd.exe:
WshShell.Run("%COMSPEC% /c " & CurPath & "\Mybatchfile.bat", 0, True)
Check similar questions here and here for more information.
Have you tried using RunAs?
cmds=WshShell.RUN("runas /noprofile /user:mymachine\administrator " _
& sCurPath & "\Mybatchfile.bat", 0, True)
Since it works on Windows 7 but not on Server 2008 R2, It sounds like a permissions issue to me.
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