簡體   English   中英

CreateProcess 和 installshield 的卸載字符串

[英]CreateProcess and installshield's uninstall strings

我正在調用 pInvoke 來調用內核的 CreateProcess() 並將它傳遞給我想卸載的某個應用程序的 UninstallString。 當您嘗試卸載應用程序時,此 UninstallString 與添加/刪除程序執行的操作相同。 對 CreateProcess() 的調用似乎適用於所有 MSI UninstallStrings,例如:

MsiExec.exe /I{88BAE373-00F4-3E33-828F-96E89E5E0CB9}

但不會為 InstallShield UninstallStrings 啟動任何內容,例如: RunDll32 C:\PROGRA~2\COMMON~1\INSTAL~1\PROFES~1\RunTime\10\50\Intel32\Ctor.dll,LaunchSetup文件 (x86)\InstallShield 安裝信息{34B37A74-125E-4406-87BA-E4BD3D097AE5}\setup.exe" -l0x9 -removeonly

我錯過了什么? 如果我在命令行 window 中運行相同的 UninstallString,它會運行並啟動卸載程序。 我嘗試了 ShellExecute() 但似乎也不起作用。 我知道我可以將卸載字符串解析為可執行文件(Rundll32),並將 rest 解析為 arguments 並將它們傳遞給托管進程 class 作為 StartInfo,但我特別想避免使用 InstallShield 字符串運行,特別是因為字符串很好。

有任何想法嗎?

[DllImport("kernel32.dll")] 
public static extern bool CreateProcess(string lpApplicationName, string lpCommandLine,     IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles, uint  dwCreationFlags, IntPtr lpEnvironment,string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);

PROCESS_INFORMATION pi = new ProcessUtils.PROCESS_INFORMATION();
STARTUPINFO si = new ProcessUtils.STARTUPINFO();
CreateProcess(null, path, IntPtr.Zero, IntPtr.Zero, false, 0, IntPtr.Zero, null, ref si, out pi);
int pID = pi.dwProcessId;

   [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public struct STARTUPINFO
    {
        public Int32 cb;
        public string lpReserved;
        public string lpDesktop;
        public string lpTitle;
        public Int32 dwX;
        public Int32 dwY;
        public Int32 dwXSize;
        public Int32 dwYSize;
        public Int32 dwXCountChars;
        public Int32 dwYCountChars;
        public Int32 dwFillAttribute;
        public Int32 dwFlags;
        public Int16 wShowWindow;
        public Int16 cbReserved2;
        public IntPtr lpReserved2;
        public IntPtr hStdInput;
        public IntPtr hStdOutput;
        public IntPtr hStdError;
    }
    [StructLayout(LayoutKind.Sequential)]
    public struct PROCESS_INFORMATION
    {
        public IntPtr hProcess;
        public IntPtr hThread;
        public int dwProcessId;
        public int dwThreadId;
    }

這可能不是您的問題,但創建過程需要將啟動信息結構清零,即 ZeroMemory。 還需要將 cb 參數設置為結構的大小。

我的問題是我通過 c# 命令行參數傳遞了卸載字符串。 但是當卸載字符串包含引號(如 setup.exe "c\program files...")時,編譯器會刪除這些引號。 所以為了解決我的問題,我在用三元組傳遞它們之前替換它們。 str.Replace("\"", "\"\"\"") 就可以了。

謝謝,kj

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM