# Log Off Script



## LUNIX

Hello 

OS: Windows XP Professional SP2

I am trying to create a batch that creates a 'Log Off Script', I know of gpedit.msc, but is there a way some utility maybe that could help me create this script from the commandline?

Kind Regards


----------



## JohnWill

A "Log Off Script" is just a batch file with the commands you want to execute. You use Notepad or the like to create it.


----------



## LUNIX

I need to create the log off script using a batchfile, the creation of the log off script is part of a larger script. Can this be done?


----------



## JohnWill

Can you create a batchfile (or logoff script) from another batchfile? Sure, it would help a bunch to know specifics. Depending on how complicated the logoff script was, you may want a 3rd party application. How about specifics of the issues and what the script needs to do?


----------



## Dan O

shutdown -L

Will log off a user.


----------



## JohnWill

I was trying to find out the functionality desired. A "Logoff script" can contain literally any command.


----------



## LUNIX

Its a batchscript that lets say, delete a file. What I wonna know is if you can add a log off script from the commandline in Windows Xp Professional? And if so without using any 3rd party tools.


----------



## JohnWill

echo delete "C:\Documents and Settings\somefile.xxx" > delscript.bat

What do you want the logoff script to do?


----------



## LUNIX

Its not that, I want to add a script I have already created. The problem is that I want to add the script through the commandprompt and not through gpedit.msc.


----------



## JohnWill

Oh, we finally have a meeting of the minds! 

It would be easy to copy the script to C:\WINDOWS\System32\GroupPolicy\User\Scripts\Logoff, the real question is do you need to add something to the registry. My sense is simply copying might work, but it would be easy enough to test.

You can add a script using gpedit.msc, then see what is added to the registry, if anything. Duplicating that registry update in your script and copying the file ought to get it done.


----------



## LUNIX

Yeah I did that, but then now i have to make the batch so that the script can be run on any computer and add my script.. problem is that i cant make my script import the SID of the current user I would have to make the SID an Envoirmental Variable I have tried various applications but nothing I have tried seems to be able to do this... Do you know a script (preferably written in batch) that could do such a thing?

Here is a sample of the script I have written:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\%SID%\Scripts\Logoff\0\0]
"Script"="Test.bat"
"Parameters"=""
"ExecTime"=hex(b):d7,07,04,00,03,00,12,00,13,00,2d,00,09,00,7d,00

%SID% should output the current logged on users SID


----------



## JohnWill

How about using PsGetSID? A little creative batch file writing will get it into a environment variable.

C:\>psgetsid

PsGetSid v1.43 - Translates SIDs to names and vice versa
Copyright (C) 1999-2006 Mark Russinovich
Sysinternals - www.sysinternals.com

SID for \\MAIN:
S-1-5-21-343818398-746137067-725345543


----------

