Announcement

Collapse
No announcement yet.

Win Xp Logoff Script

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Win Xp Logoff Script

    Hello Guys

    I am not very good at VbScript. and I need a script that will run when user try to logoff.

    So when user click logoff i need script to give Warning msg with Ok and Cancel option

    if user clicks ok then it will delete everything on desktop and log user off. but if user clicks cancel then script will get cancelled.


    Is this possible if so if you guys can help me that will be great.

    thank you

    Raj

  • #2
    Re: Win Xp Logoff Script

    To run logoff scripts before the user logs off - edit the Logoff Script Option at the "User Configuration" in the GPO by enabling the policy "Run logoff scripts synchronously".

    This sample vbscript will try to delete every file and folder from the user's desktop after the user has clicked the YES button:
    Code:
    '# IMPORTANT note!
    '# To avoid permanent loss of the items on YOUR desktop !!!!,
    '  while testing, rem out or comment out the lines that
    '  actually delete! files and subfolders. Also comment out the
    '  3 lines where the file/folder attibutes are being changed.
    
    Const CSIDL_DESKTOP = &H10
    
    MsgBoxSpecifics = vbOKCancel+vbQuestion+vbDefaultButton1+vbSystemModal
    Do until answer=vbOK
       answer = MsgBox("Continue cleaning the user's desktop?",_
         MsgBoxSpecifics ,"Clean Desktop!")
       If answer=vbCANCEL Then wscript.quit
    Loop
    
    Set fso = CreateObject("scripting.filesystemobject")
    Set WshShell = CreateObject("WScript.Shell")
    
    With CreateObject("Shell.Application")
       Set objDesktop = .Namespace(CSIDL_DESKTOP)
       DesktopPath = objDesktop.Self.Path
    End With
    
    ':: Recursively remove any 'File Attributes' from all files and subfolders
    ClearAttributes = WshShell.run ("%comspec% /c (pushD """ & _
         DesktopPath & """ &&(ATTRIB -S -H -R -A /D /S) & popD)>nul", _
         0,true)
    
    ':: Delete all filesystem items from desktop
    on Error Resume Next
    For Each objItem in objDesktop.Items
       strName = objItem.Path : err.clear
       If fso.FileExists(strName) = True Then
         strList = strList & vbNewLine & "FILE:" _
             & vbTab & objItem.name
         fso.DeleteFile(strName)
       ElseIf fso.FolderExists(strName) = True Then
         strList = strList & vbNewLine & "FOLDER: " _
             & vbTAB & objItem.name
         fso.DeleteFolder(strName)
       End IF
       If err.number <> 0 then strList = strList & vbNewLine _
         & vbTab & err.description & " (" & objItem.name & " unable to delete)"
    Next
    
    WshShell.popup "> Items Deleted:" _
        & strList, 5, "Thank you"
    
    wscript.quit 0
    \Rems

    More about the 'msgBox' function:
    - http://www.w3schools.com/VBScript/func_msgbox.asp
    - http://www.devguru.com/technologies/...ef/msgbox.html
    Last edited by Rems; 3rd June 2009, 20:14.

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Win Xp Logoff Script

      Hello mate


      thank you for that.

      But for some reason when ever i try to run it i am getting Syntax error ?????



      Raj

      Comment


      • #4
        Re: Win Xp Logoff Script

        It should also tell you which LINE the error is at
        Tom Jones
        MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
        PhD, MSc, FIAP, MIITT
        IT Trainer / Consultant
        Ossian Ltd
        Scotland

        ** Remember to give credit where credit is due and leave reputation points where appropriate **

        Comment


        • #5
          Re: Win Xp Logoff Script

          Its Line 1 Char 24


          But i removed that line and put it back in now its running but its not deleteing anything on desktop its just runs and does nothing everything on desktop remains as it is ???





          Raj
          Last edited by rraj; 3rd June 2009, 16:27.

          Comment


          • #6
            Re: Win Xp Logoff Script

            Check the end of line 1 reads & H 1 0 (no spaces -- last two characters are one and zero)
            Without line 1 the delete will fail as it cant find the desktop
            Tom Jones
            MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
            PhD, MSc, FIAP, MIITT
            IT Trainer / Consultant
            Ossian Ltd
            Scotland

            ** Remember to give credit where credit is due and leave reputation points where appropriate **

            Comment


            • #7
              Re: Win Xp Logoff Script

              Originally posted by rraj View Post
              Its Line 1 Char 24

              But i removed that line and put it back in now its running but its not deleteing anything on desktop its just runs and does nothing everything on desktop remains as it is ???

              Raj
              Does the popup-window appear with the OK and Cancel buttons?

              Maybe there are other errors - try removing the line: On Error Resume Next


              \Rems

              This posting is provided "AS IS" with no warranties, and confers no rights.

              __________________

              ** Remember to give credit where credit's due **
              and leave Reputation Points for meaningful posts

              Comment


              • #8
                Re: Win Xp Logoff Script

                Yes Ok Cancell menu pop ups fine just removed on error line and now is coming with syntex error on line 18 ??




                Raj

                Comment


                • #9
                  Re: Win Xp Logoff Script

                  Originally posted by Ossian View Post
                  Check the end of line 1 reads & H 1 0 (no spaces -- last two characters are one and zero)
                  Without line 1 the delete will fail as it cant find the desktop

                  Oassian i checked and end of first line does read &H10 no speces ??

                  Comment


                  • #10
                    Re: Win Xp Logoff Script

                    Just tried it on XP SP3 with no errors
                    Note:
                    I commented out the lines that actually delete files!
                    Ran as administrator by double clicking, not through logoff script
                    Tom Jones
                    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
                    PhD, MSc, FIAP, MIITT
                    IT Trainer / Consultant
                    Ossian Ltd
                    Scotland

                    ** Remember to give credit where credit is due and leave reputation points where appropriate **

                    Comment


                    • #11
                      Re: Win Xp Logoff Script

                      Originally posted by Ossian View Post
                      Just tried it on XP SP3 with no errors
                      Note:
                      I commented out the lines that actually delete files!
                      Ran as administrator by double clicking, not through logoff script

                      Sorry mate me just being bit dumb tried it and works fine is there any chance that if i click ok to delete everything after it deleted it logs user off and is there any chance that it can also delet any shortcuts created on desktop ??

                      Guys this is much apreciated great jobs thank ou guys

                      Comment


                      • #12
                        Re: Win Xp Logoff Script

                        Made a few modifications to the script. Can you test the script now.

                        EDIT:
                        Added also a dos command line into the vbscript, it'll take care of possible existing hidden and readonly file attribute bits before running the part that will try to delete the items. Why a Dos? well just because it was simple to write (it would take much more code for doing the same in vbs).

                        thanks,
                        \Rems


                        Originally posted by rraj View Post
                        is there any chance that it can also delet any shortcuts created on desktop ??
                        A Shortcut is a file too, so it will be deleted, - would you like to exclude shortcuts from being deleted?
                        Files that exist on the All-Users-Desktop will not be deleted by this script.
                        _
                        Last edited by Rems; 4th June 2009, 00:02.

                        This posting is provided "AS IS" with no warranties, and confers no rights.

                        __________________

                        ** Remember to give credit where credit's due **
                        and leave Reputation Points for meaningful posts

                        Comment


                        • #13
                          Re: Win Xp Logoff Script

                          mate thats great thats all good an working just a last sorry mate is there any chance after it delets files on desktop it logs user off ??? and if they cancell it does nothing.

                          ??


                          as i want it too be logoff script so i need it to log user off after it clears dekstop ?


                          Thank you very much !!

                          Comment


                          • #14
                            Re: Win Xp Logoff Script

                            That is also possible.

                            When you mensioned a 'logoff script' I thought that this script should automatically start during the user logoff process, in that case add the logoffscript to the GPO that is linked to the OU containing the users, and then also "Run logoff scripts synchronously" must be Enabled.

                            Else, When the script will be launched by the user him/her self and must programmatically logging the user off -> add the following line to the existing script:
                            LogOff = WshShell.run ("logoff.exe", 0, False)
                            (just above the line: wscript.quit 0)


                            \Rems

                            This posting is provided "AS IS" with no warranties, and confers no rights.

                            __________________

                            ** Remember to give credit where credit's due **
                            and leave Reputation Points for meaningful posts

                            Comment


                            • #15
                              Re: Win Xp Logoff Script

                              Originally posted by Rems View Post
                              That is also possible.

                              When you mensioned a 'logoff script' I thought that this script should automatically start during the user logoff process, in that case add the logoffscript to the GPO that is linked to the OU containing the users, and then also "Run logoff scripts synchronously" must be Enabled.

                              Else, When the script will be launched by the user him/her self and must programmatically logging the user off -> add the following line to the existing script:
                              LogOff = WshShell.run ("logoff.exe", 0, False)
                              (just above the line: wscript.quit 0)


                              \Rems


                              Hello mate yes sorry for that confusun i just need one last thing off you whats code for shutdown and restart computer instead of log off ??

                              if i get that then i think i am all sorted .

                              thank you very much again mate this is much apreciated .


                              Kind reagards

                              Raj

                              Comment

                              Working...
                              X