引用 | 編輯
綠茶三頭犬
2013-01-25 06:46 |
樓主
▼ |
||
x0
1. www.abc.com/index.php 能否載入成功,若能則顯示 Label1,else 顯示 Label22. 讀取 ini 問題,雖然在網上找到方法,也十分成功,但網上的方法大多是 PartA_1=TestA1 PartB_1=TestB1 Dim lReturnLen1 As UInt64 Dim sSection1 As String = "Part1" '區段 Dim sKey1 As String = "PartA_1&qu .. 訪客只能看到部份內容,免費 加入會員 x0
|
引用 | 編輯
ebolaman
2013-01-27 14:12 |
1樓
▲ ▼ |
P.S. 文章標題最好改一下,以利搜尋功能
1. 可以用 HttpWebRequest 和 HttpWebResponse 來測試網站的回應 除此之外,在連接完成後,可以進一步取得網頁 或是 作其他的 request 底下的 tryConnect 連接成功會傳回 true 複製程式 Private Function tryConnect() Dim httpReq As Net.HttpWebRequest = Net.WebRequest.Create("http://www.google.com") Dim httpRes As Net.HttpWebResponse httpReq.Method = "GET" '嘗試連接 Try httpRes = httpReq.GetResponse Catch ex As Net.WebException MessageBox.Show(ex.Message) Return False End Try '檢查 StatusCode (正確的話通常是 200 = Net.HttpStatusCode.OK) If httpRes.StatusCode = Net.HttpStatusCode.OK Then MessageBox.Show("OK") Return True Else MessageBox.Show("Oops!! Status code = " & httpRes.StatusCode) Return False End If End Function 2. 最簡單的辦法是用 REGEX (regular expression) 第一行的 pattern 是 \[.+\][\r\n]+(.+=[^\r\n]+)[\r\n] \[ -> [ .+ -> 任何字元 \] -> ] [\r\n]+ -> 超過一次以上的 CrLf [^\r\n]+ -> 一次以上的非 CrLf 的字元 用刮號 () 是為了取得想要的部分而已,即是 以下 code 中 match(i).Groups(1).Value 抓到的值 要測試 regex 有許多軟體可以測試,除了維基提供的 regex 編輯器 還有 Notepad++ 的插件 RegEx Helper 和免費版非常好用的的 Rad Software Regular Expression Designer 和不是免費版但卻很高級的 Expresso 其實大部分的文字編輯器搜尋部分就有 Regex 的功能 (ex. Sublime Text, Notepad++, EmEditor, gVIM, Emacs, UltraEdit, TextMate, ...) 幾乎所有程式設計軟體也都有內建的 Regex 複製程式 Private Function tryParse(ByVal s As String) Dim pattern As String = "\[.+\][\r\n]+(.+=[^\r\n]+)[\r\n]" '[XXX] <CrLf> XXX=XXX <CrLf> Dim match As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(s, pattern) If 0 <> match.Count Then '如果 match 成功 For i As Integer = 0 To match.Count - 1 Dim val As String = match(i).Groups(1).Value MessageBox.Show(val) Next Return True Else Return False End If End Function 3. 參考程式碼 複製程式 Private Function stopService(ByVal s As String) 'Reference: http://www.vbforums.com/showthread.php?678233-RESOLVED-Stopping-a-Service-using-VB.Net Dim sc As New System.ServiceProcess.ServiceController sc.ServiceName = s sc.MachineName = Environment.MachineName Try If sc.Status = ServiceProcess.ServiceControllerStatus.Stopped Then '服務早就停止 Return True Else sc.Refresh() sc.Stop() sc.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped) Return True End If Catch ex As Exception MessageBox.Show(ex.Message) Return False End Try End Function Private Function startService(ByVal s As String) 'Reference: http://www.vbforums.com/showthread.php?678233-RESOLVED-Stopping-a-Service-using-VB.Net Dim sc As New System.ServiceProcess.ServiceController sc.ServiceName = s sc.MachineName = Environment.MachineName Try If sc.Status = ServiceProcess.ServiceControllerStatus.Running Then '服務早就在跑 Return True Else sc.Refresh() sc.Start() sc.WaitForStatus(ServiceProcess.ServiceControllerStatus.Running) Return True End If Catch ex As Exception MessageBox.Show(ex.Message) Return False End Try End Function Examples: 例如想關掉 Remote Registry 服務 可以用 Win7 的工作管理員中的服務列表查 名稱是 RemoteRegistry 或是用軟體 System Explorer 來查 注意 description 是 "Remote Registry" 有一個空格 而真正的 name 是 "RemoteRegistry" 沒有空格 呼叫函式要用 name 而不是 description stopService("RemoteRegistry") 來關閉服務 startService("RemoteRegistry") 來重新執行服務 處理成功函式會傳回 true x1 |
引用 | 編輯
綠茶三頭犬
2013-01-27 19:23 |
2樓
▲ ▼ |
下面是引用 ebolaman 於 2013-01-27 14:12 發表的 : Private Function SwitchService(ByVal strSvcName As String, ByVal blnOpen As Boolean) As Boolean Dim strWMIcls As String Dim objSvc As Object strWMIcls = "Win32_Service" objSvc = GetObject("winmgmts:").InstancesOf(strWMIcls)(strWMIcls & ".Name=""" & strSvcName & """") SwitchService = CallByName(objSvc, IIf(blnOpen, "StartService", "StopService"), 1) = 0 End Function SwitchService("wuauserv", False) SwitchService("W32Time", True) 1. 其實這個與你的寫法那個較好? (噢,你那個較好點) 2. 不如先說我要製作甚麼,是類似釋放記憶體的程式,類似 Game Booster / JetBoost 不過想自行製作,但怎清理電腦內存 - -? 即是按一下 Button 便能 Free memory 若只釋放我的程式我就懂,但釋放電腦記憶體就太難吧 - -? 最好每一分鐘釋放一次,太頻密應該會導致程式出現異常吧? 3. 優先權先否將記憶體盡量分配在高優先度應用程式? x0 |