Solved

Logoff scripts to run only on LOG OFF

Posted on 2004-03-25
7
928 Views
Last Modified: 2010-04-13
I set a logoff script for domain that backs up files to the server when users log off their workstations and it works fine. The problem is that it executes also when they restart their machines when they have to. That is a big inconvenience because depending on the size of the files that are being backed up, it may take a while. For one user, it took her 40 minutes to restart her computer.

I am wondering, is there a way to configure Windows 2000 so that logoff scripts run ONLY when a user clicks Start, Log off ? So that they run only on forced Log Off??
0
Comment
Question by:njava
  • 5
  • 2
7 Comments
 
LVL 16

Expert Comment

by:JamesDS
ID: 10685053
In a word, no - sorry!

The logoff event is called during the shutdown request, there is no way around this.

An alternative might be to insert a question in the the script that asks if they want to run the script and if there is no response after 5 seconds, then gets on a runs it anyway. That way a user doing a reboot gets the choice of a full backup.

Cheers

JamesDS
0
 
LVL 1

Author Comment

by:njava
ID: 10761853
Oh, for some reasons I don't get a notification anymore when someone replies to my post.

Do you have any suggestions how to modify the script? How to do something like this:

ECHO <PRESS ANY KEY TO EXIT LOG OFF SCRIPT>
IF KEYPRESSED
   EXIT
0
 
LVL 1

Author Comment

by:njava
ID: 10762112
I came with an idea...how to generate Anykey stroke???


ECHO <PRESS ANY KEY TO EXIT LOG OFF SCRIPT>
SET Anykey =
IF '%Anykey%' ==
EXIT
SLEEP 20

:: MY SCRIPT STARTS HERE
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 16

Accepted Solution

by:
JamesDS earned 100 total points
ID: 10763464
njava

Batch language doesn't work like this as it will continue processing regardless of user input. I suggest you write a short bit of VBScript code that ask the user for input and then sets a variable that either exits or continues the batch file.

Try this VBScript code and use it to call your logoff script. It will ask the user a question and act on the result:

Set WshShell = Wscript.CreateObject("Wscript.Shell")

strInput = MsgBox("Do you want to shutdown?",vbokcancel,"Logoff and backup script")

If strInput = 1 Then wshShell.run("logoff.bat") ' They pressed ok
If strInput = 2 Then WScript.Quit ' They pressed cancel

Cheers

JamesDS
0
 
LVL 1

Author Comment

by:njava
ID: 10770253
I modified logoff.vbs script a bit. Is there any way to make two buttons - Logoff and Restart instead of Yes and No?


Set wshShell = WScript.CreateObject("Wscript.Shell")

strInput = MsgBox("Do you want to Logoff or Restart your computer?", vbQuestion + vbYesNo, "Select Logoff or Restart")

If strInput = 1 Then wshShell.Run ("backup.bat") ' They pressed Logoff
If strInput = 2 Then WScript.Quit ' They pressed Restart
0
 
LVL 1

Author Comment

by:njava
ID: 10770525
I worked out a solution :-) The problem is that to set a custom button in Visual Basic you'd have to make a separate form and then assign a code to each button. I am not sure if this is possible in VBS. I re-designed the script again. It's easy to understand and it works. I graded your answer "B" because I still had to pull out a lot of my own hair :-) Thanks for your help anyway!


Set wshShell = WScript.CreateObject("Wscript.Shell")

strInput = MsgBox("Do you want to backup your e-mail?", vbQuestion + vbYesNo, "Select Yes or No")

If strInput = 6 Then wshShell.Run ("backup.bat") ' They pressed Yes
If strInput = 7 Then WScript.Quit ' They pressed No
0
 
LVL 1

Author Comment

by:njava
ID: 10779030
My troubles with logoff scripts are not over...in fact, it doesn't work...well, if you want to participate, I posted another question on that topic at.

http://www.experts-exchange.com/Operating_Systems/Win2000/Q_20947113.html
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question