version inicial
commit
a6ed8484a5
|
|
@ -0,0 +1,4 @@
|
||||||
|
/.vs/*
|
||||||
|
/Notifica/bin/*
|
||||||
|
/MigrationBackup/*
|
||||||
|
/Notifica/obj/*
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.10.35013.160
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notifica", "Notifica\Notifica.csproj", "{F4DFCA6B-D27D-4F2C-9ED6-39751A005E45}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{F4DFCA6B-D27D-4F2C-9ED6-39751A005E45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{F4DFCA6B-D27D-4F2C-9ED6-39751A005E45}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{F4DFCA6B-D27D-4F2C-9ED6-39751A005E45}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{F4DFCA6B-D27D-4F2C-9ED6-39751A005E45}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {B8E9237F-F36B-43F0-A550-8EB9021E6295}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<configuration>
|
||||||
|
<startup>
|
||||||
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
|
||||||
|
</startup>
|
||||||
|
<appSettings>
|
||||||
|
<add key="usuario" value="Gerardo"/>
|
||||||
|
<add key="dominio" value=""/>
|
||||||
|
<add key="clave" value="D7+ZrJAX"/>
|
||||||
|
</appSettings>
|
||||||
|
</configuration>
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
using Microsoft.Toolkit.Uwp.Notifications;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace Notifica
|
||||||
|
{
|
||||||
|
internal class Notifica : impersonalizacionTarea
|
||||||
|
{
|
||||||
|
public string msg { get; set; }
|
||||||
|
public void tareaImpersonalizada()
|
||||||
|
{
|
||||||
|
MessageBox.Show(msg);
|
||||||
|
/*
|
||||||
|
new ToastContentBuilder()
|
||||||
|
.AddArgument("action", "viewConversation")
|
||||||
|
.AddArgument("conversationId", 9813)
|
||||||
|
.AddText("Aviso")
|
||||||
|
.AddText(msg)
|
||||||
|
.Show();*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,70 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{F4DFCA6B-D27D-4F2C-9ED6-39751A005E45}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<RootNamespace>Notifica</RootNamespace>
|
||||||
|
<AssemblyName>Notifica</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
|
<Deterministic>true</Deterministic>
|
||||||
|
<NuGetPackageImportStamp>
|
||||||
|
</NuGetPackageImportStamp>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<ApplicationIcon>solologo_ico.ico</ApplicationIcon>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="PresentationFramework" />
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Configuration" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Net.Http" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="impersonalizacionExe.cs" />
|
||||||
|
<Compile Include="Notifica.cs" />
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="App.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications">
|
||||||
|
<Version>7.1.3</Version>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="solologo_ico.ico" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||||
|
<StartArguments>"Notificacion de prueba"</StartArguments>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
using Microsoft.Toolkit.Uwp.Notifications;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Notifica
|
||||||
|
{
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
if (args.Count() <= 0)
|
||||||
|
return;
|
||||||
|
var Notificador = new impersonalizacionExe();
|
||||||
|
var Notificacion = new Notifica();
|
||||||
|
Notificador.Tarea = Notificacion;
|
||||||
|
|
||||||
|
Notificador.Usuario=ConfigurationManager.AppSettings["usuario"];
|
||||||
|
Notificador.Dominio = ConfigurationManager.AppSettings["dominio"];
|
||||||
|
Notificador.Clave = ConfigurationManager.AppSettings["clave"];
|
||||||
|
foreach (string arg in args)
|
||||||
|
{
|
||||||
|
Notificacion.msg = arg;
|
||||||
|
string res=Notificador.runImpersonal();
|
||||||
|
|
||||||
|
var sw = new StreamWriter("F:\\desa\\v2022\\Notifica\\Notifica\\bin\\Release\\Sample.txt");
|
||||||
|
if (res != "")
|
||||||
|
sw.WriteLine(res);
|
||||||
|
else
|
||||||
|
sw.WriteLine("ok");
|
||||||
|
sw.Close();
|
||||||
|
|
||||||
|
|
||||||
|
//string mens = ConfigurationManager.AppSettings["MensajeAviso"];
|
||||||
|
/*new ToastContentBuilder()
|
||||||
|
.AddArgument("action", "viewConversation")
|
||||||
|
.AddArgument("conversationId", 9813)
|
||||||
|
.AddText("Aviso")
|
||||||
|
.AddText(arg)
|
||||||
|
.Show();*/
|
||||||
|
// Not seeing the Show() method? Make sure you have version 7.0, and if you're using .NET 6 (or later), then your TFM must be net6.0-windows10.0.17763.0 or greater
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// La información general de un ensamblado se controla mediante el siguiente
|
||||||
|
// conjunto de atributos. Cambie estos valores de atributo para modificar la información
|
||||||
|
// asociada a un ensamblado.
|
||||||
|
[assembly: AssemblyTitle("Notifica")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("Notifica")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2024")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Si establece ComVisible en false, los tipos de este ensamblado no estarán visibles
|
||||||
|
// para los componentes COM. Si es necesario obtener acceso a un tipo en este ensamblado desde
|
||||||
|
// COM, establezca el atributo ComVisible en true en este tipo.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// El siguiente GUID sirve como id. de typelib si este proyecto se expone a COM.
|
||||||
|
[assembly: Guid("f4dfca6b-d27d-4f2c-9ed6-39751a005e45")]
|
||||||
|
|
||||||
|
// La información de versión de un ensamblado consta de los cuatro valores siguientes:
|
||||||
|
//
|
||||||
|
// Versión principal
|
||||||
|
// Versión secundaria
|
||||||
|
// Número de compilación
|
||||||
|
// Revisión
|
||||||
|
//
|
||||||
|
// Puede especificar todos los valores o usar los valores predeterminados de número de compilación y de revisión
|
||||||
|
// utilizando el carácter "*", como se muestra a continuación:
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
|
|
@ -0,0 +1,111 @@
|
||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Security.Principal;
|
||||||
|
using System.Security.Permissions;
|
||||||
|
using Microsoft.Win32.SafeHandles;
|
||||||
|
using System.Runtime.ConstrainedExecution;
|
||||||
|
using System.Security;
|
||||||
|
using Windows.System;
|
||||||
|
using System.Runtime.Remoting.Messaging;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Notifica
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public interface impersonalizacionTarea
|
||||||
|
{
|
||||||
|
void tareaImpersonalizada();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class impersonalizacionExe
|
||||||
|
{
|
||||||
|
public string Usuario { get; set; }
|
||||||
|
public string Dominio { get; set; }
|
||||||
|
|
||||||
|
public string Clave { get; set; }
|
||||||
|
|
||||||
|
public impersonalizacionTarea Tarea { get; set; }
|
||||||
|
|
||||||
|
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||||
|
private static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword,
|
||||||
|
int dwLogonType, int dwLogonProvider, out SafeTokenHandle phToken);
|
||||||
|
|
||||||
|
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
|
||||||
|
public extern static bool CloseHandle(IntPtr handle);
|
||||||
|
|
||||||
|
private void run()
|
||||||
|
{
|
||||||
|
Tarea.tareaImpersonalizada();
|
||||||
|
}
|
||||||
|
//si va bien devuelve ""
|
||||||
|
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
|
||||||
|
public string runImpersonal()
|
||||||
|
{
|
||||||
|
SafeTokenHandle safeTokenHandle;
|
||||||
|
var res = "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
const int LOGON32_PROVIDER_DEFAULT = 0;
|
||||||
|
//This parameter causes LogonUser to create a primary token.
|
||||||
|
const int LOGON32_LOGON_INTERACTIVE = 2;
|
||||||
|
|
||||||
|
// Call LogonUser to obtain a handle to an access token.
|
||||||
|
bool returnValue = LogonUser(Usuario, Dominio, Clave,
|
||||||
|
LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT,
|
||||||
|
out safeTokenHandle);
|
||||||
|
|
||||||
|
|
||||||
|
if (false == returnValue)
|
||||||
|
{
|
||||||
|
int ret = Marshal.GetLastWin32Error();
|
||||||
|
res=string.Format("LogonUser failed with error code : {0}", ret);
|
||||||
|
}
|
||||||
|
using (safeTokenHandle)
|
||||||
|
{
|
||||||
|
// Check the identity.
|
||||||
|
/*Console.WriteLine("Before impersonation: "
|
||||||
|
+ WindowsIdentity.GetCurrent().Name);*/
|
||||||
|
// Use the token handle returned by LogonUser.
|
||||||
|
using (WindowsIdentity newId = new WindowsIdentity(safeTokenHandle.DangerousGetHandle()))
|
||||||
|
{
|
||||||
|
using (WindowsImpersonationContext impersonatedUser = newId.Impersonate())
|
||||||
|
{
|
||||||
|
res = res + "identidad: " + WindowsIdentity.GetCurrent().Name;
|
||||||
|
run();
|
||||||
|
// Check the identity.
|
||||||
|
/*Console.WriteLine("After impersonation: "
|
||||||
|
+ WindowsIdentity.GetCurrent().Name);*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Releasing the context object stops the impersonation
|
||||||
|
// Check the identity.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
res=res+"excepcion:"+ex.Message;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public sealed class SafeTokenHandle : SafeHandleZeroOrMinusOneIsInvalid
|
||||||
|
{
|
||||||
|
private SafeTokenHandle()
|
||||||
|
: base(true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport("kernel32.dll")]
|
||||||
|
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||||
|
[SuppressUnmanagedCodeSecurity]
|
||||||
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
|
private static extern bool CloseHandle(IntPtr handle);
|
||||||
|
|
||||||
|
protected override bool ReleaseHandle()
|
||||||
|
{
|
||||||
|
return CloseHandle(handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 114 KiB |
Loading…
Reference in New Issue