Skip to content

Commit 1b09860

Browse files
authored
Uploaded project
First product-upload
1 parent 24bcc10 commit 1b09860

10 files changed

+256
-0
lines changed

HomeComputerControl.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HomeComputerControl", "HomeComputerControl\HomeComputerControl.csproj", "{404B42F4-E135-4D2F-8FD0-20A590814930}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{404B42F4-E135-4D2F-8FD0-20A590814930}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{404B42F4-E135-4D2F-8FD0-20A590814930}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{404B42F4-E135-4D2F-8FD0-20A590814930}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{404B42F4-E135-4D2F-8FD0-20A590814930}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

HomeComputerControl/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
5+
</startup>
6+
</configuration>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{404B42F4-E135-4D2F-8FD0-20A590814930}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>HomeComputerControl</RootNamespace>
11+
<AssemblyName>HomeComputerControl</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<PropertyGroup>
36+
<StartupObject />
37+
</PropertyGroup>
38+
<ItemGroup>
39+
<Reference Include="System" />
40+
<Reference Include="System.Core" />
41+
<Reference Include="System.Windows.Forms" />
42+
<Reference Include="System.Xml.Linq" />
43+
<Reference Include="System.Data.DataSetExtensions" />
44+
<Reference Include="Microsoft.CSharp" />
45+
<Reference Include="System.Data" />
46+
<Reference Include="System.Net.Http" />
47+
<Reference Include="System.Xml" />
48+
</ItemGroup>
49+
<ItemGroup>
50+
<Compile Include="Program.cs" />
51+
<Compile Include="Properties\AssemblyInfo.cs" />
52+
</ItemGroup>
53+
<ItemGroup>
54+
<None Include="App.config" />
55+
</ItemGroup>
56+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
57+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
58+
Other similar extension points exist, see Microsoft.Common.targets.
59+
<Target Name="BeforeBuild">
60+
</Target>
61+
<Target Name="AfterBuild">
62+
</Target>
63+
-->
64+
</Project>

HomeComputerControl/Program.cs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows.Forms;
7+
using System.IO;
8+
using System.Diagnostics;
9+
using System.Runtime.InteropServices;
10+
using System.ComponentModel;
11+
using System.Threading;
12+
using System.Reflection;
13+
14+
namespace HomeComputerControl {
15+
class Program {
16+
static string currentLocation = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
17+
static private string filePath = currentLocation + "/computerAction.txt";
18+
static string error_message = "";
19+
20+
//Logout
21+
[DllImport("user32.dll", SetLastError = true)]
22+
static extern int ExitWindowsEx(uint uFlags, uint dwReason);
23+
24+
//Lock
25+
[DllImport("user32.dll")]
26+
public static extern bool LockWorkStation();
27+
28+
static void clearFile() {
29+
if (File.Exists(filePath)) {
30+
File.Delete(filePath);
31+
}
32+
}
33+
34+
static void Main(string[] args) {
35+
clearFile();
36+
while (true) {
37+
if (File.Exists(filePath)) {
38+
if (new FileInfo(filePath).Length != 0) {
39+
string line = File.ReadAllLines(filePath)[0];
40+
DateTime lastModified = File.GetLastWriteTime(filePath);
41+
string action;
42+
string parameter = null;
43+
44+
if(lastModified.AddSeconds(30) > DateTime.UtcNow) {
45+
//If file has been modified recently - check for action
46+
if (line.Contains(":")) {
47+
//Contains a parameter
48+
action = line.Split(':')[0];
49+
parameter = line.Split(':')[1];
50+
} else {
51+
action = line;
52+
}
53+
54+
switch (action) {
55+
case "shutdown":
56+
57+
//Shuts down the computer
58+
Process.Start("shutdown", "/s /t 0");
59+
break;
60+
case "restart":
61+
62+
//Restart the computer
63+
Process.Start("shutdown", "/r /t 0");
64+
break;
65+
case "sleep":
66+
67+
//Puts computer to sleep
68+
Application.SetSuspendState(PowerState.Suspend, true, true);
69+
break;
70+
case "logout":
71+
72+
//Logs out of the current user
73+
ExitWindowsEx(0, 0);
74+
break;
75+
case "lock":
76+
77+
//Lock computer
78+
LockWorkStation();
79+
break;
80+
case "mute":
81+
82+
//Mutes windows
83+
error_message = "This feature is not supported yet";
84+
break;
85+
case "set_volume":
86+
//Requires parameter
87+
if (parameter != null) {
88+
89+
} else {
90+
error_message = "Parameter not set";
91+
}
92+
break;
93+
default:
94+
//Unknown action
95+
error_message = "Unknown action \"" + action + "\"";
96+
break;
97+
}
98+
} else {
99+
error_message = "No action set lately";
100+
}
101+
} else {
102+
error_message = "No action set (file is empty)";
103+
}
104+
clearFile();
105+
if (error_message.Length != 0) {
106+
MessageBox.Show(error_message, "Error | HomeComputerControl");
107+
error_message = "";
108+
}
109+
} else {
110+
//File doesn't exist... On hold
111+
}
112+
Thread.Sleep(500);
113+
}
114+
}
115+
}
116+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("HomeComputerControl")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("HomeComputerControl")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("404b42f4-e135-4d2f-8fd0-20a590814930")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
c:\users\alber\documents\visual studio 2015\Projects\HomeComputerControl\HomeComputerControl\bin\Debug\HomeComputerControl.exe.config
2+
c:\users\alber\documents\visual studio 2015\Projects\HomeComputerControl\HomeComputerControl\bin\Debug\HomeComputerControl.exe
3+
c:\users\alber\documents\visual studio 2015\Projects\HomeComputerControl\HomeComputerControl\bin\Debug\HomeComputerControl.pdb
4+
c:\users\alber\documents\visual studio 2015\Projects\HomeComputerControl\HomeComputerControl\obj\Debug\HomeComputerControl.csprojResolveAssemblyReference.cache
5+
c:\users\alber\documents\visual studio 2015\Projects\HomeComputerControl\HomeComputerControl\obj\Debug\HomeComputerControl.exe
6+
c:\users\alber\documents\visual studio 2015\Projects\HomeComputerControl\HomeComputerControl\obj\Debug\HomeComputerControl.pdb
7+
C:\Users\alber\OneDrive\C# Programmer\HomeComputerControl\HomeComputerControl\bin\Debug\HomeComputerControl.exe.config
8+
C:\Users\alber\OneDrive\C# Programmer\HomeComputerControl\HomeComputerControl\obj\Debug\HomeComputerControl.exe
9+
C:\Users\alber\OneDrive\C# Programmer\HomeComputerControl\HomeComputerControl\obj\Debug\HomeComputerControl.pdb
10+
C:\Users\alber\OneDrive\C# Programmer\HomeComputerControl\HomeComputerControl\bin\Debug\HomeComputerControl.exe
11+
C:\Users\alber\OneDrive\C# Programmer\HomeComputerControl\HomeComputerControl\bin\Debug\HomeComputerControl.pdb
12+
C:\Users\alber\OneDrive\C# Programmer\HomeComputerControl\HomeComputerControl\obj\Debug\HomeComputerControl.csprojResolveAssemblyReference.cache
Binary file not shown.
7 KB
Binary file not shown.
13.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)