How to login in Office 365 from VBScript and brows

2019-09-10 00:54发布

问题:

I'm packing an Access application, This is connecting with a Sharepoint site. I'm using Inno Setup (With Pascal Scripts) for create an install package. So, I found this code for do something similar to that I want, when I run the code seems work fine: Open the browser, goes to Office 365, puts information (account and password), but just in the moment when open the cmd and after few seconds, all closes without finish the process.

On Error Resume Next

Const PAGE_LOADED = 4

Set objIE = CreateObject("InternetExplorer.Application.1")
Call objIE.Navigate("https://yourdomain.sharepoint.com")

objIE.Visible = True

Do Until objIE.ReadyState = PAGE_LOADED : Call WScript.Sleep(500) : Loop

objIE.Document.all.Login.Value = "username@yourdomain.com"
objIE.Document.all.Passwd.Value = "office365password"
objIE.Document.all.persist.checked=True

'The "Submit" button needs to be "clicked" twice in order to sign the user in
' * It appears that some javascript needs to take place behind the scenes to properly initiate the logon
Call objIE.Document.getElementById("cred_sign_in_button").click
Call objIE.Document.getElementById("cred_sign_in_button").click

WScript.Sleep(4000)

Do Until objIE.ReadyState = PAGE_LOADED : Call WScript.Sleep(500) : Loop

Set wShell=CreateObject("WScript.Shell")

NetCommand="net.exe use p: ""https://yourcompany.sharepoint.com/Library 1""  /user:username@yourdomain.com office365password"
wShell.Run "cmd.exe /C " & NetCommand, 1, True

Set wShell=Nothing

objIE.quit

Set objIE = Nothing

Seems to maybe can be here:

Set wShell=CreateObject("WScript.Shell")

NetCommand="net.exe use p: ""https://yourcompany.sharepoint.com/Library 1""  /user:username@yourdomain.com office365password"
wShell.Run "cmd.exe /C " & NetCommand, 1, True

My final aim is do the all process of login in the backstage (for code), create the connexion with 365 via (VBScript (?)), providing the credentials in the script, thereupon go a list in sharepoint site, title: (Serial Numbers(?)) where I Have a list with several numbers and checkboxes for to mark true in every install and avoid use the same number two times.

Thanks for advance!