La clase debe implementar la interfaz IObjectSafety.
Para compilarlo:
Ir a prompt de visual studio 2013 (abrirlo como administrador)
Si no hay una strong key, generarla con:
sn -k keyImpresora.snk
cls
call "%VS120COMNTOOLS%..\Tools\vsvars32.bat"
csc /t:library Impresora.cs /keyfile:keyImpresora.snk
regasm Impresora.dll /tlb:ImpresoraNet.dll /codebase
Código C#
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
using System.IO;
using System.Collections.Generic;
namespace X
{
[ComImport()]
[Guid("CB5BDC81-93C1-11CF-8F20-00805F2CD064")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IObjectSafety
{
[PreserveSig()]
int GetInterfaceSafetyOptions(ref Guid riid, out int pdwSupportedOptions, out int pdwEnabledOptions);
[PreserveSig()]
int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions);
}
public enum Estilo
{
Normal,
Bold,
Enlarged,
Condensed
}
public interface IImpresora
{
string Imprimir(string texto, string estilo);
void FormFeed();
void Log(string texto);
string Inicializar(string usuario);
void Agregar(string linea);
void Listar();
}
public class Linea
{
public string Texto {get; set;}
public string Estilo {get; set;}
}
[ProgId("X.Impresora")]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[ComVisible(true)]
public class Impresora : IObjectSafety
{
bool _fin = false;
string _pathImpresora = "";
List<Linea> lineas;
private const int INTERFACESAFE_FOR_UNTRUSTED_CALLER = 0x00000001;
private const int INTERFACESAFE_FOR_UNTRUSTED_DATA = 0x00000002;
private const int S_OK = 0;
[ComVisible(true)]
public int GetInterfaceSafetyOptions(ref Guid riid, out int pdwSupportedOptions, out int pdwEnabledOptions)
{
pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA;
pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA;
return S_OK;
}
[ComVisible(true)]
public int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions)
{
return S_OK;
}
[ComVisible(true)]
public void Agregar(string linea)
{
var l = new Linea();
l.Texto = linea;
lineas.Add(l);
}
[ComVisible(true)]
public void Listar()
{
File.Delete(Environment.GetEnvironmentVariable("TEMP") + "\\outLog.txt");
foreach (var l in lineas)
{
var xx = "";
xx = l.Texto;
xx = xx.Replace((char)13 + "" + (char)10, "");
if (xx.Contains(Convert.ToChar(27) + "(s3B") || xx.Contains(Convert.ToChar(27) + "(s0B"))
{
//evito estas lineas porque hacen bloquear la impresora.
xx = "";
} else
{
xx = xx.Replace( Convert.ToChar(27) + "E" + "", (char)27 + "" + (char)69 + "");
}
Log(xx);
}
EjecutarComando("type %TEMP%\\outLog.txt > " + _pathImpresora);
}
[ComVisible(true)]
public string Inicializar(string usuario)
{
var archivo = @"c:\X_imp\" + usuario + @"\XframePrinter.properties";
var host = "";
var nombreImp = "";
if (File.Exists(archivo))
{
var f = new StreamReader(archivo);
while (!f.EndOfStream)
{
var linea = f.ReadLine();
if (linea.Contains("XframeConnectorService.PrinterDriver.drivers"))
{
var v = linea.Split('=');
host = v[1];
host = host.Substring(0, host.IndexOf(","));
}
if (host != "")
{
if (linea.IndexOf("XframeConnectorService.PrinterDriver." + host + ".port", StringComparison.OrdinalIgnoreCase) >= 0)
{
var v = linea.Split('=');
nombreImp = v[1].Replace("\\", "");
}
}
}
} else
Log("NO EXISTE ARCHIVO DE CONFIG");
var ret = "";
if (host != "" && nombreImp != "")
{
_pathImpresora = @"\\" + host + @"\" + nombreImp;
ret = "OK";
}
else
{
_pathImpresora = "";
ret = "ERROR";
}
if (ret == "OK")
lineas = new List<Linea>();
return ret;
}
private void EjecutarComando(string comando) {
ProcessStartInfo processInfo;
Process proc;
_fin = false;
processInfo = new ProcessStartInfo("cmd.exe", (Convert.ToString("/c ") + comando));
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
processInfo.Verb = "runas";
proc = new Process();
proc.EnableRaisingEvents = true;
proc.StartInfo = processInfo;
proc.OutputDataReceived += OnOutputDataReceived;
proc.Exited += OnProcessExited;
proc.Start();
proc.BeginOutputReadLine();
while (!_fin) {
Thread.Sleep(1);
}
proc.Close();
}
private void OnProcessExited(object sender, EventArgs e) {
_fin = true;
}
private void OnOutputDataReceived(object sender, DataReceivedEventArgs e) {
}
[ComVisible(true)]
public void Log(string texto)
{
var f = new StreamWriter(Environment.GetEnvironmentVariable("TEMP") + "\\outLog.txt", true);
f.WriteLine(texto);
f.Close();
}
}
}
Invocar metodos de un objeto COM desde una página web con javascript - con ejemplo de impresion (call simple ActiveX object installed on the client)
Para compilarlo:
Ir a prompt de visual studio 2013 (abrirlo como administrador)
Si no hay una strong key, generarla con:
sn -k keyImpresora.snk
cls
call "%VS120COMNTOOLS%..\Tools\vsvars32.bat"
csc /t:library Impresora.cs /keyfile:keyImpresora.snk
regasm Impresora.dll /tlb:ImpresoraNet.dll /codebase
Impresora.cs
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
using System.IO;
using System.Collections.Generic;
namespace X
{
public enum Estilo
{
Normal,
Bold,
Enlarged,
Condensed
}
public interface IImpresora
{
string Imprimir(string texto, string estilo);
void FormFeed();
void Log(string texto);
string Inicializar(string usuario);
void Agregar(string linea);
void Listar();
}
public class Linea
{
public string Texto {get; set;}
public string Estilo {get; set;}
}
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Impresora : IImpresora
{
bool _fin = false;
string _pathImpresora = "";
List<Linea> lineas;
public void Agregar(string linea)
{
var l = new Linea();
l.Texto = linea;
lineas.Add(l);
}
public void Listar()
{
var estilo = "normal";
var textoOk = "";
File.Delete("c:\\temp\\outLog.txt");
foreach (var l in lineas)
{
var xx = "";
xx = l.Texto;
xx = xx.Replace((char)13 + "" + (char)10, "");
if (xx.Contains(Convert.ToChar(27) + "(s3B") || xx.Contains(Convert.ToChar(27) + "(s0B"))
{
//evito estas lineas
} else
{
// var xx = l.Texto.Replace( Convert.ToChar(27) + "(s3B", "");
// xx = xx.Replace( Convert.ToChar(27) + "(s0B", "");
xx = xx.Replace( Convert.ToChar(27) + "E" + "", (char)27 + "" + (char)69 + "");
}
Log(xx);
}
EjecutarComando("type c:\\temp\\outLog.txt > " + _pathImpresora);
/*
foreach (var l in lineas)
{
textoOk = "";
for (int i=0; i<l.Texto.Length; i++)
{
if ((int)l.Texto[i] == 12)
{
textoOk += "[FORM FEED]";
i++;
}
if ((int)l.Texto[i] == 27)
{
i++;
if ((int)l.Texto[i] == 69)
{
estilo = "bold";
i++;
} else if ((int)l.Texto[i] == 70)
{
estilo = "normal";
i++;
}
}
textoOk += l.Texto[i];
}
//Log(textoOk + " - " + estilo );
}
*/
}
public string Imprimir(string texto, string estilo)
{
if (estilo == "normal")
ImprimirLinea(texto, Estilo.Normal);
if (estilo == "bold")
ImprimirLinea(texto, Estilo.Bold);
if (estilo == "enlarged")
ImprimirLinea(texto, Estilo.Enlarged);
if (estilo == "condensed")
ImprimirLinea(texto, Estilo.Condensed);
return texto;
}
public void FormFeed()
{
//para que funcione el form feed hay que poner algun caracter antes y despues (en este caso, el signo de menos)
EjecutarComando("echo -" + (char)12 + "- > " + _pathImpresora);
}
public string Inicializar(string usuario)
{
var archivo = @"c:\X_imp\" + usuario + @"\framePrinter.properties";
var host = "";
var nombreImp = "";
if (File.Exists(archivo))
{
var f = new StreamReader(archivo);
while (!f.EndOfStream)
{
var linea = f.ReadLine();
if (linea.Contains("frameConnectorService.PrinterDriver.drivers"))
{
var v = linea.Split('=');
host = v[1];
host = host.Substring(0, host.IndexOf(","));
}
if (host != "")
{
if (linea.IndexOf("frameConnectorService.PrinterDriver." + host + ".port", StringComparison.OrdinalIgnoreCase) >= 0)
{
var v = linea.Split('=');
nombreImp = v[1].Replace("\\", "");
}
}
}
} else
Log("NO EXISTE ARCHIVO DE CONFIG");
var ret = "";
if (host != "" && nombreImp != "")
{
_pathImpresora = @"\\" + host + @"\" + nombreImp;
ret = "OK";
}
else
{
_pathImpresora = "";
ret = "ERROR";
}
if (ret == "OK")
lineas = new List<Linea>();
return ret;
}
private void ImprimirLinea(string texto, Estilo estilo)
{
//(char)27 + (char)15 ---------------- condensado on
//(char)18 --------------------------- condensado off
//(char)27 + (char)87 + (char)49 ----- enlarged on
//(char)27 + (char)87 + (char)48 ----- enlarged off
//(char)27 + (char)69 ---------------- bold on
//(char)27 + (char)70 ---------------- bold off
if (texto.Trim() == "")
{
texto = "(";
estilo = Estilo.Normal;
}
else
texto = " " + texto;
switch (estilo)
{
case Estilo.Normal:
EjecutarComando("echo" + texto + " > " + _pathImpresora);
break;
case Estilo.Bold:
EjecutarComando("echo " + (char)27 + (char)69 + texto + (char)27 + (char)70 + " > " + _pathImpresora);
break;
case Estilo.Enlarged:
EjecutarComando("echo " + (char)27 + (char)87 + (char)49 + texto + (char)27 + (char)87 + (char)48 + " > " + _pathImpresora);
break;
case Estilo.Condensed:
EjecutarComando("echo " + (char)27 + (char)15 + texto + (char)18 + " > " + _pathImpresora);
break;
}
}
private void EjecutarComando(string comando) {
ProcessStartInfo processInfo;
Process proc;
_fin = false;
processInfo = new ProcessStartInfo("cmd.exe", (Convert.ToString("/c ") + comando));
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
processInfo.Verb = "runas";
proc = new Process();
proc.EnableRaisingEvents = true;
proc.StartInfo = processInfo;
proc.OutputDataReceived += OnOutputDataReceived;
proc.Exited += OnProcessExited;
proc.Start();
proc.BeginOutputReadLine();
while (!_fin) {
Thread.Sleep(1);
}
proc.Close();
}
private void OnProcessExited(object sender, EventArgs e) {
_fin = true;
}
private void OnOutputDataReceived(object sender, DataReceivedEventArgs e) {
}
public void Log(string texto)
{
var f = new StreamWriter("c:\\temp\\outLog.txt", true);
f.WriteLine(texto);
f.Close();
}
}
}
Version anterior:
Impresora.cs
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
using System.IO;
namespace X
{
public enum Estilo
{
Normal,
Bold,
Enlarged,
Condensed
}
public interface IImpresora
{
string Imprimir(string texto, string estilo);
void FormFeed();
void Log(string texto);
}
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Impresora : IImpresora
{
bool _fin = false;
public string Imprimir(string texto, string estilo)
{
if (estilo == "normal")
ImprimirLinea(texto, Estilo.Normal);
if (estilo == "bold")
ImprimirLinea(texto, Estilo.Bold);
if (estilo == "enlarged")
ImprimirLinea(texto, Estilo.Enlarged);
if (estilo == "condensed")
ImprimirLinea(texto, Estilo.Condensed);
return texto;
}
public void FormFeed()
{
EjecutarComando("echo " + "ABC" + (char)12 + "ABC" + " > \\\\X00762\\EPSON1");
}
private void ImprimirLinea(string texto, Estilo estilo)
{
//(char)27 + (char)15 ---------------- condensado on
//(char)18 --------------------------- condensado off
//(char)27 + (char)87 + (char)49 ----- enlarged on
//(char)27 + (char)87 + (char)48 ----- enlarged off
//(char)27 + (char)69 ---------------- bold on
//(char)27 + (char)70 ---------------- bold off
if (texto.Trim() == "")
{
texto = "(";
estilo = Estilo.Normal;
}
else
texto = " " + texto;
switch (estilo)
{
case Estilo.Normal:
EjecutarComando("echo" + texto + " > \\\\X00762\\EPSON1");
break;
case Estilo.Bold:
EjecutarComando("echo " + (char)27 + (char)69 + texto + (char)27 + (char)70 + " > \\\\X00762\\EPSON1");
break;
case Estilo.Enlarged:
EjecutarComando("echo " + (char)27 + (char)87 + (char)49 + texto + (char)27 + (char)87 + (char)48 + " > \\\\X00762\\EPSON1");
break;
case Estilo.Condensed:
EjecutarComando("echo " + (char)27 + (char)15 + texto + (char)18 + " > \\\\X00762\\EPSON1");
break;
}
}
private void EjecutarComando(string comando) {
ProcessStartInfo processInfo;
Process proc;
_fin = false;
processInfo = new ProcessStartInfo("cmd.exe", (Convert.ToString("/c ") + comando));
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
processInfo.Verb = "runas";
proc = new Process();
proc.EnableRaisingEvents = true;
proc.StartInfo = processInfo;
proc.OutputDataReceived += OnOutputDataReceived;
proc.Exited += OnProcessExited;
proc.Start();
proc.BeginOutputReadLine();
while (!_fin) {
Thread.Sleep(1);
}
proc.Close();
}
private void OnProcessExited(object sender, EventArgs e) {
_fin = true;
}
private void OnOutputDataReceived(object sender, DataReceivedEventArgs e) {
}
public void Log(string texto)
{
var f = new StreamWriter("c:\\temp\\outLog.txt", true);
if (texto.IndexOf('\f') >= 0)
f.WriteLine("FORM FEEED!!!!!!");
else
f.WriteLine(texto);
f.Close();
}
}
}
Tester.htm
<html>
<head>
<script language=JavaScript>
var imp = new ActiveXObject('X.Impresora');
alert(imp.Imprimir("Texto PRUEBA"));
</script>
</head>
<body>
<h1>Tester.htm</h1>
</body>
</html>
Fuente: http://forums.asp.net/post/2204437.aspx
Ir a prompt de visual studio 2013 (abrirlo como administrador)
Si no hay una strong key, generarla con:
sn -k keyImpresora.snk
cls
call "%VS120COMNTOOLS%..\Tools\vsvars32.bat"
csc /t:library Impresora.cs /keyfile:keyImpresora.snk
regasm Impresora.dll /tlb:ImpresoraNet.dll /codebase
Impresora.cs
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
using System.IO;
using System.Collections.Generic;
namespace X
{
public enum Estilo
{
Normal,
Bold,
Enlarged,
Condensed
}
public interface IImpresora
{
string Imprimir(string texto, string estilo);
void FormFeed();
void Log(string texto);
string Inicializar(string usuario);
void Agregar(string linea);
void Listar();
}
public class Linea
{
public string Texto {get; set;}
public string Estilo {get; set;}
}
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Impresora : IImpresora
{
bool _fin = false;
string _pathImpresora = "";
List<Linea> lineas;
public void Agregar(string linea)
{
var l = new Linea();
l.Texto = linea;
lineas.Add(l);
}
public void Listar()
{
var estilo = "normal";
var textoOk = "";
File.Delete("c:\\temp\\outLog.txt");
foreach (var l in lineas)
{
var xx = "";
xx = l.Texto;
xx = xx.Replace((char)13 + "" + (char)10, "");
if (xx.Contains(Convert.ToChar(27) + "(s3B") || xx.Contains(Convert.ToChar(27) + "(s0B"))
{
//evito estas lineas
} else
{
// var xx = l.Texto.Replace( Convert.ToChar(27) + "(s3B", "");
// xx = xx.Replace( Convert.ToChar(27) + "(s0B", "");
xx = xx.Replace( Convert.ToChar(27) + "E" + "", (char)27 + "" + (char)69 + "");
}
Log(xx);
}
EjecutarComando("type c:\\temp\\outLog.txt > " + _pathImpresora);
/*
foreach (var l in lineas)
{
textoOk = "";
for (int i=0; i<l.Texto.Length; i++)
{
if ((int)l.Texto[i] == 12)
{
textoOk += "[FORM FEED]";
i++;
}
if ((int)l.Texto[i] == 27)
{
i++;
if ((int)l.Texto[i] == 69)
{
estilo = "bold";
i++;
} else if ((int)l.Texto[i] == 70)
{
estilo = "normal";
i++;
}
}
textoOk += l.Texto[i];
}
//Log(textoOk + " - " + estilo );
}
*/
}
public string Imprimir(string texto, string estilo)
{
if (estilo == "normal")
ImprimirLinea(texto, Estilo.Normal);
if (estilo == "bold")
ImprimirLinea(texto, Estilo.Bold);
if (estilo == "enlarged")
ImprimirLinea(texto, Estilo.Enlarged);
if (estilo == "condensed")
ImprimirLinea(texto, Estilo.Condensed);
return texto;
}
public void FormFeed()
{
//para que funcione el form feed hay que poner algun caracter antes y despues (en este caso, el signo de menos)
EjecutarComando("echo -" + (char)12 + "- > " + _pathImpresora);
}
public string Inicializar(string usuario)
{
var archivo = @"c:\X_imp\" + usuario + @"\framePrinter.properties";
var host = "";
var nombreImp = "";
if (File.Exists(archivo))
{
var f = new StreamReader(archivo);
while (!f.EndOfStream)
{
var linea = f.ReadLine();
if (linea.Contains("frameConnectorService.PrinterDriver.drivers"))
{
var v = linea.Split('=');
host = v[1];
host = host.Substring(0, host.IndexOf(","));
}
if (host != "")
{
if (linea.IndexOf("frameConnectorService.PrinterDriver." + host + ".port", StringComparison.OrdinalIgnoreCase) >= 0)
{
var v = linea.Split('=');
nombreImp = v[1].Replace("\\", "");
}
}
}
} else
Log("NO EXISTE ARCHIVO DE CONFIG");
var ret = "";
if (host != "" && nombreImp != "")
{
_pathImpresora = @"\\" + host + @"\" + nombreImp;
ret = "OK";
}
else
{
_pathImpresora = "";
ret = "ERROR";
}
if (ret == "OK")
lineas = new List<Linea>();
return ret;
}
private void ImprimirLinea(string texto, Estilo estilo)
{
//(char)27 + (char)15 ---------------- condensado on
//(char)18 --------------------------- condensado off
//(char)27 + (char)87 + (char)49 ----- enlarged on
//(char)27 + (char)87 + (char)48 ----- enlarged off
//(char)27 + (char)69 ---------------- bold on
//(char)27 + (char)70 ---------------- bold off
if (texto.Trim() == "")
{
texto = "(";
estilo = Estilo.Normal;
}
else
texto = " " + texto;
switch (estilo)
{
case Estilo.Normal:
EjecutarComando("echo" + texto + " > " + _pathImpresora);
break;
case Estilo.Bold:
EjecutarComando("echo " + (char)27 + (char)69 + texto + (char)27 + (char)70 + " > " + _pathImpresora);
break;
case Estilo.Enlarged:
EjecutarComando("echo " + (char)27 + (char)87 + (char)49 + texto + (char)27 + (char)87 + (char)48 + " > " + _pathImpresora);
break;
case Estilo.Condensed:
EjecutarComando("echo " + (char)27 + (char)15 + texto + (char)18 + " > " + _pathImpresora);
break;
}
}
private void EjecutarComando(string comando) {
ProcessStartInfo processInfo;
Process proc;
_fin = false;
processInfo = new ProcessStartInfo("cmd.exe", (Convert.ToString("/c ") + comando));
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
processInfo.Verb = "runas";
proc = new Process();
proc.EnableRaisingEvents = true;
proc.StartInfo = processInfo;
proc.OutputDataReceived += OnOutputDataReceived;
proc.Exited += OnProcessExited;
proc.Start();
proc.BeginOutputReadLine();
while (!_fin) {
Thread.Sleep(1);
}
proc.Close();
}
private void OnProcessExited(object sender, EventArgs e) {
_fin = true;
}
private void OnOutputDataReceived(object sender, DataReceivedEventArgs e) {
}
public void Log(string texto)
{
var f = new StreamWriter("c:\\temp\\outLog.txt", true);
f.WriteLine(texto);
f.Close();
}
}
}
Version anterior:
namespace X
[ClassInterface(ClassInterfaceType.AutoDual)]
if (estilo == "bold")
Tester.htm
<html>
<head>
<script language=JavaScript>
var imp = new ActiveXObject('X.Impresora');
alert(imp.Imprimir("Texto PRUEBA"));
</script>
</head>
<body>
<h1>Tester.htm</h1>
</body>
</html>
Fuente: http://forums.asp.net/post/2204437.aspx
Enviar directo a la impresora desde C# (raw printing)
Código Html
<body>
<object
name="Hello World"
classid="clsid:E86A9038-368D-4e8f-B389-FDEF38935B2F"
codebase="http://localhost/bin/Debug/Test.ActiveX.dll">
</object>
<script type="text/javascript">
var hw = new ActiveXObject("Test.ActiveX.PruebaX");
alert( hw.imprimir() );
</script>
</body>
Código C#
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Reflection;
using System.Diagnostics;
namespace PruebaX
{
[Guid("E86A9038-368D-4e8f-B389-FDEF38935B2F")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[ComVisible(true)]
public interface IHelloWorld
{
[DispId(0)]
string Prueba();
[DispId(1)]
string Imprimir();
}
[ComVisible(true)]
[ProgId("Test.ActiveX.PruebaX")]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(IHelloWorld))]
public class HelloWorld : IHelloWorld
{
[ComRegisterFunction()]
public static void RegisterClass(string key)
{
// Strip off HKEY_CLASSES_ROOT\ from the passed key as I don't need it
StringBuilder sb = new StringBuilder(key);
sb.Replace(@"HKEY_CLASSES_ROOT\ ", ""); // <-- extra space to preserve prettify only.. not in the real code
// Open the CLSID\{guid} key for write access
using (RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true))
{
// And create the 'Control' key - this allows it to show up in
// the ActiveX control container
using (RegistryKey ctrl = k.CreateSubKey("Control"))
{
ctrl.Close();
}
// Next create the CodeBase entry - needed if not string named and GACced.
using (RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true))
{
inprocServer32.SetValue("CodeBase", Assembly.GetExecutingAssembly().CodeBase);
inprocServer32.Close();
}
// Finally close the main key
k.Close();
}
}
public string Prueba()
{
return "Prueba";
}
{
EjecutarComando("dir c:\\temp > " + "\"" + "\\\\X00895\\Brother HL-2270DW series" + "\"");
return "Impresion enviada";
}
private void EjecutarComando(string comando)
{
ProcessStartInfo processInfo;
Process proc;
processInfo = new ProcessStartInfo("cmd.exe", (Convert.ToString("/c ") + comando));
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
processInfo.Verb = "runas";
proc = new Process();
proc.EnableRaisingEvents = true;
proc.StartInfo = processInfo;
proc.Start();
proc.BeginOutputReadLine();
proc.Close();
}
}
}
Delay sign a DLL - Firmar una dll con SN y MsBuild desde linea de comando
call "%VS120COMNTOOLS%..\Tools\vsvars32.bat"
IF NOT EXIST "C:\temp\Generados\outGAC\Signed" mkdir "C:\temp\Generados\outGAC\Signed"
IF EXIST "C:\temp\Generados\outGAC\Signed\LibX.dll" del "C:\temp\Generados\outGAC\Signed\LibX.dll"
msbuild.exe "C:\crusso\X\fuentes\desarrollo\_DLL\LibX\LibX.vbproj" /p:TargetFrameworkVersion=v4.5.1;Configuration=Release /tv:4.0 /t:Rebuild /p:OutDir="C:\temp\Generados\outGAC" /p:PreBuildEvent= /p:PostBuildEvent= /p:SignAssembly=true /p:AssemblyOriginatorKeyFile="c:\crusso\X\fuentes\desarrollo\_KEYSTORE\Desarrollo\keyLibX.snk" /p:DelaySign=true
sn -R "C:\temp\Generados\outGAC\LibX.dll" "c:\crusso\X\fuentes\desarrollo\_KEYSTORE\Desarrollo\keyLibX.snk"
gacutil.exe /i "C:\temp\Generados\outGAC\LibX.dll" /f
IF NOT EXIST "C:\temp\Generados\outGAC\Signed" mkdir "C:\temp\Generados\outGAC\Signed"
IF EXIST "C:\temp\Generados\outGAC\Signed\LibX.dll" del "C:\temp\Generados\outGAC\Signed\LibX.dll"
msbuild.exe "C:\crusso\X\fuentes\desarrollo\_DLL\LibX\LibX.vbproj" /p:TargetFrameworkVersion=v4.5.1;Configuration=Release /tv:4.0 /t:Rebuild /p:OutDir="C:\temp\Generados\outGAC" /p:PreBuildEvent= /p:PostBuildEvent= /p:SignAssembly=true /p:AssemblyOriginatorKeyFile="c:\crusso\X\fuentes\desarrollo\_KEYSTORE\Desarrollo\keyLibX.snk" /p:DelaySign=true
sn -R "C:\temp\Generados\outGAC\LibX.dll" "c:\crusso\X\fuentes\desarrollo\_KEYSTORE\Desarrollo\keyLibX.snk"
gacutil.exe /i "C:\temp\Generados\outGAC\LibX.dll" /f
Crear un drive USB bootable sin utilizar ningùn software
Step 1: Using DISKPART command
- Insert your USB flash drive to your running computer. As the first step, we need to run Command Prompt as administrator. To do this, we need to find cmd by typing 'cmd' in the search box on Windows Start Menu. After search result for 'cmd' appears, right click on it and select "Run as administrator".
- Type 'diskpart' on Command Prompt (without quotes) and hit Enter. Wait for a while until the DISKPART program run.
- Type 'list disk' to view active disks on your computer and hit Enter. There would be seen that the active disks shown as Disk 0 for hard drive and Disk 1 for your USB flashdrive with its total capacity.
- Type 'select disk 1' to determine that disk 1 would be processed in the next step then hit Enter.
- Type 'clean' and hit Enter to remove all of data in the drive.
- Type 'create partition primary' and hit Enter. Creating a primary partition and further recognized by Windows as 'partition 1'.
- Type 'select partition 1' an hit Enter. Choosing the 'partition 1' for setting up it as an active partition.
- Type 'active' and hit Enter. Activating current partition.
- Type 'format fs=ntfs quick' and hit Enter. Formatting current partition as NTFS file system quickly.
- Type 'exit' and hit Enter. Leaving DISKPART program but don't close the Command Prompt instead. We would still need it for next proces
Step 2: create the boot sector
Step 2: Creating Boot Sector
Let us assume that the flash / USB drive is the D: drive and the DVD installer located on drive F :. The first step, we will navigate Command Prompt to set installation DVD as its active directory.
- By default, Command Prompt's active directory for Administrator permission is on C:\Windows\System32>. We will navigate Command Prompt to set on DVD (F:) as its active directory. Just type 'f:' then hit Enter, and the active directory changed to F:.
- Type 'cd boot' and hit Enter. Active directory changed to F:\boot>.
- Type 'bootsect /nt60 d:' and hit Enter. Creating boot sector on D: drive (USB flash drive).
- Type 'exit' and hit Enter to close the Command Prompt. Until this step we have made a bootable USB drive sucessfully, and the flash drive is ready to be used as a boot media.
Step 3: Copying Installation Files
xcopy f:\*.* d:\ /E /H /F
Fuente: http://www.instructables.com/id/How-to-Create-a-Bootable-USB-Drive-Without-Using-A/?ALLSTEPS
Desinstalar assembly del GAC de .NET
Ejemplo:
Desinstalar la LibX de la carpeta GAC de .NET:
gacutil /u "LibX,Version=3.0.0.0, Culture=neutral, PublicKeyToken=2ebfdc71997c1f40"
la version a especificar en el gacutil es
v4.0_3.0.0.0__2ebfdc71997c1f40
y el token:
v4.0_3.0.0.0__2ebfdc71997c1f40
Suscribirse a:
Comentarios (Atom)
