Skip to content

Instantly share code, notes, and snippets.

def createCOMObject(progID):
type = System.Type.GetTypeFromProgID(progID)
if None == type:
return None
return System.Activator.CreateInstance(type)
...
obj = createCOMObject("Shell.Application")
def getLogicalDrives():
return System.IO.Directory.GetLogicalDrives()
import clr
clr.AddReference("System.Management")
import System
from System.Management import *
logicalDrives = None
def getLogicalDrives():
global logicalDrives
if None == logicalDrives:
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import *
print dir()
import clr
clr.AddReference("System.Windows.Forms")
import System.Windows.Forms
_f = None
for _x in dir(System.Windows.Forms):
try:
_f = System.Windows.Forms.__dict__[_x]
if callable(_f):
globals()[_x] = _f
except:
import clr
clr.AddReference("System.Management")
from System.Management import *
from System import Console
def EvLogEventArrived(sender, e):
##Get the Event object and display it
for pd in e.NewEvent.Properties:
Console.WriteLine("{0} = {1}", pd.Name, pd.Value)
@SteveGilham
SteveGilham / gist:9a79a3e76220113f1c00
Created April 14, 2015 20:25
Embed powershell in FePy
import clr
import System.Collections
clr.AddReference("System.Management.Automation")
from System.Management.Automation import *
from System.Management.Automation.Runspaces import *
import System.IO
def RunScript(script):
runspace = RunspaceFactory.CreateRunspace()
runspace.Open()
[reflection.assembly]::LoadFrom("C:\IronPython-1.1\IronPython.dll")
$pythonEngine = New-Object -TypeName "IronPython.Hosting.PythonEngine"
$pythonEngine.Execute("print 'Hello World!'")
[reflection.assembly]::LoadFrom("C:\IronPython-2.0A7\IronPython.dll")
$pythonEngine = [ironpython.hosting.pythonengine]::CurrentEngine
$pythonEngine.Execute("print 'Hello World!'")
using System;
using System.Collections.Generic;
using System.Text;
namespace negatives
{
class Program
{
static void Main(string[] args)
{