如何利用批次檔(Batch)讀取指令執行的結果或文字檔案內容

The Will Will Web | 如何利用批次檔(Batch)讀取指令執行的結果或文字檔案內容

最近從 Visual Studio 2010 的 建置部署套件 功能自動產生的網站安裝批次檔中學到一個批次檔的使用技巧,他可以透過批次檔直接讀取機碼(Registry)的資訊並擷取出執行檔所在路徑,這樣一來就不用將執行檔所在的路徑寫死在批次檔裡,是非常彈性的一種方法,藉此也剛好把批次檔的 FOR 語法的使用方式給釐清一番,這樣一來以後要透過批次檔讀取或解析文字檔就更方便了。

我們先來看看這段批次檔的內容,並解釋各參數的用法,不過這種語法有點學習門檻,一定要多加思考才能融會貫通:

注意:在批次檔中要寫 %i 變數必須要寫成 %%i 才行,如果直接在指令列模式執行時可直接輸入 %i

mouse_event, mouse simulation

AllAPI.net – Your #1 source for using API-functions in Visual Basic!

mouse_event

The mouse_event function synthesizes mouse motion and button clicks.Windows NT only: This function has been superseded. Use MouseEventEx instead.

VB4-32,5,6
Declare Sub mouse_event Lib “user32″ Alias “mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

Mouse emulation

Mouse emulation [Archive] – VBForums

Hack
Dec 11th, 2001, 06:23 AM
Take a look at this link.

http://www.allapi.net/apilist/apifunction.php?apifunction=mouse_event

Incendently, I can find nothing on MouseEventEx, so play around with MouseEvent and see what that does for you.


AlbafaN
Dec 11th, 2001, 01:14 PM
you’ll wanna use the SendMessage API with the WM_LBUTTONDOWN and WM_LBUTTONUP constants….

—-
Public Declare Function SendMessage Lib “user32″ Alias “SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
—-

SendMessage hWnd&, WM_LBUTTONDOWN, 0&, 0&
SendMessage hWnd&, WM_LBUTTONUP, 0&, 0&

…. but before you do this, you need to get the handle (hWnd) of the window the mouse is over (the button, or whatever). If you dont know how to do this, lemme know…