Ejemplo n.º 1
0
        private bool CreateDesktopIcons(string fileName, string linkName)
        {
            try
            {
                string p = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                string s = this.GetBinFile(fileName);
                IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();

                string linkFilePath = p + "\\" + linkName + ".lnk";
                if (File.Exists(linkFilePath))
                {
                    File.Delete(linkFilePath);
                }
                IWshRuntimeLibrary.WshShortcut shortcut = (IWshRuntimeLibrary.WshShortcut)shell.CreateShortcut(linkFilePath);
                shortcut.TargetPath       = s;
                shortcut.Arguments        = "";
                shortcut.Description      = fileName;
                shortcut.WorkingDirectory = Path.Combine(this.installPath.Text, this.binPath);
                shortcut.IconLocation     = string.Format("{0},0", s);
                shortcut.Save();

                this.AddLog("桌面快捷方式创建成功");
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 复制文件,并创建快捷方式
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CopyThread_DoWork(object sender, DoWorkEventArgs e)
        {
            DirectoryInfo Startup = new DirectoryInfo(Application.StartupPath);

            LabTitle.Text = Startup.Name;
            DirectoryInfo desktop      = new DirectoryInfo(Environment.GetFolderPath((Environment.SpecialFolder.Desktop)));
            String        shortcutPath = Path.Combine(desktop.FullName, Startup.Name + ".lnk");
            String        exePath      = Process.GetCurrentProcess().MainModule.FileName;

            IWshRuntimeLibrary.IWshShell   shell    = new IWshRuntimeLibrary.WshShell();
            IWshRuntimeLibrary.WshShortcut shortcut = (IWshRuntimeLibrary.WshShortcut)shell.CreateShortcut(shortcutPath);
            shortcut.TargetPath       = exePath;
            shortcut.Description      = "应用程序说明";
            shortcut.WorkingDirectory = Environment.CurrentDirectory;
            shortcut.IconLocation     = exePath;
            shortcut.WindowStyle      = 1;
            shortcut.Save();
            BarPross.Maximum = FilesCounter(new DirectoryInfo(Application.StartupPath));
            DeepCopyDirectory(Startup, new DirectoryInfo(Path.Combine("D:\\", Startup.Name)));
            BarPross.Value = BarPross.Maximum;
            if (Startup.Name.ToUpper().Contains("USBBOOT"))
            {
                Process reboot = new Process();
                reboot.StartInfo.FileName = Path.Combine("D:\\", Startup.Name, "run_a0.bat");
                reboot.Start();
            }
            else
            {
                Process reboot = new Process();
                reboot.StartInfo.FileName = Path.Combine("D:\\", Startup.Name, Application.ProductName + ".exe");
                reboot.Start();
            }
            System.Environment.Exit(0);
        }
Ejemplo n.º 3
0
        public static void SearchVM(ref List <VirtualMachine> VMList)
        {
            var RoamingAppdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            var UserProfile    = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            var Version7Folder = Path.Combine(UserProfile, "Virtual Machines");
            var VMFolder       = Path.Combine(RoamingAppdata, @"Microsoft\Virtual PC\Virtual Machines");

            string[] Files;

            //Virtual 2004 2007
            if (Directory.Exists(VMFolder))
            {
                Files = Directory.GetFiles(VMFolder);
                foreach (string lnkFile in Files)
                {
                    if (Path.GetExtension(lnkFile) == ".lnk")
                    {
                        var Shell = new IWshRuntimeLibrary.WshShell();
                        IWshRuntimeLibrary.WshShortcut Shortcut = Shell.CreateShortcut(lnkFile);
                        var Target = Shortcut.TargetPath;

                        if (File.Exists(Target) && (Path.GetExtension(Target) == ".vmc"))
                        {
                            var VM = new VirtualPC_VM(Target);
                            VMList.Add(VM);
                        }
                    }
                }
            }

            //Windows Virtual PC (Version7)
            if (Directory.Exists(Version7Folder))
            {
                Files = Directory.GetFiles(Version7Folder);
                foreach (string vmcx in Files)
                {
                    if (Path.GetExtension(vmcx) == ".vmcx")
                    {
                        var XML    = new VirtualPC_XML(vmcx);
                        var Target = XML.ReadValue(@"vm_description/vmc_path");

                        if (File.Exists(Target) && (Path.GetExtension(Target) == ".vmc"))
                        {
                            var VM = new VirtualPC_VM(Target);
                            VMList.Add(VM);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private bool CreateStartupMenu()
        {
            try
            {
                string p = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
                string s = this.CreateStartupBatFile();
                IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();

                IWshRuntimeLibrary.WshShortcut shortcut = (IWshRuntimeLibrary.WshShortcut)shell.CreateShortcut(p + "\\startup.lnk");
                shortcut.TargetPath       = s;
                shortcut.Arguments        = "";
                shortcut.Description      = "启动";
                shortcut.WorkingDirectory = this.installPath.Text;
                shortcut.IconLocation     = string.Format("{0},0", s);
                shortcut.Save();

                this.AddLog("启动组快捷方式创建成功");
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }