Skip to content

Instantly share code, notes, and snippets.

@pcrama
pcrama / RunAsFromFile.cs
Last active January 18, 2022 14:28
Read Windows user name & password from plain text file and execute command with those credentials
// .\CompileSimply-CSharp.ps1 . RunAsFromFile.cs "64" "System.Diagnostics.Process.dll"
//
// From https://social.technet.microsoft.com/Forums/lync/en-US/132e170f-e3e8-4178-9454-e37bfccd39ea/startprocess-verb-runas-amp-credential
// $pw= convertto-securestring "PASSWORD" -asplaintext –force
// $pp = new-object -typename System.Management.Automation.PSCredential -argumentlist "DOMAIN\user",$pw
// $script = "c:\pathtoscript.ps1"
// Start-Process powershell -Credential $pp -ArgumentList '-noprofile -command &{Start-Process $script -verb runas}'
// $pw= convertto-securestring "PASSWORD" -asplaintext –force
// $pp = new-object -typename System.Management.Automation.PSCredential -argumentlist "DOMAIN\user",$pw
// $script = "c:\pathtoscript.ps1"
@pcrama
pcrama / Compile-CLIUtils.ps1
Last active January 16, 2020 11:36
Calls CompileSimply-CSharp for the different CLI utils
Param(
[string]$dir,
[string]$x64 # "64" for x64 compiler, "" for 32bit
)
. "$dir\CompileSimply-CSharp.ps1" $dir wdscli.cs $x64 ""
. "$dir\CompileSimply-CSharp.ps1" $dir cliphtml.cs $x64 WPF\PresentationCore.dll
. "$dir\CompileSimply-CSharp.ps1" $dir RunAsFromFile.cs $x64 System.Diagnostics.Process.dll
@pcrama
pcrama / cliphtml.cs
Last active December 2, 2021 10:53
Sets clipboard content to HTML (to export org mode as rich text to the clipboard)
/* Compiling this needs a reference to the PresentationCore dll:
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" "/reference:c:\windows\Microsoft.NET\Framework\v4.0.30319\WPF\PresentationCore.dll" "/out:cliphtml.exe" cliphtml.cs
*/
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows; // Needed to access the clipboard.
namespace SetClipBoardToHtml
@pcrama
pcrama / CompileSimply-CSharp.ps1
Last active January 16, 2018 21:36
Simplistic PowerShell script to call latest C# compiler on a simple .cs file
Param(
[string]$dir,
[string]$f,
[string]$x64, # "64" for x64 compiler, "" for 32bit
[string]$extraRef
)
Write-Host 'looking for C# compiler' -nonewline
# Get latest directory into $v
$v = ""
@pcrama
pcrama / wdscli.cs
Created March 16, 2017 21:02
Simplistic command line interface for Windows Search
using System.Data.OleDb;
using System;
class WDSCli
{
static void Main(string[] args)
{
int maxResults = 200; // Don't output more than this amount of results
bool help = args.Length == 0;
string searchRoot = ""; // limit scope of search