Sign in to follow this  
Followers 0
masonje

logoff script

7 posts in this topic

The only real way I have found to setup a logoff script is via gpedit.msc and/or group policy. We don't really use group policy where I work (at lease not consystently). I used a tool to do a pre and post snapshot to capture what registry setting are set on a pc to enable a logoff script. I exported those settings and used AutoIT to install the .reg file ( runwait("regedit -s logoff.reg") ). That works on the PC that I took the snapshot on, but not so much on any other pc. I found there is a euneque sort of ID for the pc that is a reg key, then the script to run is also stored there:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\S-1-5-21-266706710-3053449956-1142509412-500\Scripts\Logoff\0\0]

Has any one ever used AutoIT to create a good function to create a logoff/logon script?

;LogoffScript(file, [peramiter, [timeout]])
LogoffScript("defrag.exe", "c:")

??? That would rock!!!

Attached is the full registry extraction for setting up the logoff script via gpedit.msc that works on the one PC. I think the trick is going to be in finding that euneque ID for the PC.

Thoughts?

Share this post


Link to post
Share on other sites



see 'shutdown()' in the helpfile

Share this post


Link to post
Share on other sites

see 'shutdown()' in the helpfile

Not much help. That either shuts or logs the PC off with out entering the logoff script. I need the PC to run a process at logoff time.

Share this post


Link to post
Share on other sites

Not much help. That either shuts or logs the PC off with out entering the logoff script. I need the PC to run a process at logoff time.

try to search with google

run logoff xp

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I honestly don't know what you are looking for. Perhaps you would be interested in AutoIt Automated Shutdown which can be found in my signature. It is open source and you can modify it to suit your needs.

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

This example shows how to enumerate to add an entry into the Logoff key. Remember Group Policy would need to be manually be used on the OS first to create the structure in registry and in @SystemDir & "\GroupPolicy" that this script relys on for enumeration. It is not crystal clear to me on what exactly is needed to have a valid script entered and would take some research to create a good solution. Perhaps someone has already done one in scripts'n'scraps.

$return = _RegEnumGroupPolicyLogoff()
MsgBox(0, '', '@error = ' & @error & @CRLF & 'subkey = ' & @extended & @CRLF & 'main key = ' & $return)

Func _RegEnumGroupPolicyLogoff()
    Local $key = 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State'
    For $i = 1 To 1000
        $subkey = RegEnumKey($key, $i)
        If @error Then Return SetError(1, 0, '')
        If _RegEnumFindKey($key & '\' & $subkey, 'Scripts') And Not @error Then
            $key &= '\' & $subkey & '\Scripts\Logoff'
            For $i = 1 To 1000
                $subkey = RegEnumKey($key, $i)
                If @error Then
                    $index = $i -1
                    If $index < 0 Then Return SetError(2, 0, '')
                    ; Start writing info to registry here (below is only a test)
                    RegWrite($key & '\' & '\' & $index, 'test', 'Reg_SZ', 'value')
                    Return SetError(0, $index, $key)
                EndIf
            Next
        EndIf
    Next
EndFunc

Func _RegEnumFindKey($key, $subkey)
    For $i = 1 To 1000
        If RegEnumKey($key, $i) = $subkey Then
            If @error Then
                Return SetError(1, 0, '')
            Else
                Return True
            EndIf
        EndIf
    Next
EndFunc

:whistle:

Edit:

I notice the logoff key is removed when I delete my example logoff script from GPEdit so updated code for looking for the Scripts key instead as it remains.

Edited by MHz

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

MHz if you were a cute women I would kiss you! Had I thought to look at all the reg functions I think I could have figured out to use RegEnumKey(). The script you provided will be the basis to my LogOffScript() function. You are a total AutoIT :whistle:

I think I have all the keys I will need to write to based on the attached reg file in my first post on this. From there (I hope) it shouldn't be hard. I will let you know.

Edited by masonje

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0