正确的vbs源代码 [英] correct vbs source code
本文介绍了正确的vbs源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨我有这个代码来获取默认浏览器并做一些事情,比如打开网址等...然后再关闭它
i发现这段代码但它给了我很多错误
hi i have this code to get the default browser and do some thing like open url etc ... then close it again
i found this code but it give me alot of error
Private Function getDefaultBrowser() As String
Dim browser As String = String.Empty
Dim key As RegistryKey = Nothing
Try
key = Registry.ClassesRoot.OpenSubKey("HTTP\shell\open\command", False)
'trim off quotes
browser = key.GetValue(Nothing).ToString().ToLower().Replace("""", "")
If Not browser.EndsWith("exe") Then
'get rid of everything after the ".exe"
browser = browser.Substring(0, browser.LastIndexOf(".exe") + 4)
End If
Finally
If key IsNot Nothing Then
key.Close()
End If
End Try
Return browser
End Function
和这用于循环
and this for looping
Dim browser As String
browser = getDefaultBrowser()
For Each p As Process In Process.GetProcesses
If p.ProcessName = browser Then
p.Kill()
Exit For
End If
Next
推荐答案
我不明白为什么你需要获取默认浏览器 - 您的系统知道默认浏览器是什么 - 所以您只需要这样做
I dont see why you need to 'get' the default browser - your system knows what the default browser is - so you only need to do
CreateObject("WScript.Shell").Run "www.codeproject.com"
用默认浏览器打开CP。如果你想在特定的浏览器中打开一个URL,那就变得有点困难 - 但你可以谷歌代码来做那个
to open CP with the default browser. If you want to open a URL in a specific browser, then it becomes a little more difficult - but you can google for code to do that
这篇关于正确的vbs源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文