Why isn't my Batch file opening when windows start? - batch-file

The batch I created is intended to start a Python file, and for reasons of dependency with Python and Geckodriver, I have no way to work with the Batch file directly in the Startup folder, for this reason I need to work with registries.
I entered the following key in the HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run path:
But for some reason the Batch file associated with the key does not open when Windows starts. I already checked everything, the Batch file works perfectly when executed manually and path in the key value is totally correct. It is not working on RunOnce either. I also checked the Startup tab in the Task Manager and it is enabled. Does anyone know what could be happening? why is the file not working?

Related

MS Access - Linked Text File Error

I have an access database that points to a linked text file saved in the network. I’ve setup the following:
A batch file that opens the DB and runs a macro.
A scheduled Windows task that runs daily to kick-start the batch file. The process used to run with no issue, but lately I started getting this error message ‘M:\’ is not a valid path. Make sure the path name is spelled correctly and you are connected to the server on which the file resides.
Please note the following:
The windows scheduler runs with no issue.
The database opens
The Macro runs
The process throws the above error message only at the step related to the linked text file.
The strange thing is that when I run the batch file manually, the process runs like a clock and gets completed successfully (txt file path gets recognized).
Any idea about how to deal with the above issue? Please
Your assistance is appreciated
Thanks,
Ben
It is likely that your M: drive is being mapped as a result of a logon or start-up script. When taskschedular wakes the machine your script runs before this drive mapping takes place. Another thing to watch for is the user that runs taskscheduler might not have the same drive mapping as you. Always run the task manually and investigate any failures. Running the script outside the environment taskscheduler supplies is only mildly diagnostic.
Thank you for your response.
Please note that I have a proceeding VBA step that renames the same file in the same location and it occurs successfully.
Furthermore, when I engage the batch file manually, the location of linked txt file gets recognized.
Also, after getting the error message, I close the DB, open it again, click on the linked txt file, and it opens successfully.
It is very strange.

vbscript called from batch file from task scheduler failing to open excel workbook

