Jump to content

Recommended Posts

I have an application that due to strange architecture will NOT uninstall as the system account.  As such, I have to pass credentials in order to uninstall it.  The commands I am trying run to accomplish this do not generate any errors, but they're not actually completing successfully.

The $XUser and $XPass are defined as Local variables inside my function and are the username and password for a local admin account.  I have tried these variants on the command with no success:

RunAsWait($XUser, @ComputerName, $XPass, $RUN_LOGON_NOPROFILE, "MsiExec.exe /x {DB7DE612-0D4F-49B5-B6B3-A42340856F7D} /qn")
RunAsWait($XUser, @ComputerName, $XPass, $RUN_LOGON_NOPROFILE, @ComSpec & " /k " & "MsiExec.exe /x {DB7DE612-0D4F-49B5-B6B3-A42340856F7D} /qn")

Simply calling "MsiExec.exe /x {DB7DE612-0D4F-49B5-B6B3-A42340856F7D} /qn" from a command prompt removes the software, so I know that command and GUID are correct.

Any help would be greatly appreciated.

 

Share this post


Link to post
Share on other sites

Have tried a number of iterations of this with still no success.  Per another thread tried encapsulating the uninstall command into a variable to make it more intuitive with RunAsWait, but still no success.  Again, the code generates no errors but fails to work.

Version 1: This opens the command prompts, but doesn't seem to actually even try to run the msiexec commands:
 

Local $XPass = "password"
Local $XUser = "username" 
Local $rProg = @ComSpec & ' /k "MsiExec.exe /x {GUID} /qn"'
Local $aProg = @ComSpec & " /k " & @ScriptDir & "\program.msi /qn" 

RunAsWait($XUser, @ComputerName, $XPass, $RUN_LOGON_NOPROFILE, $rProg) 
Sleep (2000) 
RunAsWait($XUser, @ComputerName, $XPass, $RUN_LOGON_NOPROFILE, $aProg) 
Sleep (5000)

Version 2:  This seems to do literally nothing.  Just completes with no feedback and no system changes.
 

Local $XPass = "password" 
Local $XUser = "username" 
Local $rProg = "MsiExec.exe /x {GUID} /qn" 
Local $aProg = @ScriptDir & "\program.msi /qn" 

RunAsWait($XUser, @ComputerName, $XPass, $RUN_LOGON_NOPROFILE, $rProg) 
Sleep (2000) 
RunAsWait($XUser, @ComputerName, $XPass, $RUN_LOGON_NOPROFILE, $aProg) 
Sleep (5000)

I've stared at my syntax so long it's starting to look wrong, even the parts I know are right.  Any help from fresh eyes will be greatly appreciated.

Share this post


Link to post
Share on other sites

Will try, it's a local account though.  And if the creds were the problem, wouldn't it not be launching the command prompt at all?

 

**EDIT - Yep, that at least caused a clear failure.  Reverted.  Thank you for the suggestion though.

Edited by vyperhand

Share this post


Link to post
Share on other sites

