Does anyone know any way to programmatically load a user profile that you specify?
I'm doing this in Powershell, but maybe if there is a way to do it in another language a similar concept can be used in powershell as well.
So far all I found to work is using ProcessStartInfo()
https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
$processStartInfo = New-Object System.Diagnostics.ProcessStartInfo
$processStartInfo.CreateNoWindow = $true
$processStartInfo.UserName = "James"
$processStartInfo.Domain = "Blah.com"
$processStartInfo.Password = "mySecureP4ssw0rd"
$processStartInfo.FileName = "cmd"
$processStartInfo.Arguments = ""
$processStartInfo.LoadUserProfile = $true
$processStartInfo.UseShellExecute = $false
$processStartInfo.RedirectStandardOutput = $true
$processStartInfo.Start()
$reader = New-Object System.IO.StreamReader -ArgumentList $processStartInfo.StandardOutput
$result = $reader.ReadToEnd();
if (!$processStartInfo.HasExited)
{
$processStartInfo.Kill();
}
$reader.Close();
$processStartInfo.Close();
The issue with the code above is when I use cmd to execute the process I can't figure out how to hide the window and then close it out after it's done. I tried using ($processStartInfo.windowstyle = "hidden"), but it doesn't seem to work.
The code after $reader closes out the process, but it closes it before it finishes loading the profile. When I take that chunk of code out, then it loads the profile fine, but then the cmd windw that comes up never closes out. I have to terminate it through TaskMgr.
Any suggestions?
EDIT:
Issue is fixed, but I'm posting some threads (mostly for me to get back to if I ever need to)
https://community.spiceworks.com/top...-without-logon
https://www.sapien.com/forums/viewtopic.php?t=9641
https://blog.codinghorror.com/proces...impersonation/
https://weblogs.asp.net/ralfw/39479
http://dotbay.blogspot.com/2009/05/l...le-from-c.html
https://forums.asp.net/t/1282017.asp...Process+Start+