Using an exe and password within PS

Welcome Forums General PowerShell Q&A Using an exe and password within PS

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
6 months, 2 weeks ago.

  • Author
    Posts
  • #97906

    Participant
    Points: 0
    Rank: Member

    Hello everyone,

    I'd like some help from the community. My first experience with Powershell was about 3 months ago and I'm green behind the ears so please be gentle.

    We have a product at work that needs to be removed from several systems. This script will require using an encrypted password that will be passed along to an exe that I'm attempting to run within the script. I'll be using Landesk to push the files to local machines.

    
    
    # Self-elevate the script if required
    if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {  if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
      $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
      Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
      Exit
     }
    }
    
    
    # Pull encrypted password from file
    $cred = Get-content "C:\Program Files (x86)\LANDesk\LDClient\sdmcache\ldapps\company\password.txt" | ConvertTo-SecureString -Key (1..16)
    $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($cred)
    $PlainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
    
    # Launch uninstaller
    Start-Process -Filepath "C:\Program Files (x86)\LANDesk\LDClient\sdmcache\ldapps\company\removal.exe" UNINSTALL_PASSWORD=$PlainPassword 
    
    

    When I launch the script a pop up occurs called "Interactive Services Detection" with two options. 1. View Message and 2. Ask me later. When I click on view message I'm prompted with a message from the software I'm trying to remove. As you can imagine that is not the work flow I'd like my users to see. What I would to see is nothing at all except for the application to be removed.

    What am I missing?

    Thanks in advance and let me know if anyone needs more info.

  • #97923

    Participant
    Points: 0
    Rank: Member

    What does the message say, if you click "View message"?

    • #97966

      Participant
      Points: 0
      Rank: Member

      Great question. I'm brought into what I can only call an instance of Windows with the pop up that is asking if I want to continue with the removal of software. It's the same message I would see if I ran the exe on it's own.

      Edit : I added -WindowStyle hidden to the last line and that has stopped the Window with the pop up. Now just the pop up appears and the password is still not being passed.

      # Launch uninstaller
      Start-Process WindowsStyle hidden -Filepath "C:\Program Files (x86)\LANDesk\LDClient\sdmcache\ldapps\company\removal.exe" UNINSTALL_PASSWORD=$PlainPassword 
      

      Any help is appreciated.

The topic ‘Using an exe and password within PS’ is closed to new replies.