Batch Scripts Will not run on some Windows 7 systems - batch-file

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.

Related

How can I write a batch file to run a specific command?

I'm trying to make a batch file that will run the following command:
control name Microsoft.Personalization page pageWallpaper
How do I do this?
EDIT: I should be more specific. I know how to create a batch file but all I have written in the file is the code above, which just flashes a window and then does nothing.
The following should do what you need:
#echo off
control /name Microsoft.Personalization /page pageWallpaper
The syntax of control.exe requires the slashes before name and page.
Source: Add classic personalization menu in Windows 10 build 10074
Also, Command Line Commands for Control Panel Applets helped lead me to the answer.
I started by googling "windows control.exe command line options".
You know how to create batch files, but if you have any trouble putting the code above into a batch file and running it, and cannot figure out how, please let me know.
This works for me, running:
C:\bin> ver
Microsoft Windows [Version 10.0.14393]
Hope it works for you!
Regards,
Lud nom

How to accept user input while running a batch file in the background?

I am trying to make a script that executes very simple code to close all my applications (at least common ones, such as chrome.exe) when I enter a series of letters. This is to make it easier for shutdowns, as I hate individually closing the applications myself.
I know I can do this with a bunch of set /p commands or the choice command, but the problem is I can't get it to run in the background!
I know how to run the batch file invisibly with a VBS script, and I'll be placing the VBS script in the windows startup folder, but i am stumped as to how to accept input while cmd isn't the program selected.
Any help is greatly appreciated!

How to run batch file via task scheduler to route print and keep the DOS window open/command line available to add text

in advance, thank you for any insight you may be able to offer. i know that there is a very similar post to my scenario and i have tried all variations of the answer but cannot get it to work for me as per the initial or edited instructions. in order to circumvent the uac nags, i am running windows 7 (64 bit) and trying to run a batch file to simply 'route print cmd /k' via task scheduler and desktop shortcut but i want the DOS window to remain open and allow me to continue typing into it. when i execute the actual file, it runs as desired, however when it runs via task scheduler, the dos window closes immediately. to no avail, i have tried multiple things such as changing the 'program/script' field from C:\location\batchfilename.bat to just cmd and inputting the various arguments including cmd /k or /k or /k C:\location\batchfilename.bat to the task's 'add arguments' field and/or the batch script itself. although i do not want pause as it would close the window after pressing any key, i have also tried it in the script itself and the arguments field but it too does not keep the dos window open when running as scheduled task. nothing seems to work - your help is greatly appreciated!

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.

Remove the close option on a batch file with a command, is it possible?

I was just wondering if there is a code that can remove the "close" button on a batch file. (The minimize and expand buttons isn't important so it is ok if they will be disabled or will stay enabled) That is all. I can't seem to find any answer anywhere.
Thanks.
A batch file is nothing more that a script that another program must execute.
When you double-click a .bat file in Explorer, cmd.exe launches and "opens" the file, running the script. So your question is: can you remove the close button from cmd.exe? Good luck.
You don't want to be doing that. You should make your script NOT show a window to begin with.
If the window is shown, a user can always Ctrl + C to stop the script mid-stream.
There is a number of ways you can make the window hidden (also called "running a script silently"). See the following links:
Run a completely hidden batch file
Solved: HowTo run a batch file without it showing
Eric Helps
Or just google for "batch file silent" or "batch file hide console".
Just a side note: if you have seen this behavior before, chances are that it is not a batch file, but another programming language, and probably not using cmd.exe. C# can let you make a console program app which you can manipulate the title, but even still you cannot change the control buttons on the window. It is simply not within c# or a batch file's scope.

Resources