it-100

WPF(C#) - 빠른 설정 스크립트 ( 윈도우 트윅 )




 @ 내가 필요한건 내가 만들어야 되는듯...

훨씬 잘 만들고 좋은 프로그램도 많이 있지만,

내가 필요한 부분만 따로 커스터마이징해서 쓸 수 있는 프로그램은 없는거 같습니다.

장점이자 단점인 부분입니다.

일단 필요한 부분만 인터넷 검색하고 컴퓨터 레지스트리 변경 값 확인해가면서 만들었습니다.

추가적으로 몇가지 더 넣고 좀 보기 좋게 만들어야겠습니다.. ^^




@ MainWindow.xaml


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<Window x:Name="Window01" x:Class="WpfApp3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp3"
        mc:Ignorable="d"
        Title="MainWindow" Height="438.242" Width="654.767">
    <Grid Margin="0,2,0,-2">
        <Button x:Name="btn010" Content="자동설정" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="100" Height="50" Click="Button_Click"/>
        <Label Content="[탐색기 설정]&#xD;&#xA; - 파일탐색기열기를 '내 PC'로 변경&#xD;&#xA; - 빠른 실행에 최근에 사용된 파일 표시 체크 해제&#xD;&#xA; - 빠른 실행에 최근에 사용된 파일 표시 체크 해제" Height="82" Margin="115,10,10,0" VerticalAlignment="Top" FontSize="14"/>
        <Button x:Name="btn011" Content="절전모드끄기" HorizontalAlignment="Left" Margin="10,109,0,0" VerticalAlignment="Top" Width="100" Height="50" Click="Button_Click"/>
        <Label Content="[전원관리옵션]&#xD;&#xA; - 디스플레이끄기 '없음'&#xD;&#xA; - 컴퓨터를 절전 모드로 설정 '없음'" Height="64" Margin="115,109,10,0" VerticalAlignment="Top" FontSize="14"/>
        <Button x:Name="btn012" Content="자동실행 끄기" HorizontalAlignment="Left" Margin="10,191,0,0" VerticalAlignment="Top" Width="100" Height="50" Click="Button_Click"/>
        <Label Content="[미디어 자동실행]&#xA; - 모든 미디어장치에 자동 실행 사용 '끔'" Height="50" Margin="115,191,10,0" VerticalAlignment="Top" FontSize="14"/>
        <Button x:Name="btn013" Content="UAC 끄기" HorizontalAlignment="Left" Margin="10,246,0,0" VerticalAlignment="Top" Width="100" Height="50" Click="Button_Click"/>
        <Label Content="[사용자계정컨트롤]&#xA; - 사용자 계정 컨트롤 사용 '끔'" Height="50" Margin="115,246,10,0" VerticalAlignment="Top" FontSize="14"/>
        <Button x:Name="btn014" Content="방해 금지 모드" HorizontalAlignment="Left" Margin="10,301,0,0" VerticalAlignment="Top" Width="100" Height="50" Click="Button_Click"/>
        <Label Content="[방해금지모드]&#xA; - 각종 알림에 대한 메세지 보이기 '끔'" Height="50" Margin="115,301,10,0" VerticalAlignment="Top" FontSize="14"/>
    </Grid>
</Window>
 
cs




@ MainWindow.xaml.cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
 
namespace WpfApp3
{
    /// <summary>
    /// MainWindow.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        
 
        private void cmd(string str)
        {
            ProcessStartInfo cmd = new ProcessStartInfo();
            Process process = new Process();
 
            cmd.FileName = @"cmd";  // cmd 창 실행
            cmd.WindowStyle = ProcessWindowStyle.Hidden; //cmd 창 숨기기
            cmd.CreateNoWindow = true;      //cmd 창 띄우지 않기
            cmd.UseShellExecute = false;   // Shell 기능 미사용
            cmd.RedirectStandardInput = true;  // cmd 창에서 데이터를 가져오기
            cmd.RedirectStandardOutput = true// cmd 창으로 데이터 보내기
            cmd.RedirectStandardError = true//cmd 창에서 오류 내용 가져오기
 
            process.StartInfo = cmd;
            process.EnableRaisingEvents = false;   // 종료 이벤트 알리지 않기
            process.Start();
            process.StandardInput.Write(str + Environment.NewLine);
            process.Close();
            //string result = process.StandardOutput.ReadToEnd();  //cmd출력이 끝나면 다음 문장으로 넘어가기 위함
 
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;
 
            // 파일탐색기열기(보기)
            if (btn.Name == "btn010")
            {
                cmd(@"cmd.exe /k %windir%\System32\reg.exe ADD HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v LaunchTo /t REG_DWORD /d 1 /f");   // 파일탐색기열기 (내PC:1/ 바로가기:2)
                cmd(@"cmd.exe /k %windir%\System32\reg.exe ADD HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer /v ShowFrequent /t REG_DWORD /d 0 /f");   // 최근폴더 (표시하기:1/ 안하기:0)
                cmd(@"cmd.exe /k %windir%\System32\reg.exe ADD HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer /v ShowRecent /t REG_DWORD /d 0 /f");   // 최근파일 (표시하기:1/ 안하기:0)
            }
 
            // 전원옵션
            if (btn.Name == "btn011")
            {
                cmd(@"powercfg /x monitor-timeout-ac 0");   // 디스플레이 끄기 (시간단위:분)
                cmd(@"powercfg /x standby-timeout-ac 0");   // 컴퓨터 절전모드 실행 (시간단위:분)
            }
            
            // 미디어 자동실행 (실행끄기:1 / 실행:0)
            if (btn.Name == "btn012") cmd(@"cmd.exe /k %windir%\System32\reg.exe ADD HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers /v DisableAutoplay /t REG_DWORD /d 1 /f");
 
            // 사용자계정컨트롤 ( UAC끄기:0 / UAC켜기:1)
            if (btn.Name == "btn013") cmd(@"cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f");
            
            // 방해금지모드 (알림끄기:0 / 알림:1)
            if (btn.Name == "btn014") cmd(@"cmd.exe /k %windir%\System32\reg.exe ADD HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Notifications\Settings /v NOC_GLOBAL_SETTING_TOASTS_ENABLED /t REG_DWORD /d 0 /f");
 
            btn.IsEnabled = false;
        }
    }
}
 
cs




 @ 소스설명

대략적인 설명은 소스상에 다 나와있습니다.

일단, 프로그램 제작시 레지스트리 수정등에 있어서 C# 자체적으로 해결하지않고 cmd 프로그램을 이용하여 실행하도록 했습니다.

C# 의 경우 cmd를 거치지 않으니 안정적으로 잘 돌아가겠지만, 일단 체크해줘야할 사항이 너무 많습니다.

설정값을 정해야할 것도 많아 손이 많이 가서 수월한 작을 위해 cmd를 통해 처리를 하기로 했습니다.

물론 양이 더 많아지면 오히려 C# 자체적으로 해결하는 편이 나을거 같기는 합니다.

여튼 이정도 양이면 위와같이 cmd 의 힘을 빌어서 하는거싱 좋은거 같습니다.


그리고 만들때 UAC 컨트롤부분이 조금 신경쓰였습니다.

관리자 권한 모드로 실행해서 해야하는 부분인데, 자칫 오류가 나기 쉬운부분입니다.

완료 후 재부팅을 해줘야 정상적으로 적용이 된다고하는데, UAC의 경우도 그런지는 모르겠습니다.


인터넷의 풍부한 자료를 바탕으로 만들어보았습니다.

내가 필요한것만 나오게하려면 역시나 내손으로 직접 만들어야되는거같습니다.^^


앞으로 몇가지만 더 추가하면 될거 같습니다.

윈도우10 에서 아이콘이 깨지는 현상을 종종 보게 됩니다.

이유는 모르겠지만 너무 많이 보게 되어서, 이부분 해결이 필요할 듯합니다.


조만간 더 추가해서 올리도록 하겠습니다.