Exemple #1
0
        //保存ボタン押下時の処理
        private void saveButton_Click(object sender, EventArgs e)
        {
            //入力フォームの内容をチェックし、問題がなければショートカットを作成する
            IWshShell shell = new IWshShell_Class();
            String filePath = this.pathTextBox.Text; //ファイルパスを取得

            //実在するパスが入力されているか確認する
            if (System.IO.File.Exists(filePath))
            {
                //ショートカットを作成し、ディレクトリに配置する
                String shortcutName = this.nameTextBox.Text; //入力された名前をを取得
                IWshShortcut_Class shortcut = shell.CreateShortcut(Directory.GetCurrentDirectory() + "\\icon\\" + shortcutName + ".lnk"); //パスを指定し、ショートカットを作成
                shortcut.TargetPath = filePath; //リンク先の設定
                shortcut.Arguments = this.parameterTextBox.Text; //コマンドライン引数の指定
                shortcut.WorkingDirectory = Path.GetDirectoryName(filePath); //作業ディレクトリの指定
                shortcut.IconLocation = filePath; //アイコンの指定
                shortcut.Save(); //ショートカットの保存
                this.Close();
            }
            else
            {
                //filePathのファイルは存在しない
                MessageBox.Show("指定されたファイルは存在しません。入力をやり直して下さい");
            }
        }
Exemple #2
0
        /// <summary>
        /// 创建一个快捷方式
        /// </summary>
        /// <param name="lnkPath">创建的快捷方式完整路径</param>
        /// <param name="targetPath">目标完整路径</param>
        public static void CreateShortcut(string lnkPath, string targetPath)
        {
            IWshShell_Class wshShell = new IWshShell_Class();
            IWshShortcut    shortcut = (IWshShortcut)wshShell.CreateShortcut(lnkPath.Trim());

            shortcut.TargetPath = targetPath.Trim();
            shortcut.Save();
        }
 /// <summary>
 /// 获取快捷方式的真实路径
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 public static string getTarget(string path)
 {
     IWshShortcut _shortcut = null;
     IWshShell_Class shell = new IWshShell_Class();
     if (System.IO.File.Exists(path) == true)
         _shortcut = shell.CreateShortcut(path) as IWshShortcut;//在vs2010中CreateShortcut返回dynamic 类型
     return _shortcut.TargetPath;
 }
Exemple #4
0
 /// <summary>
 /// 获取快捷方式的真实路径
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 public static string GetTarget(string path)
 {
     IWshShortcut _shortcut = null;
     IWshShell_Class shell = new IWshShell_Class();
     if (System.IO.File.Exists(path) == true)
         _shortcut = shell.CreateShortcut(path) as IWshShortcut;//在vs2010中CreateShortcut返回dynamic 类型
     return _shortcut.TargetPath;
 }
Exemple #5
0
        private void ChangeShortcutHotkey()
        {
            IWshShell_Class wshShell = new IWshShell_Class();
            object          tempObj  = wshShell.CreateShortcut(shortcutPath);
            IWshShortcut    shortcut = (IWshShortcut)tempObj;

            shortcut.Hotkey = testBoxHotkey.Text;
            shortcut.Save();
        }
        private static void AddUtilityServiceRunnerToStartup(string utilityServiceRunnerDirectory)
        {
            var wsh = new IWshShell_Class();

            var utilityServiceRunnerShortcut = wsh.CreateShortcut("C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\Launch Utility Service Runner.lnk") as IWshShortcut;

            utilityServiceRunnerShortcut.TargetPath       = Path.Combine(utilityServiceRunnerDirectory, "UtilityServiceRunner.exe");
            utilityServiceRunnerShortcut.WorkingDirectory = utilityServiceRunnerDirectory;
            utilityServiceRunnerShortcut.Save();
        }
Exemple #7
0
 public static void createShortcut()
 {
     var wsh = new IWshShell_Class();
     IWshShortcut shortcut = wsh.CreateShortcut(Util.getToolboxesPath() + Util.tlb.name + ".lnk") as IWshRuntimeLibrary.IWshShortcut;
     shortcut.TargetPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\toolbox.exe";
     shortcut.IconLocation = Util.getToolboxesPath() + Util.tlb.name + "/icon.ico";
     shortcut.Arguments = Util.tlb.name;
     shortcut.WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath);
     shortcut.Save();
 }
Exemple #8
0
 public static IWshURLShortcut getUrlShortcut(string path)
 {
     IWshURLShortcut shortcut = null;
     if (System.IO.File.Exists(path))
     {
         var wsh = new IWshShell_Class();
         shortcut = wsh.CreateShortcut(path);
     }
     return shortcut;
 }
