如何通过不是Microsoft产品的Powershell卸载应用程序

时间:2019-01-30 13:25:13

标签: powershell

我想通过Powershell脚本卸载不是Microsoft产品的应用程序

我尝试使用下面的代码,但是它说“您不能在空值表达式上调用方法”。这是因为它无法指向相应的软件。

import UIKit
import SnapKit

protocol DateFieldDelegate: class {
    func dateSelected(_ dateField: DateField, date: Date)
}

class DateField: UIView, UITextFieldDelegate {

    weak var delegate: DateFieldDelegate?
    let field = UITextField()
    private var datePicker: UIDatePicker?

    convenience init(withStartDate startDate: Date) {
        self.init()

        datePicker = prepareDatePicker()
        guard let datePicker = datePicker else { return }
        field.inputView = datePicker
        field.delegate = self

        addSubview(field)
        field.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.leading.equalToSuperview()
            make.trailing.equalToSuperview()
            make.height.equalTo(37)
            make.bottom.equalToSuperview()
        }

        let fieldIcon = UIImageView(image: UIImage(asset: Asset.calendar))
        field.addSubview(fieldIcon)
        fieldIcon.isUserInteractionEnabled = true  // doesn't work
        fieldIcon.snp.makeConstraints { make in
            make.width.equalTo(21)
            make.height.equalTo(23)
            make.trailing.equalToSuperview().offset(-10)
            make.centerY.equalToSuperview()
        }

        setStyle(.regular)
    }

    func textFieldDidEndEditing(_ textField: UITextField) {
        guard let date = datePicker?.date else { return }
        field.text = date.formatToString()
        delegate?.dateSelected(self, date: date)
    }

    private func prepareDatePicker() -> UIDatePicker {
        let datePicker = UIDatePicker()
        datePicker.datePickerMode = .date
        datePicker.setDate(Date(), animated: false)
        datePicker.locale = Language.appLocale()
        return datePicker
    }
}

当我尝试使用$app = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -like "*Software_Name*" } $app.Uninstall() 命令时,它仅列出了Microsoft软件。

如何卸载其他软件?

1 个答案:

答案 0 :(得分:0)

可能的解决方案是在HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall的注册表中找到应用程序的GUID,然后使用MsiExec卸载它:

Start-Process -FilePath MsiExec -ArgumentList '/quiet /uninstall {109A5A16-E09E-4B82-A784-D1780F1190D6}' -Wait

上面的示例卸载了Windows Firewall Configuration Provider