我的bat文件无法正确运行,为什么? [英] My bat file can't run correctly, why?

查看:193
本文介绍了我的bat文件无法正确运行,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建一个新文件的test.bat,内容如下:

Create a new file test.bat, the content is as follows:

回声AA;

和在DOS命令行中执行它,

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

当我双击bat文件,它总是突然消失了,即使我在test.bat的文件中添加一个暂停的条款一致。这两个系统是Windows XP操作系统。可以某人告诉我问题出在哪里,好吗?

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.

现在,当我重新启动该系统使用另一个管理员帐户divscover。一切都很好。

Now, I divscover when reboot to the system using another Administrator account. All is fine.

那么,问题是否来自Windows XP的注册表记录?

So, whether the problem comes from the registry record of the Windows XP?

推荐答案

请参阅我的回答遍历目录中的文件prepends额外的字符到文件名,我已经解释检查什么,如果如预期的批处理文件不工作。

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.

环境变量的 COMSPEC PATHEXT PATH 应该是您第一次验证。并检查注册表项,在参考答案解释命令处理器的值。另外的自动运行命令处理器的价值是非常关键的。

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.

此外,启动注册表编辑器并检查注册表键的标准值 HKEY_CLASSES_ROOT \\蝙蝠显示在右侧。它应该是 batfile 。然后去 HKEY_CLASSES_ROOT \\ batfile ,打开它并导航到子项打开 - 命令。标准值为%1%* 。这可能是你的Windows注册表是部分损坏,这使得它无法通过双击运行的批处理文件。

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

通过的运行在Windows的开始菜单项。然后在命令提示符窗口中运行批处理文件。

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

和确认运行的Windows在Windows下次启动磁盘检查工具。然后重新启动Windows,让这个工具检查文件系统产生1个或多个损坏的文件错误。如果文件系统是真正检测到错误,运行Windows后完成从命令提示符窗口中启动

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

确认在Windows下次启动再次运行此工具,但如果这是有可能的话这个时候对您的硬盘和修理行业各界的读/写测试。它可能需要几个小时,这取决于驱动器C的大小:做完这个任务

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.

添加在2014年9月28日:

您已经检查了防病毒应用程序的配置?

Do you have checked already the configuration of the anti-virus application?

这可能是因为它会阻止执行所有的* .bat文件的。

It could be that it blocks the execution of all *.bat files.

您已经尝试使用Windows系统还原在其上批文件执行失败的帐户,并返回到恢复上您确信该批处理文件执行工作的日期呢?

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?

如果 NTUSER.DAT ntuser.dat.log (=当前用户的注册表)是部分损坏或事情是在Windows注册表中错误地配置了该用户帐户,这将是找回该帐户的工作环境,最简单的方法。

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.

由于批处理文件执行不使用一个帐户只能工作,原因必须在此帐户的注册表损坏或错误的设定键或值。

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.

我建议下载并运行免费工具工艺Sysinternals公司监控(微软)首先使用该帐户上如预期批处理文件执行不起作用。

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.

首先显示在该工具的启动是配置过滤器的对话框。从第一个列表中的进程名称:选择,让我们的第二个列表上选择,如果输入 CMD.EXE 在编辑栏,并让包含在上列表中选择。按钮单击旁边的包含,然后在确定

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.

现在在工具栏上的最后3个符号进程监视器点击程序主窗口关闭同时导致只监视注册表和文件系统访问这些功能。清除当前列表中点击第五符号工具栏或pressing按Ctrl + X。

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.

在Windows资源管理器示例批处理文件现在双击。然后切换到batck过程监控,向上滚动到开头和行的批处理文件执行的会发生什么看行。也许你可以看到,你认为是不正确的东西。

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.

列的结果应仅显示的成功的和的找不到名称的和很少的 NO多个条目的的注册表项在日志中。 无效的列的结果是不好的。日志可以保存为用Ctrl + S CSV文件,或通过单击磁盘符号工具栏。

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.

退出进程监视器,从该帐户注销,其他帐户登录,也从这里开始进程监视器,配置相同的过滤器,执行相同的批处理文件,并可以节约此日志到CSV文件中。比较2 CSV文件和寻找差异(除时间和行号)。

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

另一种方法,找出哪些是2帐户导致批处理文件执行不工作在比较这2帐户的注册表配置单元之间是不同的。在这两个帐户启动注册表编辑器并出口整个密钥 HKEY_CURRENT_USER 为* .reg文件。比较两个注册表出口与文本比较工具。新的管理员帐户具有绝对更少的键和值。有趣的是只有类似,但不完全相同的行这些区块。

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.

最有意思的关键是:

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

从该列表中某些键可以完全丢失。因为在这种情况下HKEY_LOCAL_MACHINE相同的密钥被考虑到了窗户,会好起来的。但是,当一个键在其批处理文件执行失败账号丢失,应该在其他帐户也下落不明,或者什么是错在这里。

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.

完全意想不到的事情发生,如果一个注册表项是指数present,但不会在注册表中存在了。比如我曾经固定的问题,其中 HKLM \\ Software \\ Classes下\\的mailto 在索引列表,但没有在注册表中存在了。当用户一个mailto链接点击时,Windows开始在一个循环在Outlook中创建新邮件Windows之前用尽资源和用户,Windows重新启动。

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.

这篇关于我的bat文件无法正确运行,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