07 Jul 2011 @ 1:47 AM 

Courtesy of the long list of things you probably shouldn’t do but will anyway heres how one goes about implementing mutex locking between multiple powershell scripts.

<#
1. Instantiate Mutex Object using new-object syntax
2. Use the same "DesiredMutexName" across scripts.  Or move mutex logic into a shared script included by each script desiring access to these mutexes.  (. Path\ScriptWithMutexLocks.ps1)
#>
$mutex = new-object -TypeName System.Threading.Mutex -ArgumentList $false, "YourDesiredMutexName";

# 3. Lock Access to critical sections in each script
$result = $mutex.WaitOne();
<#
Critical Section
#>

#4 Release
$mutex.ReleaseMutex();
<#
Script Specific / Non viotile section
#>

. . . Enjoy

Posted By: admin
Last Edit: 02 Dec 2011 @ 04:27 PM

EmailPermalink
Tags
Categories: Uncategorized


 

Responses to this post » (None)

 
Post a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">


 Last 50 Posts
 Back
Change Theme...
  • Users » 75
  • Posts/Pages » 14
  • Comments » 10
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

About



    No Child Pages.

About



    No Child Pages.

Resume



    No Child Pages.