I am writing a solution for users to open a file, and this file should navigate to a certain website and insert the user's username into the login form for them. This file needs to be accessed by users which are on a citrix session.
This should be extremely simple, and I have discovered a way of doing it via Powershell :
$aduser = Get-ADUser $env:USERNAME -Properties EmailAddress
$emailaddress = $aduser.EmailAddress
$url = "https://website.org/loginpage.asp"
$ie = New-Object -comobject "InternetExplorer.Application"
$ie.visible = $true
$ie.Navigate($url)
WaitForPage 10
$ie.Document.GetElementById("USERID").Value = $emailaddress
This works perfectly - it opens the web page, and inserts the username (email address).
However, when a user runs this from their machine, it seems impossible to hide either the CMD window (if running from .cmd
or .bat
) as well as the Powershell window. -WindowStyle Hidden
just reduced the length of time the window appears for - which is not an acceptable solution.
So my next plan of action was to recreate the above code in c# and distribute it as an exe (as this is unlikely to show any console windows). However, I can't seem to find any method of doing this in C# which does not depend on external libraries (e.g. Selenium, which also requires a driver to be installed which is not a valid option for me).
I guess my question is - can the above Powershell script be recreated in C#? Is the -comobject
from that script a .NET object, and if so how can I harness that in C#?
For reference - I am currently calling the .ps1
file as follows (in a CMD file) :
START Powershell.exe -WindowStyle Hidden -File \\file\Folder\SK\scripts\powershell\opensite.ps1
And I have not found any way of actually hiding the console windows which appear. I either need to find a solution to this, or a simple way of implementing the same thing in C#.