11using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Text ;
52using System . Diagnostics ;
63using Microsoft . Win32 ;
74
85namespace SmartSystemMenu
96{
107 static class AutoStarter
118 {
12- private const String RUN_LOCATION = @"Software\Microsoft\Windows\CurrentVersion\Run" ;
9+ private const string RUN_LOCATION = @"Software\Microsoft\Windows\CurrentVersion\Run" ;
1310
14- public static void SetAutoStartByRegister ( String keyName , String assemblyLocation )
11+ public static void SetAutoStartByRegister ( string keyName , string assemblyLocation )
1512 {
16- RegistryKey key = Registry . CurrentUser . CreateSubKey ( RUN_LOCATION ) ;
17- key . SetValue ( keyName , assemblyLocation ) ;
13+ using ( var key = Registry . CurrentUser . CreateSubKey ( RUN_LOCATION ) )
14+ {
15+ key . SetValue ( keyName , assemblyLocation ) ;
16+ }
1817 }
1918
20- public static void UnsetAutoStartByRegister ( String keyName )
19+ public static void UnsetAutoStartByRegister ( string keyName )
2120 {
22- RegistryKey key = Registry . CurrentUser . CreateSubKey ( RUN_LOCATION ) ;
23- key . DeleteValue ( keyName ) ;
21+ using ( var key = Registry . CurrentUser . CreateSubKey ( RUN_LOCATION ) )
22+ {
23+ key . DeleteValue ( keyName ) ;
24+ }
2425 }
2526
26- public static void SetAutoStartByScheduler ( String keyName , String assemblyLocation )
27+ public static void SetAutoStartByScheduler ( string keyName , string assemblyLocation )
2728 {
28- String fileName = "schtasks.exe" ;
29- String arguments = "/create /sc onlogon /tn \" {0}\" /rl highest /tr \" {1}\" " ;
30- arguments = String . Format ( arguments , keyName , assemblyLocation ) ;
31- Process scheduleProcess = new Process ( ) ;
29+ var fileName = "schtasks.exe" ;
30+ var arguments = "/create /sc onlogon /tn \" {0}\" /rl highest /tr \" {1}\" " ;
31+ arguments = string . Format ( arguments , keyName , assemblyLocation ) ;
32+ var scheduleProcess = new Process ( ) ;
3233 scheduleProcess . StartInfo . CreateNoWindow = true ;
3334 scheduleProcess . StartInfo . UseShellExecute = false ;
3435 scheduleProcess . StartInfo . FileName = fileName ;
@@ -40,12 +41,12 @@ public static void SetAutoStartByScheduler(String keyName, String assemblyLocati
4041 }
4142 }
4243
43- public static void UnsetAutoStartByScheduler ( String keyName )
44+ public static void UnsetAutoStartByScheduler ( string keyName )
4445 {
45- String fileName = "schtasks.exe" ;
46- String arguments = "/delete /tn \" {0}\" /f" ;
47- arguments = String . Format ( arguments , keyName ) ;
48- Process scheduleProcess = new Process ( ) ;
46+ string fileName = "schtasks.exe" ;
47+ string arguments = "/delete /tn \" {0}\" /f" ;
48+ arguments = string . Format ( arguments , keyName ) ;
49+ var scheduleProcess = new Process ( ) ;
4950 scheduleProcess . StartInfo . CreateNoWindow = true ;
5051 scheduleProcess . StartInfo . UseShellExecute = false ;
5152 scheduleProcess . StartInfo . FileName = fileName ;
@@ -57,14 +58,16 @@ public static void UnsetAutoStartByScheduler(String keyName)
5758 }
5859 }
5960
60- public static Boolean IsAutoStartByRegisterEnabled ( String keyName , String assemblyLocation )
61+ public static bool IsAutoStartByRegisterEnabled ( string keyName , string assemblyLocation )
6162 {
62- RegistryKey key = Registry . CurrentUser . OpenSubKey ( RUN_LOCATION ) ;
63- if ( key == null ) return false ;
64- String value = ( String ) key . GetValue ( keyName ) ;
65- if ( String . IsNullOrEmpty ( value ) ) return false ;
66- Boolean result = ( value == assemblyLocation ) ;
67- return result ;
63+ using ( var key = Registry . CurrentUser . OpenSubKey ( RUN_LOCATION ) )
64+ {
65+ if ( key == null ) return false ;
66+ string value = ( string ) key . GetValue ( keyName ) ;
67+ if ( string . IsNullOrEmpty ( value ) ) return false ;
68+ var result = ( value == assemblyLocation ) ;
69+ return result ;
70+ }
6871 }
6972 }
7073}
0 commit comments