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-02 02:27
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Ask about BAT file association, problem! (Thanks to electronixtar for solving it) View 1,550 Replies 8
Original Poster Posted 2006-09-16 01:42 ·  中国 黑龙江 齐齐哈尔 中移铁通
初级用户
Credits 30
Posts 11
Joined 2006-06-11 17:19
20-year member
UID 56883
Status Offline
I want to use BAT to do file association, but there is a small problem, ask experts to help solve!

For example, I want to associate the .jsb file to be opened with Notepad. The following is the command, which can be realized under the DOS command prompt
Assoc .jsb=jsb
Ftype jsb=C:\WINDOWS\system32\notepad.exe %1

But I want to use BAT to realize batch processing to associate files. The following is the BAT script
@ECHO off
cls
color B
ECHO.
ECHO JSB file association
ECHO.
pause

Assoc .JSB=JSB
Ftype JSB=C:\WINDOWS\system32\notepad.exe %1

ECHO.
ECHO JSB file association succeeded
ECHO.
pause
exit

Problem, I use the same command, which can be realized under the command prompt, but cannot be realized in BAT. Why? Under the command prompt, I can define the variable of 1%, but in BAT, I cannot realize the variable of 1%, and after opening, it is empty! Please tell me how to solve it by experts. How should I write BAT? I think I have a wrong writing format.

[ Last edited by 2691614 on 2006-9-16 at 05:44 ]
Floor 2 Posted 2006-09-16 03:08 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 3 Posted 2006-09-16 03:47 ·  中国 黑龙江 齐齐哈尔 中移铁通
初级用户
Credits 30
Posts 11
Joined 2006-06-11 17:19
20-year member
UID 56883
Status Offline
Thank you. I wrote the BAT like this:

@ECHO off
cls
color B
ECHO.
ECHO JSB file association
ECHO.
pause


Assoc .JSB=JSB
Ftype JSB=C:\WINDOWS\system32\notepad.exe ^%1

ECHO.
ECHO JSB file association succeeded
ECHO.
pause
exit

But still can't control the 1% variable. In the command prompt, I can define C:\WINDOWS\system32\notepad.exe %1. In the BAT, it's just C:\WINDOWS\system32\notepad.exe without 1%, so it can't read!

Please help me again, thank you!
Floor 4 Posted 2006-09-16 04:02 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 5 Posted 2006-09-16 04:05 ·  中国 黑龙江 齐齐哈尔 中移铁通
初级用户
Credits 30
Posts 11
Joined 2006-06-11 17:19
20-year member
UID 56883
Status Offline
That 1% is for controlling the open function. If there is no 1%, it just opens an empty Notepad. With 1%, it can load the content in the file.

In the command prompt, you can add the %1 variable, but in BAT, you can't add the %1 variable.

In BAT, the definition of C:\WINDOWS\system32\notepad.exe %1 is that the %1 after C:\WINDOWS\system32\notepad.exe cannot be loaded.
Attachments
Image00000.jpg
Floor 6 Posted 2006-09-16 04:06 ·  中国 黑龙江 齐齐哈尔 中移铁通
初级用户
Credits 30
Posts 11
Joined 2006-06-11 17:19
20-year member
UID 56883
Status Offline
OK, thank you. Just two % signs are enough!!!

Haha, thank you! I'm a novice, learned something new!
Floor 7 Posted 2006-09-16 04:12 ·  中国 黑龙江 齐齐哈尔 中移铁通
初级用户
Credits 30
Posts 11
Joined 2006-06-11 17:19
20-year member
UID 56883
Status Offline
There is another question. I want to ask, the Windows or WIN of the system disk can be defined with %SystemRoot%. Then what is used to define the system's Program Files! Thanks.
Floor 8 Posted 2006-09-16 04:52 ·  中国 黑龙江 齐齐哈尔 中移铁通
初级用户
Credits 30
Posts 11
Joined 2006-06-11 17:19
20-year member
UID 56883
Status Offline
Okay, found it. Thanks!
Floor 9 Posted 2006-09-16 08:52 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
Reply to floor 7:

Just run set yourself and see.

The answer is:

%ProgramFiles%

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Forum Jump: