标题: 怎样判断系统当前运行的环境是dos还是 windows
[打印本页]
作者: koala
时间: 2007-7-14 10:56
标题: 怎样判断系统当前运行的环境是dos还是 windows
:( 要求纯脚本,不允许使用第三方工具
可以从启动日志和注册表入手
-------------------------------------------------
写怎样的一个批处理脚本可以实现以下目的:
写一个含有goto指向功能的批处理脚本,判断当前系统运行的环境是在dos下还是在windows下
个人看法:用注册表regedit /e KeyName(注册表保存相关数据的位置) 导出到 filename(导出文件名字)
然后 type "filename(导出文件名字)"|"%find%" /i "strings"查找相关字符串(strings)
再用 if errorlevel返回错误代码,可是我不知道收藏相关数据的注册表位置在哪里
解题思路:系统每次成功引导都会留下日志(或者说是痕迹),
他们可能保存在 registry
或 %systemroot%中某个log文件中
请求高手帮帮koala的忙
个人模拟的命令行格式如下:
(由于爱死dos,受德国人的脚本思想的启惠,衍生了以下的例子)
如果感兴趣我将本人汉化修正的传给你看看
或者到
http://loveskoala.gbaopan.com下载 "NT核系统服务优化"
----------------------------------------------------------------------------------------------------------
脚本正文
----------------------------------------------------------------------------------------------------------
@echo off
path==%systemroot%\system32;%systemroot%;%systemdrive%\;
set find=%systemroot%\system32\find.exe
title 确定操作系统的运行环境
color 1a
cls
:Find_Out_OS
regedit /e filename keyname
:/*********
rem 或者 reg export keyname filename
rem 导出的注册表文件大小大约是上面的1/9
:**********/
type "filename"|"%find%" /i "strings1" >nul
if errorlevel==1 (
type "filename"|"%find%" /i "strings2" >NUL
if errorlevel==1 (
SET windows_OS=FALSE
echo 未发现有效的操作系统!
goto NO_FIND_OS
)
SET windows_OS=FALSE
echo 您的系统当前运行在DOS下!
goto :NO_windows_OS
)
SET windows_OS=TRUE
echo 您的系统当前运行在windows下!
goto :NO_DOS_OS
:NO_DOS_OS
if windows_OS=TRUE command /options
............(执行命令部分)
NO_windows_OS
if windows_OS=FlASE command /options
...............(执行命令部分)
:NO_FIND_OS
if windows_OS=FlASE command /options
............(执行命令部分)