Add Logoff script for stand-alone workstation?

0

I have 6 versions of Windows in VMs for testing software. The Windows VMs are stand alone and not part of domain. They span Windows XP to Windows 10. The software that gets tested produces about 1.75 GB to 2 GB of output artifacts during testing (object files, program database files, libraries and executables).

I want to execute a logoff script that cleans the artifacts. The script is quite easy since it only needs to delete 3 folders in a certain directory if its exists. I already have the script.

I found KB's like Assign Computer Shutdown Scripts and MSDN discussions like Run logoff scripts synchronously - Standalone Workstation, but they assume the Windows computer is a member workstation and part of a Domain.

How do I add a Logoff script to a Standalone/non-Member workstation to clean the build artifacts during logoff?

jww

Posted 2016-10-10T04:09:09.300

Reputation: 1

I'm confused, why can you not use the methods listed in https://technet.microsoft.com/en-us/library/cc753404.aspx again on the Group Policy configuration by setting that policy and pointing it to a script for LOGOFF or SHUTDOWN on most of your machines? These policies can be set locally with gpedit.msc and not just via a domain environment. You have a link to this via one of the other links in your question?

– Pimp Juice IT – 2016-10-10T05:52:34.963

This feels like something one would use snapshots and/or a read only drive for. – Aibobot – 2016-10-10T08:06:02.563

@Homey_D_Clown_IT - I think you cited the same article I cited. As I stated in the question, this is a stand alone workstation; and not a member of a domain. I don't have a domain controller or netlogon folder. Follow the links and read the instructions: "In Script Name, type the path to the script, or click Browse to search for the script file in the Netlogon shared folder on the domain controller." – jww – 2016-10-10T09:35:39.280

@jww Did you try to assign a local path to see what happens? – Seth – 2016-10-10T09:40:21.907

Answers

1

Depending on what actually happens on the system after you've done your testing the default Windows Task Scheduler. There is an event if a user logs off on. If you have a specific user you can even match it to him and by designing your script accordingly you could probably detect the logoff. Alternatively your could write custom event to the event log and watch for it. I'm not sure if On disconnect from user session would trigger on a local logoff.

Otherwise the suggestion from Big Chris/the comment on your question that you might be able to use the local group policies would be applicable. You might run into issues with this in Windows XP as XP is vastly different but this probably applies for every solution.

The correct/optimal way would probably to have the script that does the clean up as the last stage of your testing. After all that would make sure the testing is done and depending on how you actually do the tests (automatic build system that runs the tests?) you might even be able to just set it up as an additional step.

Seth

Posted 2016-10-10T04:09:09.300

Reputation: 7 657

1

Tested on Win 7 HP 32,64 - Win 7 Ent 32,64

If you are running tests, then it means you re-log on when next test phase starts. So just assign via TASK SCHEDULER, a LOGON trigger to run a script during LOGON, and assign as SYSTEM user so it runs in background. Just save the below Sample TASK as XML file, and edit the source :

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2016-08-17T08:16:28.8123508</Date>
   ! <Author>DOMAIN\USER</Author>
   ! <Description>Your description</Description>
  </RegistrationInfo>
  <Triggers>
    <LogonTrigger>
      <Enabled>true</Enabled>
    </LogonTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
   !   <UserId>S-1-5-18</UserId> -> This is SYSTEM user ID
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>StopExisting</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
    <UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
    !  <Command>C:\cleanup.bat</Command> This is where your script resides
    </Exec>
  </Actions>
</Task>

dExIT

Posted 2016-10-10T04:09:09.300

Reputation: 344

Thanks @dExit. I need it for logoff, not logon. My host is nearly out of disk space, and the 5 GB or 10 GB that often gets missed matters. I've got a few questions on Super User relating to the low disk space problems with VMware. – jww – 2016-10-10T09:55:30.577

I understand just think about it, your forcing yourself to use only ONE WAY thinking. – dExIT – 2016-10-12T06:27:36.517

0

Use the Local Group Policy to assign a logoff script.

Some research quickly finds various reasons why it's not easy using, say, Task Scheduler, and the recommended method is Group Policy.

Kinnectus

Posted 2016-10-10T04:09:09.300

Reputation: 9 411