要如何寫批次檔???

第 1 頁,共 2 頁 1 2 末頁末頁
顯示結果從第 1 筆 到 10 筆,共計 14 筆
  1. #1
    古毛
    註冊日期
    2001-05-15
    所在地區
    光纖
    討論區文章
    339

    要如何寫批次檔???

    各位,
    小弟有二個問題
    一、有個檔案,例如:msxml4.dll,要註冊,但是有個問題,環境有9x/2K/XP,
    想寫一個批次檔,可以判斷9x/2K/XP,正確註冊,但是想不出要如何判斷
    目前的作業環境,那位高手可以指點一下。

    PS:msxml4.dll在9x是放在windows\system,在2K/XP是放在winnt\system32

    二、regsvr32 msxml4.dll,註冊成功後,它會跳一個msgbox,有無方法叫它
    不會跳出來 >< ?



  2. #2
    萌え尽き症候群 琥珀 的大頭照
    註冊日期
    2002-08-17
    所在地區
    中和區
    討論區文章
    10,022
    2. regsvr32 /s *.dll

    You can type regsvr32 /? for additional information.

  3. #3
    會員
    註冊日期
    2002-08-27
    所在地區
    難說
    討論區文章
    1,448
    要讓批次檔判斷作業系統,可以用 %OS% 這個系統變數。
    先在 DOS 視窗打 echo %os% 試試...

  4. #4
    WebSphereMania Schnaufer 的大頭照
    註冊日期
    2001-03-29
    討論區文章
    8,876
      針對你的大標題 ─ 要如何寫批次檔,可以參考 The Ancient Art of DOS Batch FilesDOS Batch Language: A personal view
    Do you have interests in Software Testing !?

      Do you play Table Tennis !?

  5. #5
    古毛
    註冊日期
    2001-05-15
    所在地區
    光纖
    討論區文章
    339
    最初由 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),可以幫我看那裡寫錯,
    改老半天改不出來 >"<



  6. #6
    會員 ranger 的大頭照
    註冊日期
    2001-03-08
    討論區文章
    767
    改成這樣就 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 以免回應過多

  7. #7
    古毛
    註冊日期
    2001-05-15
    所在地區
    光纖
    討論區文章
    339
    最初由 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

  8. #8
    會員
    註冊日期
    2002-08-27
    所在地區
    難說
    討論區文章
    1,448
    可以用 errorlevel (錯誤代號)來查。
    一般程式在執行後,會把執行結果暫存於 errorlevel 裡。一般來說,0 代表成功,其它數字代表錯誤(哪裡錯誤得看數字而定)。這個檔可用來顯示 errorlevel:
    語法:
    @echo off
    if %1x==x goto noparam
    regsvr32 %1
    echo %errorlevel%
    goto end
    :noparam
    echo 請指定檔名
    echo.
    :end
    把它存為 test.bat,執行時,就打

    test [檔名].dll

    之後螢幕上就會顯示 errorlevel 值,你可以拿這個值去作參考。
    假設你已知 errorlevel 0 代表成功,批次檔可以這樣寫:
    語法:
    if errorlevel==0 goto success
    goto fail
    :success
    echo 成功!!!
    goto end
    :fail
    echo 失敗!!!
    :end

  9. #9
    古毛
    註冊日期
    2001-05-15
    所在地區
    光纖
    討論區文章
    339
    最初由 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

    如何?

  10. #10
    會員
    註冊日期
    2002-08-27
    所在地區
    難說
    討論區文章
    1,448
    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

    試試看吧。好久沒寫批次檔了,有錯還請見諒。



類似的主題

  1. 【軟體】如何改批次檔
    作者:ramonlin 所在討論版:-- Windows 更新 & 驅 動 程 式 版
    回覆: 5
    最後發表: 2007-10-30, 11:14 PM
  2. windows 2000的批次檔該如何寫?
    作者:kayguay 所在討論版:-- Windows 討 論 版
    回覆: 0
    最後發表: 2005-08-02, 12:59 PM
  3. 【求助】批次檔如何寫
    作者:weedmol 所在討論版:-- Windows 討 論 版
    回覆: 4
    最後發表: 2004-07-06, 07:31 PM
  4. 起問DOS批次檔要如何寫
    作者:napolen2000 所在討論版:-- HELP ME 電 腦 軟 硬 體 急 救 版
    回覆: 3
    最後發表: 2003-07-31, 11:01 PM
  5. 如何再編輯一批次檔
    作者:TTDim 所在討論版:-- 網 路 軟 體 討 論 二 版 (網路其他軟體)
    回覆: 4
    最後發表: 2001-09-15, 12:30 AM

 

此網頁沒有從搜尋引擎而來的訪客

發表文章規則

  • 不可以發表新主題
  • 不可以回覆文章
  • 不可以上傳附加檔案
  • 不可以編輯自己的文章
  •