各位,
小弟有二個問題
一、有個檔案,例如:msxml4.dll,要註冊,但是有個問題,環境有9x/2K/XP,
想寫一個批次檔,可以判斷9x/2K/XP,正確註冊,但是想不出要如何判斷
目前的作業環境,那位高手可以指點一下。
PS:msxml4.dll在9x是放在windows\system,在2K/XP是放在winnt\system32
二、regsvr32 msxml4.dll,註冊成功後,它會跳一個msgbox,有無方法叫它
不會跳出來 >< ?
各位,
小弟有二個問題
一、有個檔案,例如:msxml4.dll,要註冊,但是有個問題,環境有9x/2K/XP,
想寫一個批次檔,可以判斷9x/2K/XP,正確註冊,但是想不出要如何判斷
目前的作業環境,那位高手可以指點一下。
PS:msxml4.dll在9x是放在windows\system,在2K/XP是放在winnt\system32
二、regsvr32 msxml4.dll,註冊成功後,它會跳一個msgbox,有無方法叫它
不會跳出來 >< ?
2. regsvr32 /s *.dll
You can type regsvr32 /? for additional information.
要讓批次檔判斷作業系統,可以用 %OS% 這個系統變數。
先在 DOS 視窗打 echo %os% 試試...
針對你的大標題 ─ 要如何寫批次檔,可以參考 The Ancient Art of DOS Batch Files 及 DOS Batch Language: A personal view。
以下是我寫的:最初由 jute 發表
要讓批次檔判斷作業系統,可以用 %OS% 這個系統變數。
先在 DOS 視窗打 echo %os% 試試...
set win=%os%
echo This OS is "%os%"
if "%os%"==Windows
goto 9x
if "%os%"==Windows_NT
goto NT
:9x
REM Win95/98
%windir%\system\regsvr32.exe %windir%\system\msxml4.dll /s
goto end
:NT
REM WinNT/2K
%windir%\system32\regsvr32.exe %windir%\system32\msxml4.dll /s
goto end
:end
echo Reg Final
===========
我在Win2K下run,一直說語法錯誤(在第一個if),可以幫我看那裡寫錯,
改老半天改不出來 >"<
改成這樣就 ok.....
@echo off
echo This OS is "%os%"
if %os%==Windows goto 9x
if %os%==Windows_NT goto NT
:9x
REM Win95/98
%windir%\system\regsvr32.exe %windir%\system\msxml4.dll /s
goto end
:NT
REM WinNT/2K
%windir%\system32\regsvr32.exe %windir%\system32\msxml4.dll /s
goto end
:end
echo Reg Final
===============================================================
if ......goto 不應分行,另set win=%os% 在這堥繭L作用,所以拿掉了
在第一行加上@echo off 以免回應過多
---------最初由 ranger 發表
改成這樣就 ok.....
@echo off
echo This OS is "%os%"
if %os%==Windows goto 9x
if %os%==Windows_NT goto NT
:9x
REM Win95/98
%windir%\system\regsvr32.exe %windir%\system\msxml4.dll /s
goto end
:...
謝謝,可以了耶^^
再請一個問題,如果執行regsvr32,發現無法成功執行,
是否有辦法給一個msg,就如同執行成功,也有一個msg
可以用 errorlevel (錯誤代號)來查。
一般程式在執行後,會把執行結果暫存於 errorlevel 裡。一般來說,0 代表成功,其它數字代表錯誤(哪裡錯誤得看數字而定)。這個檔可用來顯示 errorlevel:
把它存為 test.bat,執行時,就打語法:@echo off if %1x==x goto noparam regsvr32 %1 echo %errorlevel% goto end :noparam echo 請指定檔名 echo. :end
test [檔名].dll
之後螢幕上就會顯示 errorlevel 值,你可以拿這個值去作參考。
假設你已知 errorlevel 0 代表成功,批次檔可以這樣寫:
語法:if errorlevel==0 goto success goto fail :success echo 成功!!! goto end :fail echo 失敗!!! :end
改成這樣...最初由 jute 發表
可以用 errorlevel (錯誤代號)來查。
一般程式在執行後,會把執行結果暫存於 errorlevel 裡。一般來說,0 代表成功,其它數字代表錯誤(哪裡錯誤得看數字而定)。這個檔可用來顯示 errorlevel:
[code]@echo off...
@echo off
if %os%==Windows goto 9x
if %os%==Windows_NT goto NT
:9x
REM Win95/98
echo 你的作業系統是 Windows 95/98/98SE
%windir%\system\regsvr32.exe %windir%\system\msxml4.dll /s
if %errorlevel%==0 goto ok
if %errorlevel%==3 goto err
if %errorlevel%==4 goto err
:NT
REM WinNT/2K
echo 你的作業系統是 Windows NT/2K
%windir%\system32\regsvr32.exe %windir%\system32\msxml4.dll /s
rem echo %errorlevel%
if %errorlevel%==0 goto ok
if %errorlevel%==3 goto err
if %errorlevel%==4 goto err
k
echo 作業成功
goto end
:err
echo 作業失敗
echo ------
pause
goto end
:end
@echo off
如何?
1. if 那幾行的 errorlevel 不需要加 "%"。
2. 這樣寫法,若 errorlevel 不等於 0、3 或 4,那怎麼辦?
3. 重複的那幾行 errorlevel 可以收在一起。
因為你只是要區別成功失敗,亦即 0=成功;其它=失敗,故改成這樣可能比較好:
[code]@echo off
if %os%==Windows goto 9x
if %os%==Windows_NT goto NT
:9x
REM Win95/98
echo 你的作業系統是 Windows 95/98/98SE
%windir%\system\regsvr32.exe %windir%\system\msxml4.dll /s
goto errchk
:NT
REM WinNT/2K
echo 你的作業系統是 Windows NT/2K
%windir%\system32\regsvr32.exe %windir%\system32\msxml4.dll /s
errchk:
if errorlevel==0 goto ok
goto err
k
echo 作業成功
goto end
:err
echo 作業失敗
echo ------
pause
:end
試試看吧。好久沒寫批次檔了,有錯還請見諒。
書籤