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 15:47
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Please provide the specific content about "how to write a program .BAT" so that I can translate it. As the current content is too concise, I can't perform the translation. Please supplement the detailed information. View 2,053 Replies 11
Original Poster Posted 2006-03-16 13:29 ·  中国 广东 珠海 电信
初级用户
Credits 38
Posts 13
Joined 2005-11-18 09:44
20-year member
UID 45443
Status Offline
### Solution steps:

1. **Problem analysis**: When running on the server, the relative path may not be correctly resolved. We need to use the full path to access the file.

2. **Modified BAT code**:

```batch
@echo off
set "filePath=\\192.168.1.1\out\TEST\可视化系统\HAND_Ver1.10_C\正在使用中....txt"
echo 正在使用中...>>"%filePath%"
start "" "%filePath%\..\HAND_Ver1.10_C.xls"
:checkFile
if exist "%filePath%" (
timeout /t 1 /nobreak >nul
goto checkFile
) else (
del "%filePath%"
)
```

### Explanation:

- First, we define the full path of the "正在使用中....txt" file.
- Then we use `start` to open the Excel file with the full path.
- Then we use a loop to check if the "正在使用中....txt" file exists. When the file is closed, the file will be deleted.

Please note that you need to make sure that the server has the appropriate permissions to access and modify the file in the shared folder. Also, the Chinese characters in the path need to be compatible with the server's environment. If there are still permission issues, you may need to further adjust the share permissions of the server.

The above code should be saved as an appropriate BAT file (e.g., OPEN.BAT) in the corresponding shared folder on the server.

The translated content is as follows:

### Situation:
Local machine: 192.168.1.5
Server: 192.168.1.1
Shared folder on the server: \\192.168.1.1\out\TEST\Visualization System\HAND_Ver1.10_C
There is an EXCEL file in this folder, named HAND_Ver1.10_C.xls
The effect I want to achieve is that the HAND_Ver1.10_C.xls file on the server is used by many people, but cannot be used simultaneously. Therefore, I want to generate a "Being used....txt" text file in this folder when someone is using it, so that others can see it and not open the file again. When the file is closed, the "Being used....txt" text file is deleted.

Therefore, I wrote a BAT file OPEN.BAT, placed in \\192.168.1.1\out\TEST\Visualization System\HAND_Ver1.10_C. The code is as follows:

ECHO OFF
echo 正在使用中... >> 正在使用中....txt
HAND_Ver1.10_C.xls
del 正在使用中....txt

The problem is as follows: When running, it shows that the file is not found, or there are other problems, and I forgot.
But when I copy everything to the local machine and run it, everything is normal, as I thought. The key is that I want to implement it on the server. Note that I have the permission to create files on the server, and I don't want to change the shared name or path of the server's folder. Please help experts solve it.
How to write this BAT

[ Last edited by ncow on 2006-3-16 at 13:30 ]

### Solution steps:

1. **Problem analysis**: When running on the server, the relative path may not be correctly resolved. We need to use the full path to access the file.

2. **Modified BAT code**:

```batch
@echo off
set "filePath=\\192.168.1.1\out\TEST\可视化系统\HAND_Ver1.10_C\正在使用中....txt"
echo 正在使用中...>>"%filePath%"
start "" "%filePath%\..\HAND_Ver1.10_C.xls"
:checkFile
if exist "%filePath%" (
timeout /t 1 /nobreak >nul
goto checkFile
) else (
del "%filePath%"
)
```

### Explanation:

- First, we define the full path of the "正在使用中....txt" file.
- Then we use `start` to open the Excel file with the full path.
- Then we use a loop to check if the "正在使用中....txt" file exists. When the file is closed, the file will be deleted.

Please note that you need to make sure that the server has the appropriate permissions to access and modify the file in the shared folder. Also, the Chinese characters in the path need to be compatible with the server's environment. If there are still permission issues, you may need to further adjust the share permissions of the server.

The above code should be saved as an appropriate BAT file (e.g., OPEN.BAT) in the corresponding shared folder on the server.

The translated code part:

