Sha256: 947a479c2e08d3a8900ed237651ad95444d72f2e0377a2ad8b5d43f41438803d

Contents?: true

Size: 1.06 KB

Versions: 38

Compression:

Stored size: 1.06 KB

Contents

# Function to check whether machine is currently shutting down
function ShuttingDown {
    [string]$sourceCode = @"
using System;
using System.Runtime.InteropServices;

namespace Vagrant {
    public static class RemoteManager {
        private const int SM_SHUTTINGDOWN = 0x2000;

        [DllImport("User32.dll", CharSet = CharSet.Unicode)]
        private static extern int GetSystemMetrics(int Index);

        public static bool Shutdown() {
            return (0 != GetSystemMetrics(SM_SHUTTINGDOWN));
        }
    }
}
"@
    $type = Add-Type -TypeDefinition $sourceCode -PassThru
    return $type::Shutdown()
}

if (ShuttingDown) {
  exit 1
} else {
  # See if a reboot is scheduled in the future by trying to schedule a reboot
  . shutdown.exe -f -r -t 60

  if ($LASTEXITCODE -eq 1190) {
    # reboot is already pending
    exit 2
  }

  if ($LASTEXITCODE -eq 1115) {
    # A system shutdown is in progress
    exit 2
  }

  # Remove the pending reboot we just created above
  if ($LASTEXITCODE -eq 0) {
    . shutdown.exe -a
  }
}

# no reboot in progress or scheduled
exit 0

Version data entries

38 entries across 34 versions & 5 rubygems

Version Path
vagrant-unbundled-2.2.0.0 plugins/guests/windows/scripts/reboot_detect.ps1
vagrant-unbundled-2.1.4.0 plugins/guests/windows/scripts/reboot_detect.ps1
vagrant-unbundled-2.1.2.0 plugins/guests/windows/scripts/reboot_detect.ps1
vagrant-packet-0.1.2 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/guests/windows/scripts/reboot_detect.ps1
vagrant-packet-0.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/guests/windows/scripts/reboot_detect.ps1
vagrant-packet-0.1.2 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/guests/windows/scripts/reboot_detect.ps1
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/plugins/guests/windows/scripts/reboot_detect.ps1
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/plugins/guests/windows/scripts/reboot_detect.ps1
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/plugins/guests/windows/scripts/reboot_detect.ps1
vagrant-unbundled-2.1.1.0 plugins/guests/windows/scripts/reboot_detect.ps1
vagrant-unbundled-2.0.4.0 plugins/guests/windows/scripts/reboot_detect.ps1
vagrant-unbundled-2.0.3.0 plugins/guests/windows/scripts/reboot_detect.ps1
vagrant-aws-detiber-0.7.2.pre.4 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/guests/windows/scripts/reboot_detect.ps1
vagrant-aws-detiber-0.7.2.pre.3 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/guests/windows/scripts/reboot_detect.ps1
vagrant-aws-detiber-0.7.2.pre.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-419afb4dcffe/plugins/guests/windows/scripts/reboot_detect.ps1
vagrant-unbundled-2.0.2.0 plugins/guests/windows/scripts/reboot_detect.ps1
vagrant-unbundled-2.0.1.0 plugins/guests/windows/scripts/reboot_detect.ps1
vagrant-aws-mkubenka-0.7.2.pre.22 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-f3fdbf414272/plugins/guests/windows/scripts/reboot_detect.ps1