|
fffcw
新手上路

积分 19
发帖 9
注册 2007-1-8
状态 离线
|
『楼 主』:
98下仅用批处实现“开机n次后执行某一命令“
执行什么命令不重要,比如建立文件,删除文件等等
重要的是如何在 开机n次后才执行,而且次数可以设定
更重要的是要在win98下实现
望大家不吝赐教
在这里找了很久,大多数代码98下都不能执行
我自己花了一天终于实现了意图,这基本上是我独立编的第一个程序
但是我的办法非常拙劣
等到大家给出自己的答案后,我再公布自己的办法
只为换得大家一笑
谢谢
|
|
2007-1-21 11:31 |
|
|
lotus516
高级用户
    论坛上抢劫的
积分 551
发帖 246
注册 2006-9-21
状态 离线
|
『第
2 楼』:
有那么神密么?还要我们贴了才给看,本人不才贴一个!!
@echo off
if not exist c:\%date:~0,4%%date:~5,2%%date:~8,2%.txt echo 0 >c:\%date:~0,4%%date:~5,2%%date:~8,2%.txt
setlocal enabledelayedexpansion
for /f %%i in (c:\%date:~0,4%%date:~5,2%%date:~8,2%.txt) do (
if "%%i"=="7" echo %%i&&exit
set /a num=%%i+1
echo !num! >c:\%date:~0,4%%date:~5,2%%date:~8,2%%.txt
set /a wj=%date:~0,4%%date:~5,2%%date:~8,2%-1
del c:\!wj!.txt
exit
) 要次数的话和运行的程序自己把 if "%%i"=="7" echo %%i&&exit改了!!
98不支持for是不?那么这个呢?
@echo off
if not exist c:\%date:~0,4%%date:~5,2%%date:~8,2%.txt echo 0 >c:\%date:~0,4%%date:~5,2%%date:~8,2%.txt
setlocal enabledelayedexpansion
set /p num=<c:\%date:~0,4%%date:~5,2%%date:~8,2%.txt
echo !num!
if !num! gtr 7 echo 成功&&exit
set /a num+=1
echo !num! >c:\%date:~0,4%%date:~5,2%%date:~8,2%%.txt
set /a wj=%date:~0,4%%date:~5,2%%date:~8,2%-1
del c:\!wj!.txt
exit 无98无法测
[ Last edited by lotus516 on 2007-1-22 at 12:01 PM ]
|
|
2007-1-22 02:51 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第
3 楼』:
98不支持 for /f 滴 -_-!
|

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'>" |
|
2007-1-22 03:59 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第
4 楼』:
DOS 下好像没有set/a
试试:
@echo off
if not exist c:\Num.bat >c:\Num.bat echo set Num=*
call Num.bat
if "%Num%" == "*******" goto run
set Num=%Num%*
>Num.bat echo set Num=*
goto end
:run
start ......
:end
exit PS:没有环境测试
|
|
2007-1-22 13:28 |
|
|
zch1366
中级用户
  
积分 326
发帖 148
注册 2005-12-16
状态 离线
|
『第
5 楼』:
XP下又如何编写啊..请各位大哥赐教...谢谢
|
|
2007-1-23 01:45 |
|
|
heicai
中级用户
  
积分 385
发帖 156
注册 2007-1-19
状态 离线
|
|
2007-1-23 02:10 |
|
|
lotus516
高级用户
    论坛上抢劫的
积分 551
发帖 246
注册 2006-9-21
状态 离线
|
『第
7 楼』:
Quote: | Originally posted by zch1366 at 2007-1-23 01:45:
XP下又如何编写啊..请各位大哥赐教...谢谢 |
|
不是贴了三个么?
|
|
2007-1-23 03:48 |
|
|
binghejin
初级用户
 
积分 48
发帖 19
注册 2006-12-27
状态 离线
|
『第
8 楼』:
基本思路,不知对否!
if not exist %windir%\3 goto 2(假设要运行3次后执行)
goto start
:2
if not exist %windir%\2 goto 1
ren %windir%\2 3
goto end
:1
if not exist %windir%\1 goto jl
ren %windir%\1 2
goto end
:jl
copy autoexec.bat %windir%\1(随便找一个肯定存在的文件拷贝)
goto end
:start
预先设定的程序代码
goto end
:end
此方法对XP和98都有效!
[ Last edited by binghejin on 2007-1-22 at 03:32 PM ]
|
|
2007-1-23 04:23 |
|
|
zch1366
中级用户
  
积分 326
发帖 148
注册 2005-12-16
状态 离线
|
|
2007-1-23 04:26 |
|
|
zch1366
中级用户
  