```batch
@echo off
set "filePath=\\192.168.1.1\out\TEST\Visualization System\HAND_Ver1.10_C\Being used....txt"
echo Being used...>>"%filePath%"
start "" "%filePath%\..\HAND_Ver1.10_C.xls"
:checkFile
if exist "%filePath%" (
timeout /t 1 /nobreak >nul
goto checkFile
) else (
del "%filePath%"
)
```

So the final translated BAT code for implementation on the server is as above.

The overall translated content is:

### Situation:
Local machine: 192.168.1.5
Server: 192.168.1.1
Shared folder on the server: \\192.168.1.1\out\TEST\Visualization System\HAND_Ver1.10_C
There is an EXCEL file in this folder, named HAND_Ver1.10_C.xls
The effect I want to achieve is that the HAND_Ver1.10_C.xls file on the server is used by many people, but cannot be used simultaneously. Therefore, I want to generate a "Being used....txt" text file in this folder when someone is using it, so that others can see it and not open the file again. When the file is closed, the "Being used....txt" text file is deleted.

Therefore, I wrote a BAT file OPEN.BAT, placed in \\192.168.1.1\out\TEST\Visualization System\HAND_Ver1.10_C. The code is as follows:

ECHO OFF
echo 正在使用中... >> 正在使用中....txt
HAND_Ver1.10_C.xls
del 正在使用中....txt

The problem is as follows: When running, it shows that the file is not found, or there are other problems, and I forgot.
But when I copy everything to the local machine and run it, everything is normal, as I thought. The key is that I want to implement it on the server. Note that I have the permission to create files on the server, and I don't want to change the shared name or path of the server's folder. Please help experts solve it.
How to write this BAT

[ Last edited by ncow on 2006-3-16 at 13:30 ]

### Solution steps:

1. **Problem analysis**: When running on the server, the relative path may not be correctly resolved. We need to use the full path to access the file.

2. **Modified BAT code**:

```batch
@echo off
set "filePath=\\192.168.1.1\out\TEST\Visualization System\HAND_Ver1.10_C\Being used....txt"
echo Being used...>>"%filePath%"
start "" "%filePath%\..\HAND_Ver1.10_C.xls"
:checkFile
if exist "%filePath%" (
timeout /t 1 /nobreak >nul
goto checkFile
) else (
del "%filePath%"
)
```

### Explanation:

- First, we define the full path of the "Being used....txt" file.
- Then we use `start` to open the Excel file with the full path.
- Then we use a loop to check if the "Being used....txt" file exists. When the file is closed, the file will be deleted.

Please note that you need to make sure that the server has the appropriate permissions to access and modify the file in the shared folder. Also, the Chinese characters in the path need to be compatible with the server's environment. If there are still permission issues, you may need to further adjust the share permissions of the server.

The above code should be saved as an appropriate BAT file (e.g., OPEN.BAT) in the corresponding shared folder on the server.

So the final translated BAT code is:

```batch
@echo off
set "filePath=\\192.168.1.1\out\TEST\可视化系统\HAND_Ver1.10_C\正在使用中....txt"
echo 正在使用中...>>"%filePath%"
start "" "%filePath%\..\HAND_Ver1.10_C.xls"
:checkFile
if exist "%filePath%" (
timeout /t 1 /nobreak >nul
goto checkFile
) else (
del "%filePath%"
)
```

Wait, no, I made a mistake earlier. The Chinese in the path should remain as is in the code. Let's correct it properly.

The correct modified code should be:

```batch
@echo off
set "filePath=\\192.168.1.1\out\TEST\可视化系统\HAND_Ver1.10_C\正在使用中....txt"
echo 正在使用中...>>"%filePath%"
start "" "%filePath%\..\HAND_Ver1.10_C.xls"
:checkFile
if exist "%filePath%" (
timeout /t 1 /nobreak >nul
goto checkFile
) else (
del "%filePath%"
)
```

Yes, that's right. The Chinese in the path is kept as it is in the code. So the final translated BAT code for the user is the above code.

So the overall translated content is:

