Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Anchor
TOC
TOC
Include Page
KBCOMMON:KB-CSSstyle
KBCOMMON:KB-CSSstyle

...

Contents

Table of Contents
excludeContents
stylesquare

Principle

...

TO BE COMPLETED

expect mode preparation

→ none

rsh mode

→ add "SYSTEM" user in proxy/VMS or .rhosts/Tru64    (warning) "SYSTEM" not "system"

...

Using the "Local Group Policy Editor", it is possible to add the execution of a Powershell script at Windows shutdown. As this operation is performed with the "system" account, some operations have to be performed depending on the method chosen (opa0, rsh or ssh).

Warning

Please note shutdown scripts are executed when the shutdown is executed either from the "Windows Start" menu or using the shutdown command line. They are not always executed when clicking on the "Restart" button from the Windows Update tool.

opa0 mode preparation

If the combination of username/password is used, there is no need for configuration change.

If an encrypted file is used to store the password using the "cryptedpsys" parameter, it must be created on a session as "system" account.

To do so, open a cmd.exe window as Administrator and run the following command:

C:\WINDOWS\system32>C:\Charon\psexec.exe -i -s cmd.exe

A new window will popup. To check you're connected as "system", run:

C:\WINDOWS\system32>whoami
nt authority\system

Run the following command to create the encrypted file:

C:\Users\Spock> powershell -command "ConvertTo-SecureString -String '<password>' -AsPlainText -Force ^
More? | ConvertFrom-SecureString | Out-File '<full path to the file>'"

Example:

C:\Users\Spock> powershell -command "ConvertTo-SecureString -String '12345' -AsPlainText -Force ^
More? | ConvertFrom-SecureString | Out-File 'c:\charon\msds20vmspwd.txt'"


Div
classpagebreak


Run the Powershell script in check mode:

C:\WINDOWS\system32>powershell -file c:\charon\charon_cleanshutdown.ps1 -config c:\charon\myds20vms.ini -check

then check the "OPA0 was successful" message is displayed followed by "Command successfully completed."

Note

It is recommended to move the psexec.exe program file to a secured folder or to remove it when it is no more needed (check completed)

rsh mode preparation

Warning

A proxy has to be defined at OpenVMS level hence the local "system" user must be specified. This user name is translated depending on the language of the Windows distribution.

It is then highly recommended to install an English version of Windows to avoid issues with accents and non standard characters when creating this proxy.

Execute the same operations as described in chapter "Using rsh" for Tru64 or VMS to enable remote connection for the "SYSTEM" user.

(warning) This is case sensitive so for Tru64, specify "SYSTEM" and not "system" in the .rhosts file

It is highly recommended to test the execution of the script in check mode while connected as "system" account. To do so, use the psexec.exe program file provided in the kit or download it from the Microsoft Sysinternals page.

Open a cmd.exe window as Administrator and run the following command:

C:\WINDOWS\system32>C:\Charon\psexec.exe -i -s cmd.exe

...

ssh mode

...

A new window will popup. To check you're connected as "system", run:

C:\WINDOWS\system32>whoami
nt authority\system

Run the Powershell script in check mode:

C:\WINDOWS\system32>powershell -file c:\charon\charon_cleanshutdown.ps1 -config c:\charon\myds20vms.ini -check

then check the "RSH was successful" message is displayed followed by "Command successfully completed."

Note

It is recommended to move the psexec.exe program file to a secured folder or to remove it when it is no more needed (check completed)


Div
classpagebreak


ssh mode preparation

Execute the same operations as described in chapter "Using ssh" for Tru64 or VMS to create a key pair with "SYSTEM" user with a different identity file.

To do so, use the psexec.exe program file provided in the kit or download it from the Microsoft Sysinternals page.

Open a cmd.exe window as Administrator and run the following command:

C:\WINDOWS\system32>C:\Charon\psexec.exe -i -s cmd.exe

...

A new window will popup. To check you're connected as "system", run:

C:\WINDOWS\system32>whoami
nt authority\system

Create a new ssh trust as described in the "Using ssh" chapter.

Tip

Remember to specify a different identity file in the .ini file. This can be done thanks to the "identityfsys" parameter (see: Using ssh)


Run the Powershell script in check mode:

C:\WINDOWS\system32>powershell -file c:\charon\charon_cleanshutdown.ps1 -config c:\charon\myds20vms.ini -check

then check the "SSH was successful" message is displayed followed by "Command successfully completed."

Note

It is recommended to move the psexec.exe program file to a secured folder or to remove it when it is no more needed (check completed)


Div
classpagebreak


Windows settings - Local group policy

Adding the script to the shutdown Powershell scripts

TO BE COMPLETEDOpen the "Local Group Policy Editor" (run gpedit.msc) and go to the Shutdown script setup:

Image Added

Select the "Powershell Scripts" tab, click on the "Add..." button, specify the path to the charon_cleanshutdown.ps1 script and its parameters:

Image Added

Display instructions in shutdown scripts as they run

It is recommended to enable the display instructions during shutdown to check the Charon Legacy OS shutdown is correctly performed.→ recommended

Open the "Local Group Policy Editor" (run gpedit.msc) and go to the "Computer Configuration" → "Administrative Templates" → "System" → "Scripts" setup:

Image Added

Enable this functionality and optionally leave a comment:

Image Added

Specify maximum wait time for Group Policy scripts

→ default = 600 seconds (10minBy default the script executed at Windows shutdown have a default timeout of 10 minutes (600 seconds). It is possible to change this value in case the shutdown takes more time.

Open the "Local Group Policy Editor" (run gpedit.msc) and go to the "Computer Configuration" → "Administrative Templates" → "System" → "Scripts" setup:

Image Added

Enable this functionality, define the new timeout and optionally leave a comment:

Image Added

Windows shutdown example

This example is given for a Windows 10 Professional version running Charon-AXP V4.10 B202-03. The emulated Alphaserver is a DS20 running OpenVMS 8.4:

Image Added

(info) The PowerShell window is displayed during Windows shutdown thanks to the enabled "Display instructions in shutdown scripts as they run" feature and the putty / OPA0 window is opened thanks to the "openconsolecmd" and "openconsolearg" parameters in the .ini file.

Tip

It is recommended to check the log files once the Windows server has rebooted:

  • the shutdown log file from this script and
  • the OPA0 log file defined in the Charon configuration file (if not set, it is recommended to define it)

Include Page
KBCOMMON:KB-GoToTop
KBCOMMON:KB-GoToTop