Advertisement
rilo

Check if perl script is already running (Win32)

Mar 5th, 2012
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.38 KB | None | 0 0
  1. use Win32::Mutex;
  2. my ($name) = ( $0 =~ /(.*)\.pl/ );
  3. $name =~ s/^(.*\\)//;    # erase full path names, they give problems creating mutexes
  4. ($name) = ( $^X =~ /(.*)\.exe/ ) if ( $name eq '' ); # Compatibility for perl2exe
  5. my $mutex;
  6. Win32::Mutex::Create( $mutex, 0, $name );
  7. if (Win32::GetLastError) {
  8.   # mutex already exists - another instance of this script is running
  9.   exit;
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement