Jump to content

Recommended Posts

Posted

Greetings all.

 

This is a bit of a long shot. We have a little program (exe), that someone wrote but is no longer available to get any support from. Essentially the exe is provided as a shortcut to windows start menu. When ran, it opens IE, goes to O365 email, and fills in the currently logged on users email address - that's all.

 

We now want to do that same but with Edge. Can anyone recommend a bit of a vbscript or something that will do the same thing?

 

Thanks for any input.

Manny

Posted (edited)

Using AutoIT - this should get you started.

 

I can't launch EDGE like this for the world, so i uses IE as an example.

Also you have to wait for the page to load before sending the keys. this will have to be compiled to an EXE.

I recommend Firefox in private browsing mode as IE throws a hidden login window if you have a federated page that redirects like we do. Unfortunately the method to launch EDGE does not work and I have to research it. We avoid EDGE like the plague because it causes issues even in o365

 

ShellExecuteWait("C:\Program Files (x86)\Internet Explorer\iexplore.exe", "https://login.microsoftonline.com/common/oauth2/authorize?client_id=4345a7b9-9a63-4910-a426-35363201d503&response_mode=form_post&response_type=code+id_token&scope=openid+profile&state=OpenIdConnect.AuthenticationProperties%3daCx5ptREwhUgqNyOyt2dcP22_FiQ3QwwI3RSlHH3WEDH-DC4odtRR3lUglX5ODFx9jRiRyRLqpArBjWLYCzYdeqi3wGQWWNrtzHPa7w0BV4plng0iCUqWcn07-XrNOqF&nonce=636595636959171873.OTA4MDY2NDItNGFhNC00Yjk3LWI5NDQtNzM3MTRiMmFiMjA3OTk5MDcxMTktMTg4OC00YWYyLTkyYTEtYTBkODJmZTA2MTZl&redirect_uri=https%3a%2f%2fwww.office.com%2f&ui_locales=en-US&mkt=en-US&client-request-id=92b06f50-fb93-41bb-9959-15a7d89d2f03")
Sleep(5000); waits 5 seconds
Send('[email protected]'); sends keys
Send('{ENTER}'); simulates enter key

Edited by Carm01
Posted (edited)

Nice to see someone else who dabbles with AutoIT here. :D

 

This code should work with AutoIT to make a complied EXE, but might want to change the domain name and test first. ;)

 

; Don't display an icon in the System Tray, otherwise people can click it to pause or end the script.
#NoTrayIcon

; Set the E-mail Domain.
$Domain = "domain.com"

; Open Microsoft Edge at Outlook 365 signin page.
Run(@ComSpec & " /c " & 'start microsoft-edge:https://outlook.office.com/owa/?realm=' & $Domain, "", @SW_HIDE)

; Set Window Title Matching Mode for String within String.
AutoItSetOption("WinTitleMatchMode",2)

; Wait until a window with Microsoft Edge in the title has loaded and is the active Window.
WinWaitActive("Microsoft Edge")

; Wait 3 seconds for page to load.
Sleep(3000)

; Type the logged on user's username, the @ symbol and e-mail domain name.
Send(@UserName & '@' & $Domain)

Edited by DJ-1701
Posted

Testing this the implementation of the following:

WinWaitActive("Microsoft Edge") and AutoItSetOption("WinTitleMatchMode",2) are not entirely correct. In theory they should work, however, one has the ability to add the 3 second delay into WinWaitActivate function as shown here:

WinWaitActive('Microsoft Edge', "", 3)

 

If I place that 3 second delay in , it does not function as desired, hence the Sleep(3000) has to be placed in there to correctly function.

 

 

The following below is correct implementation as you have to use regular expressions to get it to work, thus you eliminate the sleep(3000)

WinWaitActive('.*Microsoft Edge', "", 3)

 

So below is the correct implementation if you want to use:

AutoItSetOption("WinTitleMatchMode",2) you must do the proper pattern matching.

You could also eliminate the AutoITsetoption all together and just do a

 WinWaitActive("[REGEXPTITLE:(?i)(.*'Microsoft Edge')]", "", 3) 

 

Below is the revised code:

 


; Don't display an icon in the System Tray, otherwise people can click it to pause or end the script.
#NoTrayIcon

; Set the E-mail Domain.
$Domain = "domain.com"

; Open Microsoft Edge at Outlook 365 signin page.
Run(@ComSpec & " /c " & 'start microsoft-edge:https://outlook.office.com/owa/?realm=' & $Domain, "", @SW_HIDE)


; Set Window Title Matching Mode for String within String.
AutoItSetOption("WinTitleMatchMode",2)

; Wait until a window with Microsoft Edge in the title has loaded and is the active Window.
WinWaitActive('.*Microsoft Edge', "", 3)

; Type the logged on user's username, the @ symbol and e-mail domain name.
Send(@UserName & '@' & $Domain)

Posted (edited)
Testing this the implementation of the following:

WinWaitActive("Microsoft Edge") and AutoItSetOption("WinTitleMatchMode",2) are not entirely correct. In theory they should work, however, one has the ability to add the 3 second delay into WinWaitActivate function as shown here:

WinWaitActive('Microsoft Edge', "", 3)

 

If I place that 3 second delay in , it does not function as desired, hence the Sleep(3000) has to be placed in there to correctly function.

 

The following below is correct implementation as you have to use regular expressions to get it to work, thus you eliminate the sleep(3000)

WinWaitActive('.*Microsoft Edge', "", 3)

 

The section of WinWaitActive where you have placed the 3 is the timeout to check if the Window Exists, if the Window is detected before the 3 seconds are up it will immediately jump to the next command, if it does not it will just continue with the command after the 3 seconds. Using WinWaitActive the way I did with no time out, will keep it waiting until the Window loads, so if the machine is being very slow for some reason, it won't jump too far ahead of itself. :)

 

So below is the correct implementation if you want to use:

AutoItSetOption("WinTitleMatchMode",2) you must do the proper pattern matching.

You could also eliminate the AutoITsetoption all together and just do a

 WinWaitActive("[REGEXPTITLE:(?i)(.*'Microsoft Edge')]", "", 3) 

 

Both of the solutions are correct ;), I used to do it my way as it was clearer (at least to me ;)). Though you don't actually need the AutoItSetOption("WinTitleMatchMode",2) if you use the pattern matching expression.

Edited by DJ-1701
Posted
It might wait until the window title appears but as far as web page loading it does not wait so if the page does not fully load it will go as soon as it sees the window title. there is no way to detect that using winwaitactivate unless you use a custom UDF ( https://www.autoitscript.com/forum/topic/14380-how-do-i-wait-for-browser-items-to-appear/ ). There are some UDFs for Firefox and IE that might wait until the page loads but I have not dove into those. WinWaitActivate only looks at the window title not for a page to fully load.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...