2012年11月17日土曜日

スタートアップに [デスクトップの表示] を作成するプログラム


Win8起動時にデスクトップを表示する方法で紹介した
スタートアップに [デスクトップの表示] を作成する方法いかがでしたか?
 [デスクトップの表示] の作成から自分でやるのは大変だ、という人向けに

スタートアップに [デスクトップの表示] を作成するプログラムを作ってみました。

Open the Startup Folder (OpenSupF.exe)

Windows8 WindowsDesktop C# のプログラムです。


SkyDrive を使って公開します。

このリンクから >>> http://sdrv.ms/RZaKds

SkyDrive の公開フォルダが開くので
OpenSupF を適当なフォルダにダウンロードし、実行してください。

[Windows によって PC が保護されました] が表示された場合
[詳細情報] をクリック、つづいて [実行] をクリックしてください。




Created ボタン をクリックすると、ログオンしているユーザーの、スタートアップフォルダに
Show_Desktop.scf のファイル名で、[デスクトップの表示] が作成されます。

これで、Win8起動時に、スタート画面が表示後
自動的に、デスクトップに表示が切り替わるようになります。


起動時に、デスクトップを表示するのをやめたい場合は
Open ボタン をクリックすれば、スタートアップフォルダが、エクスプローラーで開きます。
そこにある、Show_Desktop.scf のファイルを削除してください。


---------------------------------------

前回作成した、[デスクトップの表示] から少し変更してあります。

・ ファイル名を、デスクトップの表示.scf から Show_Desktop.scf に変更
・ コードの内容を以下に変更、アイコンの表示が変わります。

    [Shell]
    Command=2
    IconFile=System32/imageres.dll,105
    [Taskbar]
    Command=ToggleDesktop



Open the Startup Folder (OpenSupF.exe) の内容

Form に button を 3つ配置

Form1.cs
=====================================================================


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;

namespace OpenStartupFolder
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


            // ログオン ユーザー用スタートアップフォルダを開く
        private void button1_Click(object sender, EventArgs e)

        {
            string UserProfile = Environment.GetEnvironmentVariable("USERPROFILE");
            Process.Start("EXPLORER.EXE", "/n, " + UserProfile + @"\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup");
        }


            // All User 用スタートアップフォルダを開く
        private void button2_Click(object sender, EventArgs e)

        {
            string systemDrive = Environment.GetEnvironmentVariable("SystemDrive");
            Process.Start("EXPLORER.EXE", "/n, " + systemDrive + @"\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp");
        }

     // Show_Desktop.scf を作成する
        private void button3_Click(object sender, EventArgs e)
        {
            string UserProfile = Environment.GetEnvironmentVariable("USERPROFILE");
            string Show_Desktop = UserProfile + @"\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\Show_Desktop.scf";

            // ファイルの存在を確認
            if (File.Exists(Show_Desktop))
            {
                MessageBox.Show("既に Show_Desktop.scf ファイルは存在します。");
            }
            else
            {
                // Show_Desktop.scf を作成
                Encoding Enco = Encoding.GetEncoding(0)

                StreamWriter writer = new StreamWriter(Show_Desktop, true, Enco);
                writer.WriteLine("[Shell]");
                writer.WriteLine("Command=2");
                writer.WriteLine("IconFile=System32/imageres.dll,105");
                writer.WriteLine("[Taskbar]");
                writer.WriteLine("Command=ToggleDesktop");

                writer.Close();

                MessageBox.Show("Startup Folder に Show_Desktop.scf を作成しました。");

            }
        }


    }
}


======================================================================


0 件のコメント:

コメントを投稿