Results 1 to 6 of 6

Thread: Load User Profile

  1. #1
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default Load User Profile

    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+

  2. #2

  3. #3
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,603

    Default

    I see no arguments passed to cmd, so I really don't understand why would you wait for cmd to close. It's like starting cmd and not doing anything with it. Makes no sense m8.

  4. #4
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    That's because if I pass arguments to cmd to close it, it doesn't do anything. Even if I echo something, it won't close afterwards.
    I tried passing arguments "/k exit" or "/k then timeout for 10 seconds then exit" still nothing.
    I'll play with the concept a bit more today and see what I can figure out.

    Thanks

  5. #5
    Developer RyBack's Avatar
    Join Date
    Apr 2014
    Location
    In Front of the screen
    Posts
    1,603

    Default

    Try start command

  6. #6
    Administrator James's Avatar
    Join Date
    May 2010
    Location
    on the intraweb
    Posts
    3,180

    Default

    OMG, figured it out!!!! It was right under my nose the entire time. It was just a switch in the start-process function I needed to add. :P

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •