Skip to content

Instantly share code, notes, and snippets.

View amgdy's full-sized avatar

Ahmed Magdy amgdy

View GitHub Profile
public static void RunAsDesktopUser(string fileName)
{
if (string.IsNullOrWhiteSpace(fileName))
throw new ArgumentException("Value cannot be null or whitespace.", nameof(fileName));
// To start process as shell user you will need to carry out these steps:
// 1. Enable the SeIncreaseQuotaPrivilege in your current token
// 2. Get an HWND representing the desktop shell (GetShellWindow)
// 3. Get the Process ID(PID) of the process associated with that window(GetWindowThreadProcessId)
// 4. Open that process(OpenProcess)

This Gist file is dedicated for the Ask me anything session. The next session will be on the June 7th - 12:00 AM Tunis localtime.

Just ask your question here 😁

See you soon ! 🙋

@cmw2
cmw2 / Startup.cs
Created February 15, 2019 20:43
OWIN Startup class to use AAD.
using Owin;
namespace WindowsAuthAppToAADDemo
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
@nblumhardt
nblumhardt / Program.cs
Last active September 4, 2024 10:05
Enrich.WithCaller()
using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using Serilog;
using Serilog.Configuration;
using Serilog.Core;
using Serilog.Events;
namespace ConsoleApp24
@0xced
0xced / FromHeader.cs
Last active November 1, 2023 06:20
[FromHeader] parameter binding and attribute for ASP.NET Web API + Swashbuckle integration
using System;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Metadata;
@blowdart
blowdart / UpdateIISExpressSSLForChome.ps1
Last active October 7, 2021 10:59
IIS Express certs (for now) don't contain SAN strings. This makes Chrome unhappy. Make Chrome happy again with a new organic, artisanal, gluten free HTTPS certificate.
# Create a new self signed HTTPS Certificate for IIS Express
# Crafted with all organic, GMO, gluten free ingreditations
# with an artisinal SAN to make Chrome 58 onwards happy.
#
# See https://bugs.chromium.org/p/chromium/issues/detail?id=308330
#
# Run this at an administrative PowerShell prompt.
#
# You will be prompted to trust a new certificate via a windows dialog.
# Click yes otherwise Visual Studio will not be able to determine your
@jbratu
jbratu / setupiisforsslperfectforwardsecrecy_v17.ps1
Last active August 6, 2024 17:23
Great powershell script for tightening HTTPS security on IIS and disabling insecure protocols and ciphers. Very useful on core installations.
# Copyright 2019, Alexander Hass
# https://www.hass.de/content/setup-microsoft-windows-or-iis-ssl-perfect-forward-secrecy-and-tls-12
#
# After running this script the computer only supports:
# - TLS 1.2
#
# Version 3.0.1, see CHANGELOG.txt for changes.
Write-Host 'Configuring IIS with SSL/TLS Deployment Best Practices...'
Write-Host '--------------------------------------------------------------------------------'
@mp4096
mp4096 / ppt2pdf.ps1
Created April 28, 2016 10:56
Batch convert PowerPoint files to PDF
# Batch convert all .ppt/.pptx files encountered in folder and all its subfolders
# The produced PDF files are stored in the invocation folder
#
# Adapted from http://stackoverflow.com/questions/16534292/basic-powershell-batch-convert-word-docx-to-pdf
# Thanks to MFT, takabanana, ComFreek
#
# If PowerShell exits with an error, check if unsigned scripts are allowed in your system.
# You can allow them by calling PowerShell as an Administrator and typing
# ```
# Set-ExecutionPolicy Unrestricted
@richlander
richlander / dotnet-crypto-46.cs
Last active June 4, 2022 18:45
.NET Cryptography Updates for the .NET Framework 4.6
// Example 1: Signing a byte[] using PKCS#1 v1.5 padding and a SHA-256 hash
// 4.5:
public static byte[] SignDataPkcs1Sha256(X509Certificate2 cert, byte[] data)
{
// X509Certificate2.PrivateKey returns the same object across multiple calls,
// so it shouldn't be Disposed independent of the X509Certificate2 object.
//
// The RSA base class doesn't expose any signature-based methods.
// The PrivateKey property returns AsymmetricAlgorithm, so really this call should be
@davidfowl
davidfowl / dotnetlayout.md
Last active September 17, 2024 18:14
.NET project structure
$/
  artifacts/
  build/
  docs/
  lib/
  packages/
  samples/
  src/
 tests/