I have a vbscript that I'm calling from a batch file. Inside this script it opens an excel file on a sharepoint site. When I run this batch file by dbl clicking it everything works. When I run from the task scheduler the log file shows it's failing to open the excel file on the line:
XL.Workbooks.Open(wrkbook)
Note that it works fine when dbl clicked. I'm guessing it's some kind of permissions or something but not sure who/what/when/where/why. Any ideas?
When I pipe the vbscript error I get:
Microsoft Excel cannot access the file 'file path here' for one of the following reason:
The file name or path does not exist (but it does)
The file is being used by another program (it's not as I can open the file)
The workbook you are trying to save has the same name as a currently open workbook (not sure what this is really saying but doesn't seem to apply either)
OMG, you have GOT to be kidding me. The answer is a handful of posts below in this thread and you'll never believe it.
https://social.msdn.microsoft.com/Forums/office/en-US/ac2549f5-fc1e-494d-9015-70cb31d3aeb2/opening-excel-workbook-fails-when-run-from-scheduled-task-on-windows-server-2008-rw?forum=exceldev
Literally, and I'm not joking here, all I had to do was create a a folder named 'desktop' in C:\windows\SysWOW64\config\systemprofile. So the final path is 'C:\windows\SysWOW64\config\systemprofile\desktop'.
Can you believe that? That's insane.

My bat file can't run correctly, why?

Create a new file test.bat, the content is as follows:
echo aa;
and execute it in the dos command line,
test.bat
there are no output in the window. But when I tested it in another computer, it outputs
aa
When I double click the bat file, it always disappeared suddenly even I add a "pause" clause line in the test.bat file. Both the systems are Window XP. Can sb tell me where is the problem, please?
I have checked all the things Mofi suggested, but the problem remains.
Now, I divscover when reboot to the system using another Administrator account. All is fine.
So, whether the problem comes from the registry record of the Windows XP?
See my answer on Iterating over files in directory prepends extra character to filename where I have already explained what to check if batch files are not working as expected.
The environment variables ComSpec, PATHEXT and PATH should be verified by you first. And check also the values of registry key Command Processor as explained in referenced answer. Also Autorun value of key Command Processor is very critical.
Further, start Regedit and check standard value of registry key HKEY_CLASSES_ROOT\.bat displayed on right side. It should be batfile. Then go to HKEY_CLASSES_ROOT\batfile, open it and navigate to subkey open - command. The standard value is "%1" %*. It could be that your Windows registry is partly corrupt which makes it not possible to run a batch file by double click.
A check for a problem with registry would be opening a command prompt window by running
C:\Windows\System32\cmd.exe
via Run entry in start menu of Windows. Then run your batch file from within the command prompt window.
You should also run from a command prompt window
C:\Windows\System32\chkdsk.exe C: /F
and confirm running the check disk tool of Windows on next boot of Windows. Then restart Windows to let this tool check the file system for errors resulting in 1 or more corrupt files. If an error was really detected in file system, run after Windows finished starting from a command prompt window
C:\Windows\System32\chkdsk.exe C: /F /R
Confirm running this tool once again on next boot of Windows, but this time with read/write tests on all sectors of your hard disk and repairing sectors if that is possible at all. It can take several hours depending on size of drive C: to finish this task.
Added on 2014-09-28:
Anti-virus application
Do you have checked already the configuration of the anti-virus application?
It could be that it blocks the execution of all *.bat files.
Windows System Restore
Do you have already tried to use Windows System Restore for the account on which batch file execution fails and go back to a restore point of a date on which you are sure that batch file execution worked?
If ntuser.dat or ntuser.dat.log (= registry of current user) is partly corrupt or something is misconfigured in Windows registry for this user account, this would be the easiest method to get back a working environment for the account.
Process Monitor Analysis
As execution of batch files does not work only with one account, the reason must be a corrupt or wrong set key or value in registry of this account.
I suggest to download and run free tool Process Monitor from Sysinternals (Microsoft) using first the account on which batch file execution does not work as expected.
The first displayed on start of this tool is a dialog to configure a filter. Select from first list Process Name, let is selected on second list, enter cmd.exe in edit field, and let Include selected in last list. Click next on button Include and then on OK.
Now in main application window of Process Monitor click on last 3 symbols in toolbar to toggle off those features resulting in monitoring only registry and file system accesses. Clear current list by clicking on fifth symbol in toolbar or by pressing Ctrl+X.
Now double click on your sample batch file in Windows Explorer. Then switch batck to Process Monitor, scroll up to beginning and look line by line what happens on executing of a batch file. Perhaps you can see something which you think is not correct.
The column Result should show only SUCCESS and NAME NOT FOUND and rarely NO MORE ENTRIES for registry entries in log. INVALID in column Result is not good. The log can be saved as CSV file with Ctrl+S or by clicking on disk symbol in toolbar.
Exit Process Monitor, logout from this account, logon on other account, start here also Process Monitor, configure the same filter, execute same batch file and save also this log into a CSV file. Compare the 2 CSV files and look for differences (other than time and line number).
Windows Registry Compare
Another method to find out what is different between the 2 accounts resulting in batch file execution not working is comparing the registry hives of those 2 accounts. In both accounts start Regedit and export entire key HKEY_CURRENT_USER to a *.reg file. Compare the two registry exports with a text comparison tool. The new administrator account has definitely less keys and values. Interesting are those blocks with just similar, but not identical lines.
Most interesting are the keys:
HKEY_CURRENT_USER\Console
HKEY_CURRENT_USER\Environment
HKEY_CURRENT_USER\Software\Classes\.bat
HKEY_CURRENT_USER\Software\Classes\batfile
HKEY_CURRENT_USER\Software\Microsoft\Command Processor
Some keys from this list can be missing completely. That would be okay as in this case the same key under HKEY_LOCAL_MACHINE is taken into account by Windows. But when a key is missing in account on which batch file execution fails, it should be also missing in the other account, or something is wrong here.
What could be a big and hard to find problem is a registry key which is displayed on viewing the registry tree with Regedit, but when clicking on the key it cannot be read.
I have seen such partly corrupt registry keys already several times and it is very hard to fix such a registry error. This happens for example if an application removes a registry key without removing it also from index table of the registry.
Totally unexpected things happen if a registry key is present in index, but does not exist anymore in registry. For example I fixed once an issue where HKLM\Software\Classes\mailto was in index list, but did not exist anymore in registry. When the user clicked on a mailto link, Windows started creating new emails in Outlook in a loop until Windows run out of resources and user restarted Windows.
Please add # before echo, like this:
#echo aa
#pause
Its working in my Windows7 machine.

Batch Scripts Will not run on some Windows 7 systems

Any ideas why bat files don't run in some cases?
I have written an interactive batch script (also run as an exe) works on THOUSANDS of systems, HOWEVER, a small subset of systems will NOT launch the script. They open a black box window and then close the script without giving the user the bat menu. I tried the bat file association registry reset which ensures that .bat file association is correct but that didn't help.
What I have tried: bat registry fix (.reg file)
(which didn't seem to help, the script starts but doesn't run)
(I also tested a VERY basic script that printed Hello world which also didn't work)
Thanks everyone for your help. What I found out was:
(1) Reset the command prompt:
http://social.technet.microsoft.com/Forums/windows/en-US/0a74090e-53ce-4642-8dad-0523bfd6c8a2/cant-run-bat-batch-files?forum=w7itproui
(which did not work for me)
(2) In a command prompt I had the users type 'set path' which showed that they were missing /windows/system32/ for one user. So far I had one user put it in and it fixed it. One other user had %systemroot%/system32 which I will have them try adding the path the other way to see if it fixes it. Next I will see if I can just add that to the script.

Access context menu items from windows batch file

Okay I currently need to check about 200 files, so of course i want to automate as much as i can. the software I need to use to inspect them does not seem to have a command line interface, so I am currently stuck right-clicking them and clicking edit.
Is there any way to access that edit command from command line, so I can automate this process, or am I stuck opening 200 files like this.
Okay I figured it out, and here's how I did it!
Go to regedit, and find the file extension im trying to deal with in HKEY_CLASSES_ROOT
then inside the folder for the file extension i found the name of the folder of the program this filetype uses, and that folder was also located on HKEY_CLASSES_ROOT.
Then inside that folder is a "shell" folder wherein all of the contextual options are located.
That shell folder had an element called "edit" and that element contained a shell command that was used behind the scenes to launch the editor with the specific file.
Now I can write my batch script with this command!

Resources