That's correct.  The uninstall works as local admin, domain user with local admin rights, etc.  I can psexec to a target box with these creds and run the uninstall successfully.  I feel like I have to be making a syntax error around how I'm passing the msiexec string, because even when I leave the command prompt open to debug (that's what the /k is for), it just leaves a blank command prompt.  No sign it even tried to run the msiexec portion at all.

Share this post


Link to post
Share on other sites

RunAsWait and RunAs does not give the Admin Token, and will not run a process with full admin rights.  It will only run the process under the context of the user with limited rights, even if they are an admin.  There are workarounds on the forum, depending on how you want to do it.  

 

Adam

 

Share this post


Link to post
Share on other sites

The overall script is using the #RequireAdmin element.  Again, the command prompt is launching, and in the correct user context.  It just sits there blank, and the command that's supposed to be running afterwards does not even try.

Share this post


Link to post
Share on other sites

have you tried all the different options, I think you want something like $RUN_LOGON_INHERIT (4)

    $RUN_LOGON_NOPROFILE (0) - Interactive logon with no profile.
    $RUN_LOGON_PROFILE (1) - Interactive logon with profile.
    $RUN_LOGON_NETWORK (2) - Network credentials only.
    $RUN_LOGON_INHERIT (4) - Inherit the calling process's environment instead of the user's environment.

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites

Haven't tried that.  Trying it now, will advise.

**EDIT - Same result.  Command prompt open and empty.  No sign of the msiexec command.

Edited by vyperhand

Share this post


Link to post
Share on other sites

I would love to, but because it's a custom app with some protected data in it, I can't.  However, if you can get *any* msi-based uninstall to work via the method I'm trying to use, I should be able to use that code.  The requirements are:

Must use RunAs or RunAsWait (That's the whole reason I'm using AutoIT for this effort, to prevent the passing of credentials "in the clear" by our management software)

Must uninstall via msiexec /x or wmic

This project started life as a simple batch file until I discovered that the product simply would not uninstall when the commands were run as SYSTEM.   The batch still runs perfectly under literally any other admin credentials.

==

:: Remove Existing Credential Provider
MsiExec.exe /x {DB7DE612-0D4F-49B5-B6B3-A42340856F7D} /qn

PING 1.1.1.1 -n 1 -w 5000 > NUL

::Install New Version
%~dp0program.msi /qn

Share this post


Link to post
Share on other sites

Where is the location of the MSI?  It may be in a directory that the RunAs user does not have permissions to access.  Check the permissions, and make sure the user has access to the file.  

 

Adam

 

Share this post


Link to post
Share on other sites
34 minutes ago, AdamUL said:

Where is the location of the MSI?  It may be in a directory that the RunAs user does not have permissions to access.  Check the permissions, and make sure the user has access to the file.  

 

Adam

 

Good idea - location's good.  Same results from several locations actually.  Also, please keep in mind that the script is never making it to the install element - the problem is at the uninstall right at the beginning.

 

22 minutes ago, Jos said:

Also remember you likely run the autoit3 script in x86 mode and the cmd in x64.

Jos

Could you explain that a bit further?  That's at least new info. To elaborate, I'm using the SciTE editor for AutoIT, and I'm using the Tools > Test Run function right now for testing.

Edited by vyperhand
additional information.

Share this post


Link to post
Share on other sites

Good point Jos.  I totally forgot about that.  Have a look at Running under Windows 64-bit Edition in the Help File.  Try adding the following to the the top of your script. 

#include <WinAPIFiles.au3>
;Disable x86 redirection mechanism for a 32-bit script.
If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False)

 

Adam

 

Share this post


Link to post
Share on other sites

OK, That changed the behavior at least - now, I briefly get a command prompt that shows the MSI command in the title bar, but I see no output in the command window.  The software is still not uninstalled.

Dug in a bit, and I'm starting to think it's a problem with the test run feature in SciTE now.  This version at least generated a message in the event log, however that message makes little sense.  The MSI call says it couldn't access the network profile for the logged-in user... which it has no reason to be doing.  Going to compile and move it to a different sandbox for further testing.

This is the full (sanitized) version of the code now.

 

#include <AutoItConstants.au3>
#include <WinAPIFiles.au3>
#RequireAdmin

;Disable x86 redirection mechanism for a 32-bit script.
If @OSArch = "X64" And Not @AutoItX64 Then _WinAPI_Wow64EnableWow64FsRedirection(False)

FileInstall("C:\My Files\Projects\Avatier Upgrade\Product.msi", @ScriptDir & "\Product.msi")
Sleep (5000)
RipRep()

Func RipRep()

    Local $XPass = "password"
    Local $XUser = "user"
    Local $rProg = @ComSpec & ' /k "MsiExec.exe /x {DB7DE612-0D4F-49B5-B6B3-A42340856F7D} /qn"'
    Local $aProg = @ComSpec & " /k " & @ScriptDir & "\Product.msi /qn"

    RunAsWait($XUser, @ComputerName, $XPass, 2, $rProg)
    Sleep (2000)
    RunAsWait($XUser, @ComputerName, $XPass, 2, $aProg)
    Sleep (5000)

EndFunc

Exit

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By bmy007ro
      I have this psexec command working fine 
      Local $sMachine = InputBox("Input PC name", "Enter Computer Name")
      psexec \\$sMachine -u $sDomain\$sUserName -p $sPassword  \\NetworkFLD\FILENAME.cmd > C:\Temp\TT\My.log
       
      I wanted to converted to AutoIT script
      Cloud you help, please !?
       
    • By ahmet
      Hello,
      I am trying to make a program that will uninstall some software, provided by some form of a list. I have this
      ; Generated by AutoIt Scriptomatic June 08, 2010 ;#RequireAdmin $sPartialName="java" $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" ;$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") ;$objWMIService=ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2") $objWMIService=ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Product", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems If StringInStr($objItem.Name,$sPartialName)=1 Then ConsoleWrite("Full name:" & $objItem.Name & @CRLF) RunAs("USERNAME",@ComputerName,"PASSWORD",0,@ComSpec & " /c" & ' wmic product where name="Java 9.0.4 (64-bit)" call uninstall /nointeractive',"C:\WINDOWS\system32\wbem",@SW_MAXIMIZE) ;Run('wmic product where name="Java 9.0.4 (64-bit)" call uninstall /nointeractive',"",@SW_MAXIMIZE) ExitLoop EndIf Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_Product" ) Endif The script above fails uninstalling software despite providing username and password for admin account. If I run script with admin rights then the software gets uninstalled.
      At the following link there is a script by JLogan3o13 but it does not either uninstall software, unless run as admin..
      Is there some way to uninstall software using wim or wimc by providing user name and password?
       
    • By nitron
      Hy to all, 
      I am really Sorry to come up with this question but i can't seem to solve the Problem.
      Its quite easy, I have been using RegNumKey for Years, but i seemed to lose track of something.
      For $ZaehlerLocal = 1 to 1200
            $RegKey = RegEnumKey("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall", $ZaehlerLocal)
            If @error <> 0 then ExitLoop
            $RegKey2=RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\"&$RegKey,"DisplayName")
            $RegKey3=RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\"&$RegKey,"UninstallString")
            $RegKey4=RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\"&$RegKey,"QuietUninstallString")

            if StringInStr($RegKey,"_Office15")==0 and StringInStr($RegKey2,"(German) 2013")==0 and StringInStr($RegKey,".KB")==0 and StringInStr($RegKey2,"Security update")==0 and StringInStr($RegKey2,"Framework")==0 Then
              FileWrite($FileHandleLocal,$RegKey&";")
              FileWrite($FileHandleLocal,$RegKey2&";")
              FileWrite($FileHandleLocal,$RegKey3&";")
              FileWriteline($FileHandleLocal,$RegKey4&";")
           EndIf
         Next
       
      Ive been using this to get all uninstall Strings from the Registry but for some reason, this doesn't work anymore. 
      I get some keys but not all, nore does it start with the first registry.
      As you can see in the picture, the Registry starts with {13DA9C7C-EBFB-40D0-94A1-55B42883DF21}
      but RegNumKey starts with Adressbook.
      Any Ideas what I am doing wrong? I tried HKLM64 instead as well, but with same result.
      Again sorry to bother, but i can't Find the mistake.
       

    • By careca
      I didn't see anything like this, so i figured i created it.
      The objective is to uninstall an application by right mouse clicking it's shortcut, and then selecting the uninstall in context menu.
      To make this work you simply run the exe to set the registry/context menu. To remove the context menu entry, run it again.
      That's it, it will only be called when there's a right mouse click in a shortcut file and the entry is pressed.
      Then it will search the registry for the path of the application and start the uninstall exe from respective application.
      From then on, the user has to go through the uninstaller process for that application.
      Any problem let me know.
    • By 31290
      Hello everyone, 
      I'm working on a WMIC uninstaller. A quite simple one with a button to display product names in a editable list (for copy/paste purposes) but the main problem is that in order to achieve this, in my corporation, normal users cannot uninstall softs.
      What I found/adapt so far:
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("wmic uninstaller", 300, 152, 337, 380) $Label1 = GUICtrlCreateLabel("Computername", 0, 8, 75, 17) $Input1 = GUICtrlCreateInput(@ComputerName, 0, 32, 125, 21) $Label2 = GUICtrlCreateLabel("wmic command", 150, 8, 77, 17) $Combo1 = GUICtrlCreateCombo("Model_Computer", 150, 32, 125, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "Current_user|Installed_Apps|Serial_Number|Bios_Version") $Button1 = GUICtrlCreateButton("List Apps", 150, 72, 91, 49) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit case $button1 $wmi = GUICtrlRead($combo1) $pc = GUICtrlRead($input1) call($wmi,$pc) EndSwitch WEnd Func Model_Computer($pc) RunWait(@ComSpec & ' /c ' & 'wmic /node:' & $pc &' product get name > %temp%\apps.txt' ,"", @SW_HIDE) $file=(@TempDir & "/apps.txt") $fileread= FileRead($file) MsgBox(0, $pc , $fileread) FileDelete(@TempDir & "/apps.txt") EndFunc Here's the textual version I gave to my techs:
      Create cmd shortcut on Desktop, run it as a different user (using their own admin accounts). Once opened, type wmic Once wmic loaded, type product get name Wait for the list of installed soft to display Type product where name="Exact App name" call uninstall Type "Y" to confirm Wait for task execution Don't care about exit code App is uninstalled (verified by getting the list again)! In fact, I'd like to automatize this process.
      Any ideas over here?
      Thanks ^^
×
×
  • Create New...