删除windows ce上的执行文件

发布于 2024-12-08 12:39:44 字数 102 浏览 1 评论 0原文

我想在 windows ce 上制作一个卸载程序。

问题是我想在执行其他所有操作后删除卸载程序本身。

这有可能吗?或者有什么办法可以用另一种方式制作卸载程序?

i want to make a uninstaller on windows ce.

The Problem is I want to delete the uninstaller itself after executed everything else.

Is this possible somehow? Or is there someway to make a unistaller in another way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拥醉 2024-12-15 12:39:44

您只需让应用程序将其自身移动到回收站即可。这很痛苦,因为您必须通过 P/Invoke 来使用不直观的结构来完成此操作。这个样本应该对此有所帮助。

        private bool Recycle(string path)
    {
        try
        {
            ShowProgress(string.Format("Moving {0} to Recycle bin.", path));
            SHFILEOPSTRUCT sfo = new SHFILEOPSTRUCT();
            sfo.hwnd = IntPtr.Zero;
            sfo.wFunc = FO_DELETE;
            sfo.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
            sfo.pFrom = path +'\0' + '\0';
            sfo.pTo = null;
            sfo.fAnyOperationsAborted = false;
            sfo.hNameMappings = IntPtr.Zero;
            sfo.lpszProgressTitle = string.Empty;
            int ret = SHFileOperation(ref sfo);

            return (ret == 0);
        }
        catch (Exception ex)
        {
            ShowProgress(string.Format("Failed to move {0} to Recycle bin.", path));
            ShowProgress(ex.ToString());
        }
        return false;
    }


    // SHFileOperation wFunc and wFunc values
    public const uint FO_MOVE = 0x0001;
    public const uint FO_COPY = 0x0002;
    public const uint FO_DELETE = 0x0003;
    public const uint FO_RENAME = 0x0004;

    public const ushort FOF_MULTIDESTFILES = 0x0001;
    public const ushort FOF_CONFIRMMOUSE = 0x0002;
    public const ushort FOF_SILENT = 0x0004; // don't create progress/report
    public const ushort FOF_RENAMEONCOLLISION = 0x0008;
    public const ushort FOF_NOCONFIRMATION = 0x0010; // Don't prompt the user.
    public const ushort FOF_WANTMAPPINGHANDLE = 0x0020;// Fill in SHFILEOPSTRUCT.hNameMappings
                                                    // Must be freed using SHFreeNameMappings
    public const ushort FOF_ALLOWUNDO = 0x0040;
    public const ushort FOF_FILESONLY = 0x0080;  // on *.*, do only files
    public const ushort FOF_SIMPLEPROGRESS = 0x0100;  // means don't show names of files
    public const ushort FOF_NOCONFIRMMKDIR = 0x0200;  // don't confirm making any needed dirs
    public const ushort FOF_NOERRORUI = 0x0400;  // don't put up error UI
    public const ushort FOF_NOCOPYSECURITYATTRIBS = 0x0800;  // dont copy NT file Security Attributes
    public const ushort FOF_NORECURSION = 0x1000;  // don't recurse ushorto directories.

    //[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
    //If you use the above you may encounter an invalid memory access exception (when using ANSI
    //or see nothing (when using unicode) when you use FOF_SIMPLEPROGRESS flag.
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public struct SHFILEOPSTRUCT
    {
        public IntPtr hwnd;
        public uint wFunc;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string pFrom;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string pTo;
        public ushort fFlags;
        [MarshalAs(UnmanagedType.Bool)]
        public bool fAnyOperationsAborted;
        public IntPtr hNameMappings;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string lpszProgressTitle;
    }

    [DllImport("ceshell.dll")]
    public static extern int SHFileOperation([In] ref SHFILEOPSTRUCT lpFileOp);

You can just have the app move itself to the recycle bin. It's a pain because you have to P/Invoke to do this with an unintuative structure. This swatch should help with that.

        private bool Recycle(string path)
    {
        try
        {
            ShowProgress(string.Format("Moving {0} to Recycle bin.", path));
            SHFILEOPSTRUCT sfo = new SHFILEOPSTRUCT();
            sfo.hwnd = IntPtr.Zero;
            sfo.wFunc = FO_DELETE;
            sfo.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
            sfo.pFrom = path +'\0' + '\0';
            sfo.pTo = null;
            sfo.fAnyOperationsAborted = false;
            sfo.hNameMappings = IntPtr.Zero;
            sfo.lpszProgressTitle = string.Empty;
            int ret = SHFileOperation(ref sfo);

            return (ret == 0);
        }
        catch (Exception ex)
        {
            ShowProgress(string.Format("Failed to move {0} to Recycle bin.", path));
            ShowProgress(ex.ToString());
        }
        return false;
    }


    // SHFileOperation wFunc and wFunc values
    public const uint FO_MOVE = 0x0001;
    public const uint FO_COPY = 0x0002;
    public const uint FO_DELETE = 0x0003;
    public const uint FO_RENAME = 0x0004;

    public const ushort FOF_MULTIDESTFILES = 0x0001;
    public const ushort FOF_CONFIRMMOUSE = 0x0002;
    public const ushort FOF_SILENT = 0x0004; // don't create progress/report
    public const ushort FOF_RENAMEONCOLLISION = 0x0008;
    public const ushort FOF_NOCONFIRMATION = 0x0010; // Don't prompt the user.
    public const ushort FOF_WANTMAPPINGHANDLE = 0x0020;// Fill in SHFILEOPSTRUCT.hNameMappings
                                                    // Must be freed using SHFreeNameMappings
    public const ushort FOF_ALLOWUNDO = 0x0040;
    public const ushort FOF_FILESONLY = 0x0080;  // on *.*, do only files
    public const ushort FOF_SIMPLEPROGRESS = 0x0100;  // means don't show names of files
    public const ushort FOF_NOCONFIRMMKDIR = 0x0200;  // don't confirm making any needed dirs
    public const ushort FOF_NOERRORUI = 0x0400;  // don't put up error UI
    public const ushort FOF_NOCOPYSECURITYATTRIBS = 0x0800;  // dont copy NT file Security Attributes
    public const ushort FOF_NORECURSION = 0x1000;  // don't recurse ushorto directories.

    //[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
    //If you use the above you may encounter an invalid memory access exception (when using ANSI
    //or see nothing (when using unicode) when you use FOF_SIMPLEPROGRESS flag.
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public struct SHFILEOPSTRUCT
    {
        public IntPtr hwnd;
        public uint wFunc;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string pFrom;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string pTo;
        public ushort fFlags;
        [MarshalAs(UnmanagedType.Bool)]
        public bool fAnyOperationsAborted;
        public IntPtr hNameMappings;
        [MarshalAs(UnmanagedType.LPWStr)]
        public string lpszProgressTitle;
    }

    [DllImport("ceshell.dll")]
    public static extern int SHFileOperation([In] ref SHFILEOPSTRUCT lpFileOp);
谜兔 2024-12-15 12:39:44

Killer.cmd:

:a
del uninstaller.exe
if exist uninstaller.exe goto a
del killer.cmd

在退出卸载程序之前启动它,这样 uninstaller.exe 将尽快被删除,然后 killer.cmd 也会被删除。

// 不过,不确定 CE 中是否有 .cmd。

killer.cmd:

:a
del uninstaller.exe
if exist uninstaller.exe goto a
del killer.cmd

Start it before exitting your uninstaller, so uninstaller.exe will be removed as soon as it's possible, and then killer.cmd is also removed.

// Though, not sure if there are .cmds in CE.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文