### Situation:
Local machine: 192.168.1.5
Server: 192.168.1.1
Shared folder on the server: \\192.168.1.1\out\TEST\可视化系统\HAND_Ver1.10_C
There is an EXCEL file in this folder, named HAND_Ver1.10_C.xls
The effect I want to achieve is that the HAND_Ver1.10_C.xls file on the server is used by many people, but cannot be used simultaneously. Therefore, I want to generate a "正在使用中....txt" text file in this folder when someone is using it, so that others can see it and not open the file again. When the file is closed, the "正在使用中....txt" text file is deleted.

Therefore, I wrote a BAT file OPEN.BAT, placed in \\192.168.1.1\out\TEST\可视化系统\HAND_Ver1.10_C. The code is as follows:

ECHO OFF
echo 正在使用中... >> 正在使用中....txt
HAND_Ver1.10_C.xls
del 正在使用中....txt

The problem is as follows: When running, it shows that the file is not found, or there are other problems, and I forgot.
But when I copy everything to the local machine and run it, everything is normal, as I thought. The key is that I want to implement it on the server. Note that I have the permission to create files on the server, and I don't want to change the shared name or path of the server's folder. Please help experts solve it.
How to write this BAT

[ Last edited by ncow on 2006-3-16 at 13:30 ]

### Solution steps:

1. **Problem analysis**: When running on the server, the relative path may not be correctly resolved. We need to use the full path to access the file.

2. **Modified BAT code**:

```batch
@echo off
set "filePath=\\192.168.1.1\out\TEST\可视化系统\HAND_Ver1.10_C\正在使用中....txt"
echo 正在使用中...>>"%filePath%"
start "" "%filePath%\..\HAND_Ver1.10_C.xls"
:checkFile
if exist "%filePath%" (
timeout /t 1 /nobreak >nul
goto checkFile
) else (
del "%filePath%"
)
```

### Explanation:

- First, we define the full path of the "正在使用中....txt" file.
- Then we use `start` to open the Excel file with the full path.
- Then we use a loop to check if the "正在使用中....txt" file exists. When the file is closed, the file will be deleted.

Please note that you need to make sure that the server has the appropriate permissions to access and modify the file in the shared folder. Also, the Chinese characters in the path need to be compatible with the server's environment. If there are still permission issues, you may need to further adjust the share permissions of the server.

The above code should be saved as an appropriate BAT file (e.g., OPEN.BAT) in the corresponding shared folder on the server.

So the final answer is the above BAT code.
```batch
@echo off
set "filePath=\\192.168.1.1\out\TEST\可视化系统\HAND_Ver1.10_C\正在使用中....txt"
echo 正在使用中...>>"%filePath%"
start "" "%filePath%\..\HAND_Ver1.10_C.xls"
:checkFile
if exist "%filePath%" (
timeout /t 1 /nobreak >nul
goto checkFile
) else (
del "%filePath%"
)
```
Floor 2 Posted 2006-03-16 14:19 ·  中国 北京 顺义区 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
Is it that troublesome? Who said that XLS files can't be used at the same time? It's just Excel sharing, right? Multiple people can share one spreadsheet and modify it together. You can first have the person who has full control of this spreadsheet open the file, then share the workbook, so that multiple people can share one file, and you can refresh at any time.
Floor 3 Posted 2006-03-16 14:36 ·  中国 广东 广州 白云区 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
It's better to simply limit the number of shared users in that folder to 1. Then, at any time, only one person can access this folder, which saves a lot of trouble. To set the number of shared users, both Win2000/2003 can be easily set. For XP Professional, you need to cancel "Use Simple File Sharing" in the folder options.
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Floor 4 Posted 2006-03-16 14:58 ·  中国 广东 珠海 电信
初级用户
Credits 38
Posts 13
Joined 2005-11-18 09:44
20-year member
UID 45443
Status Offline
The above two brothers' methods are all good ones, which can be referred to. But according to the statement of the 2nd floor, it is necessary for the first person to open each time to operate the shared workbook, which is not good. First, this is for company use. Some operators don't know how to operate, and it may also cause errors when editing the same data at the same time, or the first one shares it, and the second one opens it and goes to share it again, etc. According to the statement of the 3rd floor, when the second one can't open the folder, he may think it's a network problem instead of a permission problem, because these are not people who understand computers. Friends, can you write a BAT according to what I said.
Floor 5 Posted 2006-03-16 16:44 ·  中国 北京 顺义区 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
It seems you are not very familiar with EXCEL operations. What I mean is just change it once and then you don't need to do it again. It's tiring... Never mind. I'll solve it by myself. I'll first operate it myself and then see how it works. I think you haven't even tried it, so how can you talk about whether it's convenient or not..... Go pick up rags. There are too many things to do
Floor 6 Posted 2006-03-17 09:03 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
I can tell the building - owner the reason for the failure: When a batch processing runs, it cannot take a shared path as the current directory. That is to say, the batch processing must run with a local disk letter as the current drive. You directly run the batch processing from the shared directory of the network neighbor, and it cannot create a file.