积分 326
发帖 148
注册 2005-12-16
状态 离线
|
『第
10 楼』:
@echo off
if not exist c:\%date:~0,4%%date:~5,2%%date:~8,2%.txt echo 0 >c:\%date:~0,4%%date:~5,2%%date:~8,2%.txt
setlocal enabledelayedexpansion
for /f %%i in (c:\%date:~0,4%%date:~5,2%%date:~8,2%.txt) do (
if "%%i"=="7" echo %%i&&exit
set /a num=%%i+1
echo !num! >c:\%date:~0,4%%date:~5,2%%date:~8,2%%.txt
set /a wj=%date:~0,4%%date:~5,2%%date:~8,2%-1
del c:\!wj!.txt
exit
)
要次数的话和运行的程序自己把 if "%%i"=="7" echo %%i&&exit改了!!
98不支持for是不?那么这个呢?
if "%%i"=="7" echo %%i&&exit 改了 if "%%i"=="3" echo %%i&&setup 不成功
if "%%i"=="7" echo %%i&&exit 改了 if "%%i"=="3" echo %%setup&&exit 不成功
我改错了吗??谢谢赐教...
|
|
2007-1-23 04:54 |
|
|
lotus516
高级用户
    论坛上抢劫的
积分 551
发帖 246
注册 2006-9-21
状态 离线
|
『第
11 楼』:
if "%%i"=="7" echo %%i&&exit 改了 if "%%i"=="3" echo %%i&&setup 不成功
if "%%i"=="7" echo %%i&&exit 改了 if "%%i"=="3" echo %%setup&&exit 不成功
setup,你加个路径看看!!!%%setup是一定错的!!你有setup这个变量么?给个实例更好理解!!
if "%%i"=="3" start d:\qq.exei&&exit
[ Last edited by lotus516 on 2007-1-23 at 01:08 PM ]
|
|
2007-1-23 11:00 |
|
|
fffcw
新手上路

积分 19
发帖 9
注册 2007-1-8
状态 离线
|
『第
12 楼』:
谢谢各位的智力奉献,由于上网不多,所以没有尽早回复各位
2楼本人不是神秘,实在是水平欠佳,你们写的我基本读不懂
而且我的办法的确相当拙劣,本来爱面子不该献丑
但是从中也能看出我的死缠烂打精神
2,4,8楼的我马上试验一下,看98下可否
至于为什么非要用98,权当一个考题好了,真正会98批处的我想一定是最顶尖的高手
何况这里叫做 中国DOS联盟 ! 而不是叫 中国XP联盟 !
[ Last edited by fffcw on 2007-1-22 at 11:54 PM ]
|
|
2007-1-23 12:13 |
|
|
fffcw
新手上路

积分 19
发帖 9
注册 2007-1-8
状态 离线
|
『第
13 楼』:
测试结果有了 8 楼的非常成功,恭喜你的了第一名,奖品到斑竹处领取
测试的代码如下:
if not exist %windir%\3 goto 2
goto start
:2
if not exist %windir%\2 goto 1
ren %windir%\2 3
goto end
:1
if not exist %windir%\1 goto jl
ren %windir%\1 2
goto end
:jl
copy c:\autoexec.bat %windir%\1
:: 上面的autoexec.bat要去掉隐藏等属性
goto end
:start
echo 按计划需要执行的程序代码
goto end
:end
但是
如果我要设定100次。。。。。。你还有更好的改进吗?
|
|
2007-1-23 13:04 |
|
|
fffcw
新手上路

积分 19
发帖 9
注册 2007-1-8
状态 离线
|
『第
14 楼』:
恭喜4楼获得最佳创意奖,你的想法很good,但是
set Num=%Num%*
>Num.bat echo set Num=*
请说明一下意思,执行数次后Num.bat 文件里面只是" Num=* "
没有出现几个" * " 号
我改成“ set Num=%Num%* >Num.bat echo set Num=* "
不行,改成" set Num=%Num%* >Num.bat " 也不行
嗬嗬,见笑了
你还能改进吗?特等奖等着你呢
|
|
2007-1-23 13:12 |
|
|
fffcw
新手上路

积分 19
发帖 9
注册 2007-1-8
状态 离线
|
『第
15 楼』:
2楼很遗憾
代码只在C盘建立了一个文本文件,全名是“.txt" ,点前什么也没有
setlocal enabledelayedexpansion 这句报告语法错误
后面的句子好像用到了前面的参数,所以没有单独测试
而且时间也晚了,我也是要休息滴
但是你还是获得了第三名的好成绩,加油,晚安,兄弟!
毫无疑问
你的想法也很ok,用时间进行检验再好不过了
不建立文件,直接用时间写成判断语句是不是更简洁呢?
请再试试看!
我忽然又冒出个念头,试成了一起告诉大家
夜深了,大家好梦!
[ Last edited by fffcw on 2007-1-23 at 12:25 AM ]
|
|
2007-1-23 13:17 |
|