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-12 15:09
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Problem] Let the batch processing determine by itself whether it is run by double - clicking View 3,040 Replies 20
Original Poster Posted 2008-11-12 18:35 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
Title: Understand the batch processing operation mechanism.

Bonus rules:
Novel idea 8 points
No temporary files 3 points
Concise code 3 points
Perfect code 15 points

Title content:
Let the batch processing judge by itself whether it is double-clicked to run or manually input and run in CMD.
Just like tasklist.exe, net.exe, ping.exe, when we double-click these files, they will flash by and we can't see the help information of these commands. Only when we manually input in CMD can we see. Now the question is to write a batch file. When we double-click to run (without any parameters), display "Double-click to run" and pause. If it is manually input and run in CMD (also without any parameters), display "Run manually input in CMD" and then do not pause, directly return to the command prompt.
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
HAT +4 2008-11-12 20:40
523066680 +15 2009-10-12 17:43
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
Floor 2 Posted 2008-11-12 19:49 ·  中国 湖北 武汉 联通
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
@echo off
wmic process where "name='cmd.exe'" get commandline | findstr /ric:"^cmd /c.*%~n0" >nul&& echo/Double-click run || echo/Command line run
pause

Is this okay?
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
pusofalse +15 2008-11-12 20:13
Floor 3 Posted 2008-11-12 20:13 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
Floor 4 Posted 2008-11-12 20:29 ·  中国 广东 江门 电信
中级用户
★★
Credits 338
Posts 175
Joined 2007-10-21 15:30
18-year member
UID 100351
Gender Male
Status Offline
Floor 5 Posted 2008-11-12 22:39 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Administrator>"C:\Documents and Settings\Administrator
\Desktop\123.bat"
Double-click to run
CommandLine
"C:\WINDOWS\system32\cmd.exe"
cmd /c ""C:\Documents and Settings\Administrator\Desktop\123.bat" "
cmd /c ""C:\Documents and Settings\Administrator\Desktop\123.bat" "
"C:\WINDOWS\system32\cmd.exe"

Press any key to continue. . .
S smile 微笑,L love 爱,O optimism 乐观,R relax 放松,E enthusiasm 热情...Slore
Floor 6 Posted 2008-11-13 11:00 ·  中国 湖北 武汉 联通
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Hehe, special circumstances naturally didn't consider so much.
Floor 7 Posted 2008-12-06 01:01 ·  中国 江西 赣州 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
```
@echo off
if "%~1"=="" (
if "%~0"=="%~nx0" (
echo Run manually in CMD
) else (
echo Run by double-clicking & pause
)
)
```

Utilization: Double-clicking will display the full path of the batch file itself, while in the command prompt window only the file name is displayed.
(Of course, if the full path is entered in the command prompt window, it will be misjudged)
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
523066680 +15 2009-10-10 19:45
Floor 8 Posted 2009-10-10 19:46 ·  中国 广东 广州 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
It will become a classic! Although I'm not new here, I still post to boost it.
Floor 9 Posted 2009-10-10 21:56 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
Unless double quotes are included when entering at the command line, and also pay attention to sometimes uppercase and sometimes lowercase, otherwise it should not be misjudged, right!

@echo off&setlocal enabledelayedexpansion
set a0=%0
set a1="%cd%\%~nx0"

if !a0! equ !a1! (echo Double-click to run) else (echo Run from command line)
echo !a0!
echo !a1!
pause
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
523066680 +9 2009-10-12 17:50
精简
=> 个人网志
Floor 10 Posted 2009-10-11 18:19 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
re: netbenton

Brother's code still lacks consideration. There is a special case for the system variable cd that the last character in the root directory does not have "\". It seems that this point is still ignored by many people.

In fact, judging by the cmdcmdline variable is more orthodox.
山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
Floor 11 Posted 2009-10-11 19:42 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
What's a little more?
@echo off&setlocal enabledelayedexpansion

set a0=%0
set a1="%cd%\%~nx0"
set a1=!a1:\\=\!

if !a0! equ !a1! (echo Double-click to run) else (echo Run in command line)
echo !a0!
echo !a1!
pause
精简
=> 个人网志
Floor 12 Posted 2009-10-12 17:26 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
I can't answer this question. You can provide other topics and I will try my best to help you.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
523066680 +9 2009-10-12 17:43
山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
Floor 13 Posted 2009-10-12 17:42 ·  中国 广东 广州 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
Calling in cmd...


C:\Documents and Settings\liubo\Desktop>call a.bat
There should not be /c at this time.

C:\Documents and Settings\liubo\Desktop>@if ""C:\WINDO"=="cmd /c " (echo Double-click) else (echo Not double-click)

C:\Documents and Settings\liubo\Desktop>

(Warm reminder, liubo is not my name, I don't call Liu Bo... Don't make fun of me ha)

[ Last edited by 523066680 on 2009-10-12 at 17:49 ]
Floor 14 Posted 2009-10-12 18:17 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
Robust be tested by everyone


@echo off
echo %cmdcmdline%|findstr/bc:"cmd /c """>nul&&echo Double-clicked||echo Not double-clicked
pause
山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
Floor 15 Posted 2009-10-12 18:35 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
Originally posted by pusofalse at 2008-11-12 06:35 PM:
The purpose of the question: To understand the operation mechanism of batch processing.

Bonus rules:
8 points for novel ideas
3 points for no temporary files
3 points for concise code
15 points for perfect code

Question content:
Let the batch processing determine by itself whether it is...


I don't know if this is the meaning

http://bbs.bathome.cn/viewthread.php?tid=4725
山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
Forum Jump: