running .exe as admin with username and password

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Tony Antony Tony Antony 1 month ago.

  • Author
    Posts
  • #56648
    Profile photo of Tony Antony
    Tony Antony
    Participant

    Hello,

    $server = $env:mfdrives
    
    $apps = "\\$server\Apps\"
    
    Start-Process $apps\faxUploadSetup.exe

    When I run this, it opens the faxupload.exe software, which is good, but if I try to install it, it will ask for admin credentials. How would I store the admin usename and password in the script so that when a user runs it, it won't ask them?

    Thank you,

    Tony

  • #56659
    Profile photo of Sonny Puijk
    Sonny Puijk
    Participant
    $Username = "administrator"
    $Password = "ThisIsThePassword"
    $Credentials = New-Object PSCredential($UserName,$(ConvertTo-SecureString -AsPlainText -String $Password -Force))
    
    $server = $env:mfdrives
    $apps = "\\$server\Apps\"
    
    Start-Process $apps\faxUploadSetup.exe -Credential $Credentials
    

    You can obfuscate the credentials using base64 encoding or something else. I still haven't found of a foolproof way of providing admin credentials to scripts like this. They're always stored somewhere.

  • #56675
    Profile photo of Paal Braathen
    Paal Braathen
    Participant

    I haven't been able to try it myself yet, but I'd look into the credential manager rather than saving the password as plaintext.

    This module might assist you:

    https://www.powershellgallery.com/packages/CredentialManager/

  • #56678
    Profile photo of Tony Antony
    Tony Antony
    Participant

    Thank you all,
    I'll try that

  • #56681
    Profile photo of Tony Antony
    Tony Antony
    Participant

    Now it says

    Start-Process : This command cannot be run due to the error: Logon failure: unknown user name or bad password.

    I verified that the username and passwords are correct.

You must be logged in to reply to this topic.