China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 22:11
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » About modifying the registry with batch commands! View 3,513 Replies 19
Original Poster Posted 2006-04-10 23:48 ·  中国 海南 海口 电信
初级用户
Credits 24
Posts 8
Joined 2006-04-10 23:46
20-year member
UID 53639
Status Offline
Today I encountered a problem when using batch commands to modify the registry and had some questions! Here is the code I wrote:

@echo off
echo Windows Registry Editor Version 5.00>>ok.reg
echo [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run]>>ok.reg
echo "key"="C:\\WINDOWS\\key.exe">>ok.reg
regedit /s ok.reg
del ok.reg

I don't know if there are any mistakes! This is the code in the REG file:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run]
"key"="C:\\WINDOWS\\key.exe"

I don't understand that I can import it when I write other registry entries. But there are a few that I can't import no matter how I edit them. I have modified them many times repeatedly. It should be fine. I really can't figure it out. Is the command used incorrectly? Please ask an expert for guidance. I'm almost going crazy~~~ If possible, add my QQ: 50594677 and talk to me in detail!
Floor 2 Posted 2006-04-11 09:02 ·  美国
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
The code should be error-free. Post the code that can't be imported, and everyone will help you take a look. Just forget about adding QQ.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 3 Posted 2006-04-11 11:32 ·  中国 海南 海口 电信
初级用户
Credits 24
Posts 8
Joined 2006-04-10 23:46
20-year member
UID 53639
Status Offline
It's just that the code above can't be imported.. Otherwise you can try it on your own machine.
Floor 4 Posted 2006-04-11 11:54 ·  中国 重庆 巴南区 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
Using the REG tool is not better
http://www.msfans.net/bbs/
Floor 5 Posted 2006-04-11 12:22 ·  中国 北京 鹏博士BGP
中级用户
★★
Credits 404
Posts 179
Joined 2006-03-30 14:44
20-year member
UID 53056
Status Offline
Hehe blank line

Are you blank?
Floor 6 Posted 2006-04-11 12:23 ·  中国 北京 鹏博士BGP
中级用户
★★
Credits 404
Posts 179
Joined 2006-03-30 14:44
20-year member
UID 53056
Status Offline
Also, the path is \, don't use \\. I also changed this.
Floor 7 Posted 2006-04-11 13:03 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
TO the person above:
In XP, blank lines are no longer needed, and the initial "Windows Registry Editor Version 5.00" can also be replaced with REGEDIT4. Also, the \ in the path should be escaped by adding an extra \ in front.

Re the original poster:
Personally, I think the code is correct, and based on your description:
"I don't understand that I can import when I was writing other registry entries. But there are a few that I just can't import no matter how I edit them. I've modified them many times repeatedly. It should be no problem."
Preliminarily, it is considered that due to the particularity of the run key, the registry monitoring of the antivirus software may have been enabled, causing it to be restored as soon as it is modified. So it is suggested to first close the antivirus software and other monitoring software and then make the modification. Also, there may be an issue with permissions, but as long as there are no special settings, the keys under HKEY_CURRENT_USER should be changeable. Personally, I think the original poster should check from these aspects.
Floor 8 Posted 2006-04-11 15:58 ·  中国 四川 绵阳 电信
高级用户
★★
Credits 587
Posts 282
Joined 2006-04-10 03:40
20-year member
UID 53599
Gender Male
Status Offline
It is suggested to use the reg command, so that the entry of variables can be supported.

For example:
The following are some batch commands of Pinyin JiaJia USB version
reg add "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v %SystemRoot%\system32\pyjj4.ime /t REG_SZ /d WINXPSP2 /f //Vista system correction
set /p usbjj= Please enter the current path and press Enter //USB JiaJia path
reg add "HKLM\SOFTWARE\jj4" /v "install path" /t REG_SZ /d "%usbjj%" /f //USB JiaJia path

%SystemRoot% will be replaced with the installation path of Windows
%usbjj% will be replaced with the characters entered by the keyboard

[ Last edited by xuantian on 2006-4-11 at 16:05 ]
Floor 9 Posted 2006-04-11 21:02 ·  中国 海南 海口 电信
初级用户
Credits 24
Posts 8
Joined 2006-04-10 23:46
20-year member
UID 53639
Status Offline
Reply to post 7:
The two methods you mentioned, I've tried both. Both ended in failure. Really depressed. I don't know what error occurred. Brother post 7, you can also test it yourself. Help find out what the problem is! Also, I really hope experts can give an answer..~~

Reply to post 8:
I once saw someone use the setlocal command and the reg add command to modify the registry. The following is the code I saw:
@echo off

setlocal

set regkey="HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\Licensing Core"

reg add %regkey% /v EnableConcurrentSessions /T REG_DWORD /D 1 /f

endlocal
Since I'm not very familiar with these two commands, please experts explain to me~~~ Thank you.
Floor 10 Posted 2006-04-11 21:14 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
The code has been tested successfully. The current user only has the permissions of the users group, and the antivirus software is not enabled (actually, it has never been installed). The code seems to be feasible. I don't know how you tested it. You can first manually add a one-click under the run key and try.
Floor 11 Posted 2006-04-11 21:41 ·  中国 海南 海口 电信
初级用户
Credits 24
Posts 8
Joined 2006-04-10 23:46
20-year member
UID 53639
Status Offline
I generated the batch file and just double-clicked to run it. My user has administrator privileges. It shouldn't be this problem. I don't know what the problem is. But I can use the reg add command to add it in. Also, when using the reg add command, sometimes there is an error of too many parameters. What is this error and how to solve it!!!
Floor 12 Posted 2006-04-11 23:25 ·  中国 四川 绵阳 电信
高级用户
★★
Credits 587
Posts 282
Joined 2006-04-10 03:40
20-year member
UID 53599
Gender Male
Status Offline
When using the reg command, enclose the added key and key value in quotes, so that there will be no errors when there are spaces in between. As for the commands, you can use the help, which are all in Chinese. For example: You can use reg add /? to get help when adding registry entries, etc....
Floor 13 Posted 2006-04-12 15:35 ·  中国 海南 海口 电信
初级用户
Credits 24
Posts 8
Joined 2006-04-10 23:46
20-year member
UID 53639
Status Offline
Thanks to the 12th floor. The problem has been solved..
Floor 14 Posted 2006-04-12 16:35 ·  中国 四川 绵阳 电信
高级用户
★★
Credits 587
Posts 282
Joined 2006-04-10 03:40
20-year member
UID 53599
Gender Male
Status Offline
Windows Registry Editor Version 5.00>>aaa.reg
Using the above command to create a registry temporary file and indirectly operate the registry through it is an incorrect method.

The reason is:

The temporary file saved through such an operation is in hypertext format, but the Windows Registry Editor Version 5.00 registry is (UniCode) double-byte text. Once NT's registry detects that the first line of the registry file is Windows Registry Editor Version 5.00, it will treat it as a binary NT registry file. Naturally, this registry text is also treated as UniCode text by NT's registry.

Generally speaking, if there are no spaces in the registry keys and values at this time, it should be able to be imported normally, but if there is a space in one of the keys or values, the registry's identification will go wrong, such as "Windows NT".


So the correct writing should be REGEDIT4>>aaa.reg

In this way, the created file will be regarded by NT's registry as a pure text format registry file (that is, the registry file format of the Win9X series), and there will be no more errors.

The writing of Windows Registry Editor Version 5.00>>aaa.reg confuses the concept of registry format! So it is not surprising that sometimes errors occur

That's all for now. I'll continue when I think of it :D
Floor 15 Posted 2006-04-12 21:00 ·  中国 广东 广州 白云区 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
Um. NT platform systems are all encoded in Unicode, and these systems are downwardly compatible with the ANSI encoding used by DOS/Win9x.

In the "Notepad" under NT systems, there are several text type options in the save type. In contrast, the "Notepad" of Win9x is really much less capable!
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Forum Jump: