Executing old tools (cmd.exe)

Welcome Forums General PowerShell Q&A Executing old tools (cmd.exe)

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

11 months ago.

  • Author
  • #96975

    Points: 0
    Rank: Member

    Hi Folks,

    So, I am running into a problem where I can't seem to run the command without getting the following error message. Can someone give me some pointers as to what I am doing wrong? I am pulling the uninstall command from the registry and sending that information into a the variable $UninstallCMDfor the installed application and appending "/qn /norestart". When I do this, I get the error message below.

    Command= cmd.exe /c ($UninstallCMD) /qn /norestart

    '/qn' is not recognized as an internal or external command, operable program or batch file.

    Thanks for any pointers I may receive.

  • #96986

    Points: 727
    Helping Hand
    Rank: Major Contributor

    It depends pretty much on the uninstall string you get from the registry and how you try to execute it.
    BTW: Whatfor cmd? Powershell is a command line shell and is able to run either internal and external commands or tools. No need to start another command line shell from the current command line shell. 😉

  • #97005

    Points: 67
    Rank: Member

    You can use the example below and see if that works. If you put the '–%' after the external command Powershell will not try to parse any of it.

    c:\windows\system32\sc.exe –% qc bits

    Whatever switches or values you would use for that command in the command prompt just add after the two dashes and percent.

  • #97022

    Points: 398
    Helping Hand
    Rank: Contributor

    Generally speaking, as we cannot see what the actual uninstall variable string is, I would recommend you alter your syntax and make use of Start-Process:

    Start-Process -FilePath "cmd.exe" -ArgumentList '/c $UninstallCMD', '/qn' '/norestart'

    However, given that from this syntax you can guess that $UninstallCMD is just a standard CMD command, you need not actually invoke cmd.exe to do this. Split your uninstall string into the executable being invoked (I'm guessing probably msiexec.exe?) and the arguments, and do it like this:

    Start-Process -FilePath "msiexec.exe" -ArgumentList $Arguments, '/qn', '/norestart'

The topic ‘Executing old tools (cmd.exe)’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort