Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 删除windows ce上的执行文件_C#_.net_Compact Framework_Windows Ce - Fatal编程技术网

C# 删除windows ce上的执行文件

C# 删除windows ce上的执行文件,c#,.net,compact-framework,windows-ce,C#,.net,Compact Framework,Windows Ce,我想在windows ce上创建一个卸载程序 问题是我想在执行所有其他操作后删除卸载程序本身 这有可能吗?或者有什么方法可以用另一种方式制作单面飞碟?killer.cmd: :a del uninstaller.exe if exist uninstaller.exe goto a del killer.cmd 在退出卸载程序之前启动它,以便尽快删除uninstaller.exe,然后也会删除killer.cmd //但是,不确定CE中是否有.cmds。您可以让应用程序自行移动到回收站。这是一

我想在windows ce上创建一个卸载程序

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

这有可能吗?或者有什么方法可以用另一种方式制作单面飞碟?

killer.cmd:

:a
del uninstaller.exe
if exist uninstaller.exe goto a
del killer.cmd
在退出卸载程序之前启动它,以便尽快删除
uninstaller.exe
,然后也会删除
killer.cmd


//但是,不确定CE中是否有.cmds。

您可以让应用程序自行移动到回收站。这是一种痛苦,因为您必须使用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);

来吧,有人相信我的回答!我实际上在我们的windows CE.Sry安装程序中使用了它,但它在我的项目中不起作用。。。