Exemple #9
0
        public static void CreateShortcut(string path, string fileName, string iconPath)
        {
            var          wsh      = new IWshShell_Class();
            IWshShortcut shortcut = wsh.CreateShortcut(string.Format("{0}\\{1}.lnk",
                                                                     Environment.GetFolderPath(Environment.SpecialFolder.Desktop), fileName)) as IWshShortcut;

            shortcut.TargetPath   = path;
            shortcut.IconLocation = iconPath;
            shortcut.Save();
        }
Exemple #10
0
        //  --> https://stackoverflow.com/questions/18023379/creating-a-file-shortcut-lnk
        public override void /*AbstractProgramLogic.*/ PromoteStartup()
        {
            var fileName = this._programInfo.Origin.Location;
            var wsh      = new IWshShell_Class();
            var shortcut = wsh.CreateShortcut(fileName) as IWshShortcut;

            shortcut.TargetPath = this._programInfo.StartInfo.FilePath;
            shortcut.Arguments  = this._programInfo.StartInfo.Arguments;
            shortcut.Save();
        }
Exemple #11
0
        static void Main(string[] args)
        {
            var Folder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
            var wsh    = new IWshShell_Class();

            // Creates a copy of the application handling the startup procedure
            string Startup = Folder + @"\\Itadel-Lock-Shortcut.lnk";

            if (!System.IO.File.Exists(Startup))
            {
                IWshShortcut Shortcut = wsh.CreateShortcut(Startup) as IWshShortcut;
                Shortcut.TargetPath = Assembly.GetExecutingAssembly().Location;
                Shortcut.Save();
            }

            Process[] Itadel = Process.GetProcessesByName("Itadel");
            if (Itadel.Length == 0)
            {
                /* Wait 30000 milliseconds (30seconds) then open the lockscreen
                 * This is used to secure that bootup is able to finish before the screen is locked */
                Thread.Sleep(millisecondsTimeout: 30000);
                // The application settings to open the Lockscreen in case of autostart selected
                ProcessStartInfo itadel = new ProcessStartInfo
                {
                    CreateNoWindow  = false,
                    UseShellExecute = false,
                    FileName        = "Itadel.exe",
                    WindowStyle     = ProcessWindowStyle.Hidden,
                    Arguments       = System.IO.Directory.GetCurrentDirectory() + " " + "-Q",
                };

                try
                {
                    Process.Start(itadel);
                    Thread.Sleep(millisecondsTimeout: 5000);
                    Environment.Exit(1);
                }
                catch
                {
                    Environment.Exit(1);
                }
            }
            else  // If itadel is already open, dont open anything but watch the proccess for exit
            {
                foreach (Process Proc in Itadel)
                {
                    if (Proc.ProcessName == "Itadel")
                    {
                        Proc.WaitForExit();
                        Environment.Exit(0);
                    }
                }
            }
        }
Exemple #12
0
        public static IWshShortcut getShortcut(string path)
        {
            IWshShortcut shortcut = null;

            if (System.IO.File.Exists(path))
            {
                var wsh = new IWshShell_Class();
                shortcut = wsh.CreateShortcut(path);
            }
            return(shortcut);
        }
Exemple #13
0
        public static void createShortcut()
        {
            var          wsh      = new IWshShell_Class();
            IWshShortcut shortcut = wsh.CreateShortcut(Util.getToolboxesPath() + Util.tlb.name + ".lnk") as IWshRuntimeLibrary.IWshShortcut;

            shortcut.TargetPath       = Path.GetDirectoryName(Application.ExecutablePath) + "\\toolbox.exe";
            shortcut.IconLocation     = Util.getToolboxesPath() + Util.tlb.name + "/icon.ico";
            shortcut.Arguments        = Util.tlb.name;
            shortcut.WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath);
            shortcut.Save();
        }
        private static IWshShortcut GetShellLink(string linkFilePath)
        {
            if (!global::System.IO.File.Exists(linkFilePath))
            {
                throw new FileNotFoundException("Tried to create DesktopEntry from non-existent lnk file: " + linkFilePath);
            }

            IWshShell shell     = new IWshShell_Class();
            var       shellLink = (IWshShortcut)shell.CreateShortcut(linkFilePath);

            return(shellLink);
        }