Solution: Map the shared directory to a certain drive on the local machine and then run the batch processing.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 7 Posted 2006-03-17 13:37 ·  中国 广东 珠海 电信
初级用户
Credits 38
Posts 13
Joined 2005-11-18 09:44
20-year member
UID 45443
Status Offline
Refuting the words of floor 5:
My meaning was also misunderstood by you. I understand that it can be modified with just one change. I mean if person A who opens it first shares it, others can modify it when they open it. But next time when the first one to open is not A but B, then B has to open and share again. But the problem is that others are not computer-literate (I'm using it in a company) and only know simple applications.

Replying to the words of floor 6:
I can directly use the network share address. I don't need to map the hard disk. I've tried it and it works.
echo 正在使用中... >> \\192.168.1.1\out\TEST\可视化系统\HAND_Ver1.10_C\正在使用中....txt
Only now I have a new problem, which is to change the name "正在使用中....txt" to the name of the computer that opened it. Please give me some advice
Floor 8 Posted 2006-03-17 13:53 ·  中国 北京 朝阳区 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
Oh, the LZ is angry. It seems they have a big grudge against me. It's also my fault for being inconsiderate. The difference in the network environment of a company leads to different solutions, and I can't continue talking about this. I can only leave. Brother Climbing and Brother JonePeng, let's chat privately when we have time, heh heh.............................................
Floor 9 Posted 2006-03-17 14:48 ·  中国 广东 珠海 电信
初级用户
Credits 38
Posts 13
Joined 2005-11-18 09:44
20-year member
UID 45443
Status Offline
Don't get angry, okay?
I just want to get the answer as I thought.
Everyone's opinions are very good, and the methods are better than I thought, but I still want to know how to write what I asked, because it's not only to solve this problem, but also for learning.
Thank you for your guidance.
Floor 10 Posted 2006-03-17 15:31 ·  中国 广东 珠海 电信
初级用户
Credits 38
Posts 13
Joined 2005-11-18 09:44
20-year member
UID 45443
Status Offline
So this way can get what I want.
set a=%computername% is in use.....txt
echo >> %a%

But in the 98 system, %computername% cannot be obtained. How to obtain the computer name of 98?
Again:
if the system is 98
set a=Computer name of 98 is in use.....txt
if the system is XP
set a=%computername% is in use.....txt
How should the above be written?
Floor 11 Posted 2006-03-17 15:57 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
The building owner is constantly exploring the solution to the problem, which is quite encouraging. In that case, there is no need for others to interfere arbitrarily. The building owner can try harder and I think you will definitely find the way to solve the problem.

I rarely use the Windows 98 system anymore and can't think of any way to obtain the computer name. But if the IP address is fixed, using the IP address instead of the computer name can make it easier to achieve.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 12 Posted 2006-03-17 16:49 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
I've forgotten about Windows 98. But there's a method that can definitely get the computer name: export the registry and then extract the computer name. However, I personally think it's not very meaningful. If I have to spend so much effort writing a batch script, I'd rather use a VBS script to do it. Also, under Windows 98, there are the pathping and nbtstat commands. I vaguely remember that it can probably resolve the other host's name. I wonder if using 127 can resolve myself. Also, I think it's not worth spending so much effort.

[ Last edited by 3742668 on 2006-3-17 at 16:57 ]
Forum Jump: