Execution of a DOS command each time a user logs off

balubeto

Member
Member
Messages
173
Hi


In all editions of Windows 8, how do I make sure that it executes a DOS command each time a user logs off?

Thanks

Bye
 

My Computer

System One

  • OS
    Windows 8
DOS? Anyway, try creating a scheduled task with the Trigger at log off. Set the command on the Action tab.
 
Last edited:

My Computer

System One

  • OS
    Windows 8 Pro x64
    Computer type
    Laptop
    System Manufacturer/Model
    HP Pavilion dv7t (17.3'', i7-2630QM, HD 6770M 1Gb, 8Gb RAM, 2 SSD@120Gb + 1 HDD@750Gb)
Make a Batch File or a Macro of that command - T%hen use Task Sched to run THAT. It works better that way, you can add command line switches.
 

My Computer

System One

  • OS
    Windows 8 Pro with Media Center/Windows 7
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Asus M2N-MX SE Plus § DualCore AMD Athlon 64 X2, 2300 MHz (11.5 x 200) 4400+ § Corsair Value Select
    CPU
    AMD 4400+/4200+
    Motherboard
    Asus M2N-MX SE Plus/Asus A8M2N-LA (NodusM)
    Memory
    2 GB/3GB
    Graphics Card(s)
    GeForce 8400 GS/GeForce 210
    Sound Card
    nVIDIA GT218 - High Definition Audio Controller
    Monitor(s) Displays
    Hitachi 40" LCD HDTV
    Screen Resolution
    "1842 x 1036"
    Hard Drives
    WDC WD50 00AAKS-007AA SCSI Disk Device
    ST1000DL 002-9TT153 SCSI Disk Device
    WDC WD3200AAJB-00J3A0 ATA Device
    WDC WD32 WD-WCAPZ2942630 USB Device
    WD My Book 1140 USB Device
    PSU
    Works 550w
    Case
    MSI "M-Box"
    Cooling
    Water Cooled
    Keyboard
    Dell Keyboard
    Mouse
    Microsoft Intellimouse
    Internet Speed
    Cable Medium Speed
    Browser
    Chrome/IE 10
    Antivirus
    Eset NOD32 6.x/Win Defend
    Other Info
    Recently lost my Windows 8 on my main PC, had to go back to Windows 7.
XweAponX,
You can add command line switches without a batch file, there's a special Arguments field for that in Action. E.g.
cmd
/c echo hello>>%userprofile%\desktop\hello.txt

Certainly, CMD-file will work equally well.
 

My Computer

System One

  • OS
    Windows 8 Pro x64
    Computer type
    Laptop
    System Manufacturer/Model
    HP Pavilion dv7t (17.3'', i7-2630QM, HD 6770M 1Gb, 8Gb RAM, 2 SSD@120Gb + 1 HDD@750Gb)
Adding a user logoff script in Group Policy ( ive been trying to get this to work since this afternoon, I dont know why its not working for me, maybe youll have better luck)

Assign user logoff scripts: Group Policy



Audit users login, logoff, Startup, or Shutdown

Audit users Logon/logoff as well as Startup/Shutdown with batch file


Heres a registry edit to point to a batchfile, unfortunately its not in windows 8, Im still trying to figure it out, in the meantime i'll show you some suggestions on where to look..

windows - Running a batch file on logoff - Super User
 

My Computer

System One

  • OS
    Windows 8 & Windows 7 Dual Boot
    Computer type
    Laptop
    System Manufacturer/Model
    HP G60
    CPU
    AMD Turion RM-70 Dual Core 2.0 GHZ
    Memory
    3 GB
    Graphics Card(s)
    Nvidia GeForce 8200M G
    Screen Resolution
    1366 x 768
    Mouse
    MS Intellipoint 5 button (love it!)
    Browser
    Chrome and Chromium
    Antivirus
    Avast Free & Malwarebytes
By chance, in Windows 8 Standard (and in other editions), there is one registry key or entry that can perform a reg command that is executed when a user logs off? This key or entry must operate at the global level.

Thanks

Bye
 

My Computer

System One

  • OS
    Windows 8
balubeto,
There's no such registry key, but a scheduled task is easy to deploy.

Brooklyn567,
How would you do a group policy logoff script in Windows 8 (not Pro)?
 
Last edited:

My Computer

System One

  • OS
    Windows 8 Pro x64
    Computer type
    Laptop
    System Manufacturer/Model
    HP Pavilion dv7t (17.3'', i7-2630QM, HD 6770M 1Gb, 8Gb RAM, 2 SSD@120Gb + 1 HDD@750Gb)
I'm attempting to do something similar as well (run a vbscript to call a powershell script). However, with just the standard Windows 8 edition Group Policy Editor is not included. Task Scheduler has no event for logging off or shutting down. [DEL]In fact, I can't get Task Scheduler to ever actually run a task. Even the most basic Startup task will not trigger during Startup (SOLVED)[/DEL].

Has anyone figured out a way to run scripts at shutdown, or even at logoff, that doesn't require Windows 8 Pro/Server?


Details:

I am running a VBscript to call a PowerShell script. The purpose of which is to copy files from one drive to another.

I've got a RAM disk where I've symbolically linked Google Chrome's \Default folder. This way every time I shut down, all the cookies, bookmarks, temp files are lost. My scripts are attempting to copy certain files like "Bookmarks" and "Last Session" from a dump folder on a hard disk, back into the RAM disk folder on Startup so I don't have to continuously import my bookmarks back into Chrome. This way everytime I shut off the machine, all the junk is lost but my bookmarks and last tab session are saved to file. Then when the machine starts up again, I've got a fresh browser with my bookmarks already imported and my last opened tabs up and going.