Exemple #15
0
        static void Main(string[] args)
        {
            WshShell shell = new WshShell();
            var      wsh   = new IWshShell_Class();

            int    count      = 1;
            var    sourcePath = "G:\\2.Anime\\pixivutil";
            var    targetPath = "C:\\Users\\mouri\\Downloads\\test\\___";
            Random rnd        = new Random();

            var parentDirectory = new DirectoryInfo(sourcePath);

            foreach (var directory in parentDirectory.EnumerateDirectories())
            {
                if (directory.FullName == targetPath)
                {
                    continue;
                }
                FileInfo[] randomFiles = directory
                                         .GetFiles("*.*", SearchOption.AllDirectories)
                                         .Where(file => !file.Name.Contains("folder"))
                                         .OrderByDescending(x => x.Name)
                                         .Take(20)
                                         .OrderBy(x => rnd.Next())
                                         .Take(count)
                                         .ToArray();

                foreach (FileInfo file in randomFiles)
                {
                    string targetFile = Path.Combine(targetPath, file.Name);
                    //Console.WriteLine("copy " + file.FullName + " -> " + targetFile);
                    //file.CopyTo(targetFile);
                    //IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(targetFile + ".lnk") as IWshRuntimeLibrary.IWshShortcut;
                    //string shortcutAddress = targetFile + @".lnk";
                    //IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
                    //shortcut.TargetPath = file.FullName;
                    //shortcut.Save();

                    var shortcutName = file.Name + ".lnk";
                    // Create empty .lnk file
                    string path = System.IO.Path.Combine(targetPath, shortcutName);
                    System.IO.File.WriteAllBytes(path, new byte[0]);
                    // Create a ShellLinkObject that references the .lnk file
                    Shell32.Shell           shl = new Shell32.Shell();
                    Shell32.Folder          dir = shl.NameSpace(targetPath);
                    Shell32.FolderItem      itm = dir.Items().Item(shortcutName);
                    Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)itm.GetLink;
                    // Set the .lnk file properties
                    lnk.Path = file.FullName;
                    lnk.Save(path);
                }
            }
        }
Exemple #16
0
        public static void place_shortcut_on_desktop()
        {
            string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\YourName.lnk";
            string shortcutto  = System.Reflection.Assembly.GetExecutingAssembly().Location;

            var wsh = new IWshShell_Class();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(desktopPath) as IWshRuntimeLibrary.IWshShortcut;
            shortcut.TargetPath       = shortcutto;
            shortcut.WorkingDirectory = Directory.GetParent(shortcutto).FullName;
            shortcut.Save();
        }
Exemple #17
0
        /// <summary>
        /// Добавление в автозагрзу
        /// </summary>
        /// <param name="FilePath">Путь к запускаемому файлу</param>
        /// <param name="WorkDir">Рабочая директория</param>
        /// <param name="SaveTo">Куда сохранить ярлык</param>
        private void CreateShortCut(string FilePath, string WorkDir, string SaveTo)
        {
            var          WshShell = new IWshShell_Class();
            IWshShortcut MyShortcut;

            MyShortcut = (IWshShortcut)WshShell.CreateShortcut(SaveTo);
            //путь к exe
            MyShortcut.TargetPath  = FilePath;
            MyShortcut.Description = "Запуск";
            //рабочая диреткория
            MyShortcut.WorkingDirectory = WorkDir;
            MyShortcut.Save();
        }
        public void CreateShortcut(string ShortcutDirectory)
        {
            var          wsh      = new IWshShell_Class();
            IWshShortcut shortcut = wsh.CreateShortcut(ShortcutDirectory + "\\Igloo.lnk") as IWshRuntimeLibrary.IWshShortcut;

            shortcut.Arguments  = "";
            shortcut.TargetPath = installer.DefaultDirectory + @"\Igloo Browser.exe";
            // not sure about what this is for
            shortcut.WindowStyle      = 1;
            shortcut.Description      = "A web browser made by MoonByte";
            shortcut.WorkingDirectory = installer.DefaultDirectory;
            shortcut.IconLocation     = installer.DefaultDirectory + @"\icon.ico";
            shortcut.Save();
        }
Exemple #19
0
        public static string Extract(string ico, string shortcutLocation)
        {
            String path = Environment.GetFolderPath(Environment.SpecialFolder.System);

            Console.WriteLine(path);
            // string shortcutLocation = @"C:\Users\Gordan\Zune.lnk";
            string newIconLocation = path + @"\shell32.dll," + ico;

            IWshShell_Class Shell = new IWshShell_Class();
            //   IWshRuntimeLibrary.IWshShell_Class
            WshShortcut cl = (WshShortcut)Shell.CreateShortcut(shortcutLocation);

            cl.IconLocation = newIconLocation;
            cl.Save();
            return("");
        }
Exemple #20
0
        public void CreateConfig(Image groupImage)
        {
            string path     = @"config\" + this.Name;
            string filePath = path + @"\" + this.Name + "Group.exe";

            //
            // Directory and .exe
            //
            System.IO.Directory.CreateDirectory(@"Shortcuts\");
            System.IO.Directory.CreateDirectory(@path);
            System.IO.File.Copy(@"config\config.exe", @filePath);
            //
            // XML config
            //
            System.Xml.Serialization.XmlSerializer writer =
                new System.Xml.Serialization.XmlSerializer(typeof(Category));

            using (FileStream file = System.IO.File.Create(@path + @"\ObjectData.xml"))
                writer.Serialize(file, this);
            //
            // Create .ico
            //

            Image img = ImageFunctions.ResizeImage(groupImage, 1024, 1024); // Resize img if too big

            img.Save(path + @"\GroupImage.png");

            using (FileStream fs = new FileStream(path + @"\GroupIcon.ico", FileMode.Create))
                ImageFunctions.IconFromImage(img).Save(fs);  // saving as icon
                                                             //
                                                             // Create .lnk shortcut
                                                             //
            var wsh = new IWshShell_Class();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(
                path + "\\" + this.Name + ".lnk") as IWshRuntimeLibrary.IWshShortcut;
            shortcut.Arguments        = "";
            shortcut.TargetPath       = Path.GetFullPath(@filePath);
            shortcut.WindowStyle      = 1;
            shortcut.Description      = path + " shortcut";
            shortcut.WorkingDirectory = Path.GetFullPath(@path);
            shortcut.IconLocation     = Path.GetFullPath(path + @"\GroupIcon.ico");
            shortcut.Save();
            System.IO.File.Move(@path + "\\" + this.Name + ".lnk",
                                Path.GetFullPath(@"Shortcuts\" + this.Name + ".lnk")); // moving .lnk to correct directory
        }
Exemple #21
0
        public void appshortcut()
        {
            // Create a Windows Script Host Shell class

            IWshShell_Class shell = new IWshShell_Class();

            // Define the shortcut file

            //IWshURLShortcut shortcut = shell.CreateShortcut(location1) as IWshURLShortcut;

            IWshShortcut_Class shortcut = shell.CreateShortcut(location2) as IWshShortcut_Class;


            shortcut.WorkingDirectory = @"E:\Program Files (x86)\KuGou\KGMusic";
            shortcut.TargetPath       = @"E:\Program Files (x86)\KuGou\KGMusic\KuGou.exe";
            // Save it

            shortcut.Save();
        }
Exemple #22
0
        /// <summary>
        /// 获取快捷方式的目标路径
        /// </summary>
        /// <param name="shortcupFilePath">快捷方式的完整路径</param>
        /// <returns></returns>
        /// <exception cref="StartupItemNotFoundException"></exception>
        static public string GetTargetPathOfShortcutFile(string shortcupFilePath)
        {
            if (!System.IO.File.Exists(shortcupFilePath))
            {
                throw new StartupItemNotFoundException();
            }
            IWshShell_Class wshShell = new IWshShell_Class();

            try
            {
                IWshShortcut shortcut = (IWshShortcut)wshShell.CreateShortcut(shortcupFilePath);
                return(shortcut.TargetPath);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return("");
        }
Exemple #23
0
        /// <summary>
        /// 根据lnk path得到用户的exe 执行路径
        /// </summary>
        /// <param name="path">快捷方式lnk path</param>
        /// <returns>执行路径</returns>
        ///

        public static string GetAppExePath(string path)
        {
            string exepath = "";

            try
            {
                IWshShortcut    _shortcut = null;
                IWshShell_Class shell     = new IWshShell_Class();
                if (System.IO.File.Exists(path) == true)
                {
                    _shortcut = shell.CreateShortcut(path) as IWshShortcut;//在vs2010中CreateShortcut返回dynamic 类型
                }
                //所以要加as 进行对象类型转换
                exepath = _shortcut.TargetPath;
            }
            catch
            {
            }

            return(exepath);
        }
        /*
         * Creates a link between a tag and a bundle.
         * Link is placed in orig_path and links to dest_path
         */
        public void CreateROLink(String origPath, String destPath, string bundleName)
        {
            //TODO add shortcut icon
            IWshShell_Class shell = new IWshShell_Class();
            try {
                // Create the shortcut and choose the path for the shortcut
                IWshShortcut myShortcut = shell.CreateShortcut(origPath + "\\" + bundleName + ".lnk");
                // Where the shortcut should point to
                myShortcut.TargetPath = destPath;
                // Description for the shortcut
                myShortcut.Description = "bundle";
                // Location for the shortcut's icon
                //myShortcut.IconLocation = MediaTypeNames.Application.StartupPath + @"\app.ico";

                myShortcut.IconLocation = Application.StartupPath + @"\Icons\bundle.ico";
                // Create the shortcut at the given path
                myShortcut.Save();
            }
            catch (Exception e) {
                throw;
            }
        }
Exemple #25
0
        public void Add2StartUp(bool startupStatus)
        {
            string startupPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "USBSecure.lnk");

            if (startupStatus)
            {
                string shortCutTo = System.Reflection.Assembly.GetExecutingAssembly().Location;

                var          wsh      = new IWshShell_Class();
                IWshShortcut shortCut = wsh.CreateShortcut(startupPath) as IWshShortcut;
                shortCut.TargetPath       = shortCutTo;
                shortCut.WorkingDirectory = Directory.GetParent(shortCutTo).FullName;
                shortCut.Save();
            }
            else
            {
                if (System.IO.File.Exists(startupPath))
                {
                    System.IO.File.Delete(startupPath);
                }
            }
        }
Exemple #26
0
        public void creatdesktop()

        {
            string app = Environment.CurrentDirectory + @"\_58.exe";

            try
            {
                // Create a Windows Script Host Shell class
                IWshShell_Class shell = new IWshShell_Class();
                // Define the shortcut file
                IWshShortcut_Class shortcut = shell.CreateShortcut(app + ".lnk") as IWshShortcut_Class;
                // Set all its properties
                shortcut.Description  = "Smart sample of creating shell shortcut";
                shortcut.TargetPath   = app;
                shortcut.IconLocation = app + ",0";
                // Save it
                shortcut.Save();
            }
            catch (COMException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemple #27
0
        /// <summary>
        /// Installs an app using the full process
        /// </summary>
        /// <param name="executables">The list of executables installed in the program</param>
        /// <param name="programFolder">The folder where the program is situated</param>
        /// <param name="installFolder">The folder where the program is to be installed</param>
        /// <param name="containedInAnAppFolder">Whether the executable is contained in an app folder or is standalone</param>
        /// <param name="isAdmin">Whether the user wishes to act as admin or not</param>
        public static void InstallApp(List<ExecutableData> executables, string programFolder, string installFolder, bool containedInAnAppFolder, bool isAdmin)
        {
            // Change shortcut name to include standard .lnk extension
            executables.ForEach(x => x.ShortcutName = Path.GetFileNameWithoutExtension(x.ShortcutName) + ".lnk");

            // Move files to project folder
            Directory.CreateDirectory(installFolder);
            if (containedInAnAppFolder)
            {
                SharedApp.MoveDirectory(programFolder, installFolder);
            }
            else
            {
                foreach (ExecutableData executable in executables)
                {
                    System.IO.File.Move(Path.Combine(programFolder, executable.ExecutablePath), Path.Combine(installFolder, executable.ExecutablePath));
                }
            }

            // Create shortcuts
            IWshShell_Class wsh = new IWshShell_Class();
            foreach (ExecutableData executable in executables)
            {
                IWshShortcut shortcut, desktopShortcut = null;
                if (isAdmin)
                {
                    // Create standard shortcut
                    shortcut = wsh.CreateShortcut(Path.Combine(Environment.GetFolderPath(
                        Environment.SpecialFolder.CommonPrograms), executable.ShortcutName)) as IWshShortcut;

                    // Create desktop shortcut
                    if (executable.OnDesktop)
                    {
                        desktopShortcut = wsh.CreateShortcut(Path.Combine(Environment.GetFolderPath(
                            Environment.SpecialFolder.CommonDesktopDirectory), executable.ShortcutName)) as IWshShortcut;
                    }
                }
                else
                {
                    // Create standard shortcuts
                    shortcut = wsh.CreateShortcut(Path.Combine(Environment.GetFolderPath(
                        Environment.SpecialFolder.Programs), executable.ShortcutName)) as IWshShortcut;

                    // Create desktop shortcut
                    if (executable.OnDesktop)
                    {
                        desktopShortcut = wsh.CreateShortcut(Path.Combine(Environment.GetFolderPath(
                            Environment.SpecialFolder.Desktop), executable.ShortcutName)) as IWshShortcut;
                    }
                }
                shortcut.WorkingDirectory = installFolder;
                shortcut.TargetPath = Path.Combine(installFolder, Path.Combine(installFolder, executable.ExecutablePath));
                shortcut.Save();

                // Desktop shortcuts will be created if they are required
                if (executable.OnDesktop)
                {
                    desktopShortcut.WorkingDirectory = installFolder;
                    desktopShortcut.TargetPath = Path.Combine(installFolder, Path.Combine(installFolder, executable.ExecutablePath));
                    desktopShortcut.Save();
                }
            }
        }
Exemple #28
0
        private static void CreateObject()
        {
            settings Settings = settings.load();

            string URL = Settings.sonarrURL + "/api/history?page=1&pageSize=" + Settings.sonarrMaxHistory + "&sortkey=date&sortDir=desc&apikey=" + Settings.sonarrAPI;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);

            request.Method      = "GET";
            request.ContentType = "application/json";
            //request.ContentLength = DATA.Length;


            try
            {
                WebResponse webResponse = request.GetResponse();
                using (Stream webStream = webResponse.GetResponseStream())
                {
                    if (webStream != null)
                    {
                        using (StreamReader responseReader = new StreamReader(webStream))
                        {
                            string response = responseReader.ReadToEnd();

                            JsonDocument jo = JsonDocument.Parse(response);



                            //open the response and parse it using JSON. Query for newly imported files
                            foreach (JsonElement element in jo.RootElement.GetProperty("records").EnumerateArray())
                            {
                                try
                                {
                                    string      title  = element.GetProperty("sourceTitle").ToString();
                                    JsonElement elData = element.GetProperty("data");

                                    JsonElement elImportPath;
                                    bool        success = elData.TryGetProperty("importedPath", out elImportPath);
                                    if (!success)
                                    {
                                        Console.Out.WriteLine("No import path for " + title + " - failed / still processing?");
                                    }
                                    else
                                    {
                                        string importPath = elImportPath.ToString();

                                        //go through these and create the link.
                                        bool found = false;
                                        foreach (grabbedFile g in Settings.recentGrabs)
                                        {
                                            if (g.filename == importPath)
                                            {
                                                found = true;
                                            }
                                        }

                                        if (found == true)
                                        {
                                            Console.Out.WriteLine("Already processed " + importPath);
                                        }
                                        else
                                        {
                                            Console.Out.WriteLine("Processing        " + importPath);
                                            string filename = Path.GetFileNameWithoutExtension(importPath);

                                            //invalid chars
                                            foreach (char invalidchar in System.IO.Path.GetInvalidFileNameChars())
                                            {
                                                filename = filename.Replace(invalidchar, '_');
                                            }

                                            filename = Settings.destinationFolder + @"/" + filename + ".lnk";


                                            //apply any replacements
                                            string destination = importPath;
                                            foreach (replacement r in Settings.replacements)
                                            {
                                                destination = destination.Replace(r.source, r.replace);
                                            }
                                            //replace unix paths with windows ones.
                                            destination = destination.Replace(@"/", @"\");

                                            //TODO - for linux use mslink.sh http://www.mamachine.org/mslink/index.en.html
                                            //craete the link file.
                                            var wsh = new IWshShell_Class();
                                            try
                                            {
                                                IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(filename) as IWshRuntimeLibrary.IWshShortcut;
                                                shortcut.TargetPath = destination;
                                                shortcut.Save();
                                            }

                                            catch (Exception e)
                                            {
                                                Console.Out.WriteLine("--------Failed to create shortcut---------");
                                                Console.Out.WriteLine(filename);
                                                Console.Out.WriteLine(e.Message);
                                                Console.Out.WriteLine(e.InnerException);
                                                Console.Out.WriteLine(e.StackTrace);
                                                Console.Out.WriteLine("-----------------");
                                            }
                                            //log it
                                            Settings.recentGrabs.Add(new grabbedFile(importPath));
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    Console.Out.WriteLine("-----Failed to parse record------------");
                                    Console.Out.WriteLine(e.Message);
                                    Console.Out.WriteLine(e.InnerException);
                                    Console.Out.WriteLine(e.StackTrace);
                                    Console.Out.WriteLine("-----------------");
                                }
                            }
                        }
                    }
                }
                Settings.save();
            }
            catch (Exception e)
            {
                Console.Out.WriteLine("-----------------");
                Console.Out.WriteLine(e.Message);
                Console.Out.WriteLine(e.InnerException);
                Console.Out.WriteLine(e.StackTrace);
                Console.Out.WriteLine(e.ToString());
            }
        }
Exemple #29
0
        //アイコンをフォームに描写する
        private void arrangeIconsProcessing()
        {
            //作業ディレクトリのiconディレクトリにあるショートカットの一覧を取得する
            string[] files = Directory.GetFiles(Directory.GetCurrentDirectory() + "\\icon");

            IWshShell shell = new IWshShell_Class();

            //フォームの座標
            pictureBoxNumber = 0; //ピクチャボックス番号の初期化
            int x = 0; //フォームのx軸
            int y = 30; //フォームのy軸
            const int ICON_SIZE = 35; //フォームに表示するアイコンのサイズ
            Size clientSize = this.ClientSize;
            int width = clientSize.Width / ICON_SIZE; //一行に何個アイコンが並ぶか

            //ショートカットからメニューの項目を作成する
            foreach (String filePath in files)
            {
                //ファイルがショートカットであるかどうかを判定
                FileInfo fileInfo = new FileInfo(filePath);
                String extension = fileInfo.Extension; //ファイルの拡張子を取得

                //ショートカットのアイコンを取得
                Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(filePath);

                //ショートカットだった場合、メニューに項目を追加する
                if (extension.Equals(".lnk"))
                {
                    //一つのショートカットに付き、一つのアイコンを作成する
                    IWshShortcut_Class shortcut = shell.CreateShortcut(filePath);
                    PictureBox pictureBox = new PictureBox();
                    pictureBox.Name = "pictureBox" + pictureBoxNumber; //ピクチャボックスに名前を付ける
                    pictureBoxNumber++; //ピクチャボックス番号の更新

                    //アイコンをクリックすると、リンク先を開く処理を追加
                    pictureBox.Click += delegate(object sender, EventArgs e)
                    {
                        //ショートカットのリンク先を開く処理を実装
                        Process.Start(shortcut.TargetPath, shortcut.Arguments);
                    };

                    //ツールチップにファイル名を表示する
                    pictureBox.MouseHover += delegate(object sender, EventArgs e)
                    {
                        String fileName = fileInfo.Name.Substring(0, fileInfo.Name.Length - extension.Length); //ファイル名から拡張子を取り除く
                        ToolTip toolTip = new ToolTip();
                        toolTip.SetToolTip(pictureBox, fileName);
                    };

                    //フォームにアイコンを追加する
                    pictureBox.Image = icon.ToBitmap();
                    pictureBox.SizeMode = PictureBoxSizeMode.AutoSize;
                    pictureBox.Location = new Point(x, y);
                    this.Controls.Add(pictureBox);

                    //まだアイコンを行に並べられる場合
                    if (width != 0)
                    {
                        x += ICON_SIZE;
                        width--;
                    }

                    //行にアイコンを並べ終えた場合
                    if (width == 0)
                    {
                        width = clientSize.Width / ICON_SIZE; //並べるアイコンの数を更新
                        y += ICON_SIZE;
                        x = 0;
                    }
                }
            }
        }
 public void AttivaEsecuzioneAutomatica()
 {
     var wsh = new IWshShell_Class();
     string programPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\PrinterTimerControl.lnk";
     IWshShortcut shortcut = wsh.CreateShortcut(programPath) as IWshShortcut;            
     shortcut.Description = "Avvia Applicazione PrinterTimerControl";
     shortcut.TargetPath = Application.ExecutablePath;
     shortcut.Save();            
 }
Exemple #31
0
        private static void CreateObject()
        {
            settings Settings = settings.load();

            string URL = Settings.sonarrURL + "/api/history?page=1&pageSize=" + Settings.sonarrMaxHistory + "&sortkey=date&sortDir=desc&apikey=" + Settings.sonarrAPI;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
            request.Method = "GET";
            request.ContentType = "application/json";
            //request.ContentLength = DATA.Length;

            try
            {
                WebResponse webResponse = request.GetResponse();
                using (Stream webStream = webResponse.GetResponseStream())
                {
                    if (webStream != null)
                    {
                        using (StreamReader responseReader = new StreamReader(webStream))
                        {
                                string response = responseReader.ReadToEnd();

                                JObject jo = JObject.Parse(response);

                                Console.Write(jo.First);

                                //open the response and parse it using JSON. Query for newly imported files
                                foreach (JToken token in jo.SelectTokens("records[*].data.importedPath")) //jo.Children()
                                {
                                    //go through these and create the link.
                                    bool found = false;
                                    foreach (grabbedFile g in Settings.recentGrabs)
                                    {
                                        if (g.filename == token.ToString()) { found = true; }
                                    }

                                    if(found == true)
                                    {
                                        Console.Out.WriteLine("Already processed " + token.ToString());
                                    }
                                    else
                                    {
                                        Console.Out.WriteLine("Processing        " + token.ToString());
                                        string filename = Settings.destinationFolder + @"/" + Path.GetFileNameWithoutExtension(token.ToString()) + ".lnk";
                                        string destination = token.ToString();

                                        //apply any replacemenbts
                                        foreach (replacement r in Settings.replacements)
                                        {
                                            destination = destination.Replace(r.source, r.replace);
                                        }

                                        //craete the link file.
                                        var wsh = new IWshShell_Class();
                                        IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(filename) as IWshRuntimeLibrary.IWshShortcut;
                                        shortcut.TargetPath = destination;
                                        shortcut.Save();

                                        //log it
                                        Settings.recentGrabs.Add(new grabbedFile(token.ToString()));
                                    }
                                }

                        }
                    }
                }
                Settings.save();
            }
            catch (Exception e)
            {
                Console.Out.WriteLine("-----------------");
                Console.Out.WriteLine(e.Message);
            }
        }
        private void ShortcutToPath_Func(string ShortcutOriFilePath)
        {
            //http://dobon.net/vb/dotnet/file/pathcombine.html //フォルダ毎ドラッグしても、なうぷれTunes を 検出
            if (System.IO.File.Exists(System.IO.Path.Combine(ShortcutOriFilePath, "NowplayingTunes.exe")))
            {
                ShortcutOriFilePath = System.IO.Path.Combine(ShortcutOriFilePath, "NowplayingTunes.exe");
            }

            if (System.IO.File.Exists(System.IO.Path.Combine(ShortcutOriFilePath, "なうぷれTunes.exe")))
            {
                ShortcutOriFilePath = System.IO.Path.Combine(ShortcutOriFilePath, "なうぷれTunes.exe");
            }

            if (ShortcutOriFilePath != "")
            {
                //絶対パスに変換して、比較
                if (ShortcutOriFilePath == Application.ExecutablePath
                    || System.IO.Path.GetFullPath(ShortcutOriFilePath) == Application.ExecutablePath)  //自分自身のパスは何もしない
                {
                    ShortcutOriFilePath = "";
                }
                else
                {
                    if (System.IO.File.Exists(ShortcutOriFilePath))
                    {
                        if (ShortcutOriFilePath.Length >= 4)
                        {
                            if (ShortcutOriFilePath.LastIndexOf(".lnk") == ShortcutOriFilePath.Length - 4)
                            {
                                //http://d.hatena.ne.jp/hikaruright/20121026/1351214441
                                // .lnkファイルからpathを拾う
                                IWshShell_Class shell = new IWshShell_Class();
                                IWshShortcut_Class shortcut;
                                shortcut = (IWshShortcut_Class)shell.CreateShortcut(ShortcutOriFilePath);

                                if (System.IO.File.Exists(shortcut.TargetPath))
                                {

                                    if (shortcut.TargetPath.Substring(shortcut.TargetPath.LastIndexOf("\\") + 1) == "iTunes.exe")
                                    {
                                        iTunes_PATH = shortcut.TargetPath;
                                    }
                                    else if (shortcut.TargetPath.Substring(shortcut.TargetPath.LastIndexOf("\\") + 1) == "NowplayingTunes.exe"
                                           || shortcut.TargetPath.Substring(shortcut.TargetPath.LastIndexOf("\\") + 1) == "なうぷれTunes.exe")
                                    {
                                        NowplayingTunes_PATH = shortcut.TargetPath;
                                    }
                                }
                            }
                            else
                            {
                                if (ShortcutOriFilePath.Substring(ShortcutOriFilePath.LastIndexOf("\\") + 1) == "iTunes.exe")
                                {
                                    iTunes_PATH = ShortcutOriFilePath;
                                }
                                else if (ShortcutOriFilePath.Substring(ShortcutOriFilePath.LastIndexOf("\\") + 1) == "NowplayingTunes.exe"
                                       || ShortcutOriFilePath.Substring(ShortcutOriFilePath.LastIndexOf("\\") + 1) == "なうぷれTunes.exe")
                                {
                                    NowplayingTunes_PATH = ShortcutOriFilePath;
                                }
                            }
                        }
                    }
                }
            }
        }