C# - método para escribir logs



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace programa
{
    class ejemploLog
    {

        public void eLog(string pc, string usuario, string mensaje, StreamWriter sw)
        {
            DateTime f = DateTime.Now;
            string fecha = f.ToString("dd/MM/yyyy");
            mensaje = fecha + ";" + pc + ";" + usuario + ";" + mensaje + ";";
            Console.WriteLine(mensaje);
            sw.WriteLine(mensaje);
        }
        static void Main()
        {
            string ArchLog = @"c:\pruebaLog.txt";
            StreamWriter sw = File.AppendText(ArchLog);
            ejemploLog m = new ejemploLog();
            m.eLog("pc1", "jorge", "autorizado a acceder", sw);
            m.eLog("pc2", "jorge1", "No autorizado a acceder", sw);
            m.eLog("pc3", "jorge2", "autorizado a acceder", sw);
            Console.ReadLine();
        } // main
    } // class ejemploLog
} // namespace programa

Powershell Oneliner - Crear enlaces con el texto

teniendo un .txt con este contenido

http://rapidshare.com/files/9106992734/part41.rar
http://rapidshare.com/files/9107023022/part42.rar
http://rapidshare.com/files/9107046391/part43.rar
http://rapidshare.com/files/9107051016/part44.rar

Service Pack 1

http://rapidshare.com/files/9108036830/l.part1.rar
http://rapidshare.com/files/9108074053/l.part2.rar
http://rapidshare.com/files/9108081587/l.part3.rar

Medicina

http://rapidshare.com/files/9107829561/fix.rar

para convertir el texto en link y guardarlo en un htm para que el programa de descarga los detecte automaticamente, se puede hacer esto en powershell


WMI - Clases y propiedades

Hardware classes

Motherboard, controllers, and on-board devices

  • Win32_1394Controller
    • uint16 Availability;
    • string DeviceID;
    • string Manufacturer;
    • string Name;
    • string Status;
  • Win32_BaseBoard
    • string Manufacturer;
    • string Model;
    • string Name;
    • string Product;
    • string Status;
    • string Version

C# - Abrir un archivo que lea caracteres unicode




using System;
using System.IO;

namespace prueba
 {
   class jorge
     {
       public static void Main()
         {
           string path = "c:\a.txt";
           // abrir archivo
          StreamReader sr = new StreamReader(path, System.Text.Encoding.Default);
          string linea = sr.ReadLine();
          while (linea != null)
            {
              Console.WriteLine("linea: {0}", linea);
              linea = sr.ReadLine();
            }
          Console.ReadLine();
         }
      }
}


obtener el valor de una variable de entorno de un equipo remoto

$clave = "PATH"
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$s)
$key = $regKey.OpenSubkey("SYSTEM\CurrentControlSet\Control\Session Manager\Environment",$true)
$val = $key.GetValue("$clave")
"el valor de la clave $clave es: $val"