I've got everything working great but the shutdown portion of my scripts. For the life of me I cannot figure out how to run a shutdown script in Windows 8 (standard edition, without Group Policy Editor). It is becoming frustrating that I can simply drop my scripts in the shell folder for Startup (but not shutdown), or go into Task Scheduler and set it to run on user login (but not user logoff/shutdown). If I can just figure out how to run a shutdown script, I'm gold!
 
Last edited:

My Computer

System One

  • OS
    Windows 8
As far as using Powershell Scripts, I had a script that I used to read my Temperatures from Open Hardware Monitor, and when I set it up, it worked great, but I could never get it to run from Powershell after that, it has to be in the ISE, and even after creating it, and loading it into ISE, it would not run the way it ran the first time I ran it.

If you can convert the Powershell script to a regular Batch file, then you can add it to Task Scheduler. Is there any way you can convert the script to a BAT?

[FONT=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]I was able to create a speech macro so I could tell my computer "Ribbons" and it would start the screensaver, and "Shut Up" which would tell it to shut down, I've got one for Hibernate too, that one is just "Hibernate". I've had better luck with Speech than with Powershell.[/FONT]
 

My Computer

System One

  • OS
    Windows 8 Pro with Media Center/Windows 7
    Computer type
    PC/Desktop
    System Manufacturer/Model
    Asus M2N-MX SE Plus § DualCore AMD Athlon 64 X2, 2300 MHz (11.5 x 200) 4400+ § Corsair Value Select
    CPU
    AMD 4400+/4200+
    Motherboard
    Asus M2N-MX SE Plus/Asus A8M2N-LA (NodusM)
    Memory
    2 GB/3GB
    Graphics Card(s)
    GeForce 8400 GS/GeForce 210
    Sound Card
    nVIDIA GT218 - High Definition Audio Controller
    Monitor(s) Displays
    Hitachi 40" LCD HDTV
    Screen Resolution
    "1842 x 1036"
    Hard Drives
    WDC WD50 00AAKS-007AA SCSI Disk Device
    ST1000DL 002-9TT153 SCSI Disk Device
    WDC WD3200AAJB-00J3A0 ATA Device
    WDC WD32 WD-WCAPZ2942630 USB Device
    WD My Book 1140 USB Device
    PSU
    Works 550w
    Case
    MSI "M-Box"
    Cooling
    Water Cooled
    Keyboard
    Dell Keyboard
    Mouse
    Microsoft Intellimouse
    Internet Speed
    Cable Medium Speed
    Browser
    Chrome/IE 10
    Antivirus
    Eset NOD32 6.x/Win Defend
    Other Info
    Recently lost my Windows 8 on my main PC, had to go back to Windows 7.
*UPDATE*

I've come across a messy solution, which is basically creating a desktop shortcut that runs a VBscript to call my powershell script. The PowerShell script then executes and calls the system shutdown. I don't really like this solution because it doesn't account for system rebooting. Also, it restricts me to using only the shortcut to shutdown and does not run the script for any other shutdown events.

So I've been tinkering with a second solutionl. This method involves adding registry values to basically do what Group Policy Editor does. I have not been able to get this to work however, and I'm unsure on whether it has to do with my registry hack, or the version of Windows I'm using.

First I tried adding the script to the shutdown event:
Code:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts]    


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown]  


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0]    
"GPO-ID"="LocalGPO"    
"SOM-ID"="Local"    
"FileSysPath"="C:\\Windows\\System32\\GroupPolicy\\Machine"    
"DisplayName"="myGroupPolicy"    
"GPOName"="myGroupPolicy"


  


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0\0]    
"Script"="C:\\ShutdownScripts.vbs"    
"Parameters"=""    
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00

The script does not execute. I thought maybe it had to do with the term process unloading explorer or something. I don't understand the nuts and bolts of what is going on during shutdown. So I tried this instead:

Code:
Windows Registry Editor Version 5.00   

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Logoff]  


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Logoff\0]    
"GPO-ID"="LocalGPO"    
"SOM-ID"="Local"    
"FileSysPath"="C:\\Windows\\System32\\GroupPolicy\\Machine"    
"DisplayName"="myGroupPolicy"    
"GPOName"="myGroupPolicy"


  


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Logoff\0\0]    
"Script"="C:\\ShutdownScripts.vbs"    
"Parameters"=""    
"ExecTime"=hex(b):00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00

Still no luck.
 

My Computer

System One

  • OS
    Windows 8
XweAponX,
You can add command line switches without a batch file, there's a special Arguments field for that in Action. E.g.
cmd
/c echo hello>>%userprofile%\desktop\hello.txt

Certainly, CMD-file will work equally well.

Hi there
I think the question was not HOW to write a batch cmd but to make sure it RUNS at EVENT LOGOFF.

The question was how to ensure the command - or script runs at event logoff.

With these sorts commands just start with something simple so you know the event gets captured - for instance just display on the screen "Logging off at hh.mm.ss". Once you've got the event to trigger properly you can start messing around with the actual execution scripts -- and even have them run totally as background jobs.

Test SIMPLE stuff first as a POC (Proof of concept). - My experience is that people always delve into the most complex stuff too early in the development process.

Test your script SEPARATELY too -- so now once you've got the EVENT (LOGOFF) to trigger and your script working just match the two together --job done.

Cheers
jimbo
 

My Computer

System One

  • OS
    Linux Centos 7, W8.1, W7, W2K3 Server W10
    Computer type
    PC/Desktop
    Monitor(s) Displays
    1 X LG 40 inch TV
    Hard Drives
    SSD's * 3 (Samsung 840 series) 250 GB
    2 X 3 TB sata
    5 X 1 TB sata
    Internet Speed
    0.12 GB/s (120Mb/s)
Back
Top