這可以通過在Internet Explorer中啓動sharepoint頁面的地址並使用一些pinvoke api將密鑰或settext發送到登錄框來完成。
我對vb.net表單應用程序的這個設置進行了擴展。它適用於我的XP。我還沒有在Windows 7中嘗試過,但我相信它需要一些調整才能在那裏工作。
它使用一個名爲WindowScraper庫,從這裏開始:http://www.programmersheaven.com/download/56171/download.aspx
該庫有一堆WINAPI和PInvoke的內置如果你的組件將不會允許它(因爲你使用VS 2010,也許)。稱它沒有強名,然後使用SharpDevelop並在添加自己的證書後重建解決方案。
然後將dll放到您的應用程序目錄中並添加一個引用。
然後添加進口:
Imports WindowScrape
Imports WindowScrape.Constants
Imports WindowScrape.Types
最後,該代碼(把所有的模塊或類):
私有財產PortalAddress的String =「HTTP:// myportal @地方。 COM」 私有財產logintitle的String = 「連接到[email protected]」
公用Sub openPortal()
If My.Computer.Info.OSFullName = "Microsoft Windows XP Professional" then
LoginToPortalXP()
Else
msgbox("Someday, we will be able to log you in automatically" & vbCr & "But it isn't ready yet.")
End If
End Sub
Private Function IsWindowReady(Optional ByVal timeout As integer = 10000)
Dim isready As Boolean = false
Dim timer As Integer = 1000
Do Until Not loginBox is nothing or timer = timeout
Thread.Sleep(1000)
loginbox = HwndObject.GetWindowByTitle(logintitle)
timer = timer + 1000
loop
If Not loginbox is nothing then isready = true
Return isready
End Function
Sub LoginToPortalXP()
Try
Dim TheBrowser As Object = CreateObject("InternetExplorer.Application")
TheBrowser.Visible = True
TheBrowser.Navigate(PortalAddress)
If Not IsWindowReady then debug.print("failed") : Exit sub
Dim sys As HwndObject = loginbox.GetChildren(1) 'SysCredential
sys.GetChildren(1).Text = "myUserName" 'username box
Thread.Sleep(500)
sys.GetChildren(4).Text = "myPassword" 'password box
Thread.Sleep(500)
loginbox.GetChildren(2).Click() 'push the okay button
Catch ex As Exception
msgbox("ERROR AutoLogging into Portal: " & vbcr & & ex.Message)
Finally
End Try
End Sub
我增加了計時器,以防萬一需要更長的時間。當然,您可以更改超時時間。
你好@BGM,謝謝你的回覆。但是,我希望有一點「黑客」,使用更多的函數構建。也許我正在尋找的答案並不存在。無論如何,我真的很喜歡這個創意和你採取的方法,並提高了答案。但是不要以爲我能給出最終答案呢。再次感謝。 – mateuscb
@mateuscb嗯,我想說,我一直在尋找方法來做這個幾年。我發現的唯一方法就是這種「哈克」方式。我已經在autohotkey中編寫了另一個腳本,它執行相同的操作,但允許您選擇一個帳戶進行登錄,並且它也可以在Firefox中使用。上面的方法適用於dotnet,除了dotnet和api之外沒有任何其他方法。實際上它工作得很好。唯一的缺點是如果MS更改控件的順序。另外,我只在XP和Sharepoint Services 2007上試過它;我正在爲Windows7工作。 – bgmCoder
再次感謝@BGM! – mateuscb