Re: log off command
- From: "Matija Hrovat" <matija.hrovat@xxxxxxxxxxxxxxx>
- Date: Wed, 22 Nov 2006 17:55:46 +0100
Hi CMG,
is it possible that you switch the user after you run the batch file ?
If you do I am sorry but I did not know you will use it in that way.
Here is another script (which will hopefully do the trick);
If the line doesn't start with two spaces the lines must be corrected.
-----------START-----------
@echo off
quser %1 >user.txt
for /f "skip=1 tokens=2,3" %%u in (user.txt) DO (
SET ID=%%u & SET ID2=%%v
)
IF %ID%==console GOTO CONSOLE
ECHO NOT CONSOLE
SOON 3600 LOGOFF %ID%
GOTO END
:CONSOLE
ECHO CONSOLE
SOON 3600 LOGOFF %ID2%
GOTO END
:END
SET ID=
SET ID2=
-----------END-----------
If it doesn't work please post what the "at" command returns if you run it
after the batch file and please again describe when it does not work.
Thank you,
Matija Hrovat
"C.M.G." <cmg@xxxxxxxxxxxxxxxx> wrote in message
news:OrcJW4QDHHA.4844@xxxxxxxxxxxxxxxxxxxxxxx
Matija:
You understood my most recent post correctly.
Now, I am not entirely sure what you mean by "what command gets written in
"at" after you run the batch," however, if I go to run and type cmd and
enter, I get a "dos window." If I do this from the NoraTimCharlotte logon
and if, in the "dos window" I type "logoff.bat noratimcharlotte," the
following text is displayed:
SOON : AT 22:33:00 LOGOFF console
Added a new job with job ID = 1
Is that the information you were looking for?
Thanks again,
Clem.
"Matija Hrovat" <matija.hrovat@xxxxxxxxxxxxxxx> wrote in message
news:OGJKaXHDHHA.3600@xxxxxxxxxxxxxxxxxxxxxxx
Hi CMG,
I'm sorry I could not reply earlier.
So if I understand you correctly;
You log into cmg
You switch to NoraTimCharlotte
You use the batch file:
logoff.bat NoraTimCharlotte
and cmd user gets logged off ?
Please tell me what command gets written in "at" after you run the batch
?
e.g.
"Logoff.bat matijah" returns:
Status ID Day Time Command Line
------------------------------------------------------------------
1 Today 9:29 AM LOGOFF console
Regards,
Matija Hrovat
"C.M.G." <cmg@xxxxxxxxxxxxxxxx> wrote in message
news:ONPGfKoCHHA.5012@xxxxxxxxxxxxxxxxxxxxxxx
Matija:
I am using the following batch:
@echo off
quser %1 >user.txt
for /f "skip=1 tokens=2" %%u in (user.txt) DO SET ID=%%u
ECHO %ID%
SOON 3600 LOGOFF %ID%
del user.txt
usernames are
cmg
and
NoraTimCharlotte
The quser responses are:
USERNAME SESSIONNAME ID STATE IDLE TIME LOGON
TIME
cmg console 0 Active .PM
11/16/2006 8:05
and
USERNAME SESSIONNAME ID STATE IDLE TIME LOGON
TIME
noratimcharlotte 1 Disc .
11/17/2006 2:50
PM
Regards,
Clem.
"Matija Hrovat" <matija.hrovat@xxxxxxxxxxxxxxx> wrote in message
news:eWeO3zhCHHA.1224@xxxxxxxxxxxxxxxxxxxxxxx
Hi CMG,
which batch are you using ?
What are the exact usernames of the users ?
What do you get if you type:
- quser User1
- quser User2
Regards,
Matija Hrovat
"C.M.G." <cmg@xxxxxxxxxxxxxxxx> wrote in message
news:%23eAkmceCHHA.3604@xxxxxxxxxxxxxxxxxxxxxxx
Matija,
Here is an interesting little addendum that is a little perplexing:
If user1 logs off user2 from user1's logon, everything works fine. But
if user2 logs off user2 from user2's logon, then user1 gets logged
off.
Any idea why this happens, and how to fix it?
Clem.
"Matija Hrovat" <matija.hrovat@xxxxxxxxxxxxxxx> wrote in message
news:u4PmYtUCHHA.3476@xxxxxxxxxxxxxxxxxxxxxxx
Hi CMG,
one thing to try is that you set the delay to 60 seconds or more. It
does not work correctly if it is set to less.
Let us know if that did the trick.
Regards,
Matija Hrovat
"C.M.G." <cmg@xxxxxxxxxxxxxxxx> wrote in message
news:e6lwrsQCHHA.4680@xxxxxxxxxxxxxxxxxxxxxxx
Matija:
I downloaded and installed soon.exe, and put a copy into
c:\windows\system32.
I've tried both the old and the new version of the code (I changed
3600 to 20, so I would not have to wait so long for testing
purposes, and I added two spaces in front of every line that
contained text).
Each time I execute the command, a task is generated in taskmanager.
However, user2 is only rarely logged off. I've tried deleting all
the tasks from taskmanager and rebooting, but it still does not work
consistently (it works about 1 out of 10 times, but there is no
predictable pattern). When issuing the command from a cmd window,
the following text is displayed:
1
SOON : AT 18:04:45 LOGOFF 1
Added a new job with job ID = 1
Matija, do you have any more ideas? Thanks for your help,
Clem.
"Matija Hrovat" <matija.hrovat@xxxxxxxxxxxxxxx> wrote in message
news:uytI9RJCHHA.4292@xxxxxxxxxxxxxxxxxxxxxxx
CMG,
we did talk about this at the begining of your tread...
You have to download soon.exe:
(http://www.microsoft.com/downloads/details.aspx?familyid=ca8191e6-9eef-4975-b51c-8d670748ca8e&displaylang=en)
or
http://tinyurl.com/wodya
Copy it to c:\windows\system32
Bellow I attached a corrected/shorter version of the code:
++++++++++++++
@echo off
quser %1 >user.txt
for /f "skip=1 tokens=2" %%u in (user.txt) DO SET ID=%%u
ECHO %ID%
SOON 3600 LOGOFF %ID%
del user.txt
++++++++++++++
Let us know if it works now.
Regards,
Matija Hrovat
"C.M.G." <cmg@xxxxxxxxxxxxxxxx> wrote in message
news:OCyZrlDCHHA.3604@xxxxxxxxxxxxxxxxxxxxxxx
Matija,
I did as you suggested, no luck. I ran it form cmd and got this
message:
NOT CONSOLE
'SOON' is not recognized as an internal or external command,
operable program or batch file.
Any other ideas?
Clem.
"Matija Hrovat" <matija.hrovat@xxxxxxxxxxxxxxx> wrote in message
news:ezSF4g7BHHA.4680@xxxxxxxxxxxxxxxxxxxxxxx
Hey,
you should also copy quser.exe from c:\windows\system32\dllcache
to c:\windows\system32
Let us know if it works.
If it doesn't try running the script from cmd and look what
errors you get there.
Regards,
Matija Hrovat
"C.M.G." <cmg@xxxxxxxxxxxxxxxx> wrote in message
news:%239Vjfr3BHHA.3928@xxxxxxxxxxxxxxxxxxxxxxx
Matija:
Thanks for writing.
I copied the text into a file that I called logoff.bat. I
omitted the ++++ and the blank lines at the beginning and end,
and I made sure there were two blank spaces at the beginning of
each line. I did not change the text in the batch file at all.
I then copied the logoff.bat file to C:\WINDOWS\system32.
I then went to start/run and typed logoff.bat username
For username I used that name that appears in taskmanager under
users.
Unfortunately, this has no effect on the other user who is
logged on!
Any idea what I am doing wrong?
Thanks again,
Clem.
"Matija Hrovat" <matija.hrovat@xxxxxxxxxxxxxxx> wrote in message
news:O2LQMBsBHHA.3924@xxxxxxxxxxxxxxxxxxxxxxx
Hi CMG,
sorry for a late response.
Save the following code into a .bat file.
+++++++++++
@echo off
quser %1 >user.txt
for /f "skip=1 tokens=2," %%u in (user.txt) DO SET ID=%%u
IF ID==console GOTO CONSOLE
ECHO NOT CONSOLE
SOON 3600 LOGOFF %ID%
GOTO END
:CONSOLE
ECHO IS CONSOLE
SOON 3600 LOGOFF
:END
del user.txt
+++++++++++++
Usage:
Filename.bat username
Every line starts with two spaces so correct the code if they
don't.
Let us know if this is what you are looking for.
Regards,
Matija Hrovat
"C.M.G." <cmg@xxxxxxxxxxxxxxxx> wrote in message
news:e1q9tTtAHHA.4256@xxxxxxxxxxxxxxxxxxxxxxx
Dear Matija,
Thanks for your comprehensive answer!
I downloaded psshutdown.exe, but I cannot make it do what I am
trying to achieve:
I have two users on my local machine. I would like to log off
user2, but not user1, 60 minutes after issuing the command,
and I want the logoff to force running applications under
user2 to close. I do not want to shutdown the computer, and I
do not want to log off user1, or stop applications running
under user1.
Matija, do you think you could help me with the syntax for
that command?
Thanks again,
Clem.
"Matija Hrovat" <matija.hrovat@xxxxxxxxxxxxxxx> wrote in
message news:eTCbucZAHHA.3396@xxxxxxxxxxxxxxxxxxxxxxx
Hi C.M.G,
there are two (well at least two) possibilities.
One is using the command you mentioned "shutdown"
and the other is using a free Sysinternals utility:
PsShutdown
(http://www.sysinternals.com/Utilities/PsShutdown.html).
The main problem with both utilities is the timeout.
I am almost sure that there is no way to set the logoff
timeout with shutdown (there is supposed to be a way in
earlier versions of shutdown, but I didn't find it) and I
could not find a way to "persuade" the PsShutdown to use the
timeout switch with the logoff switch.
So I propose that you use the "at" command to set the time;
The whole command should look something like this:
at 21:00 /interactive /every:M,T,W,Th,F shutdown -l -f
The command will log off a user ever weekday at 9 pm.
The other way to go is with the "soon.exe" utility which you
can download from the following link:
(http://www.microsoft.com/downloads/details.aspx?familyid=ca8191e6-9eef-4975-b51c-8d670748ca8e&displaylang=en)
With "soon" you can set the amount of time after a specific
command will execute.
e.g.
soon /interactive 3600 shutdown -l -f
The command will log off a user after 3600 seconds.
Of course there is a lot of different ways to logoff a user
using a command line or a script. If you are familiar with
vbs scripts you can create that or you can use one of the 3rd
party utilities (e.g.
http://www.robvanderwoude.com/shutdown.html) that do exactly
what you want.
VBS Example:
'---Start Script
Const LOGOFF = 0
Const SHUTDOWN = 1
Const REBOOT = 2
Const fLOGOFF = 4
Const fSHUTDOWN = 5
Const fREBOOT = 6
strComputer = "."
Set objWMIService = GetObject _
("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\"
& _
strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
Wscript.Sleep 5000
objOperatingSystem.Win32Shutdown(fLOGOFF)
Next
'----End Script
The user will be logged off after 5 seconds.
I hope the mentioned helps and please let us know if this is
the information you were looking for and let me know if
anything is unclear in the post.
Regards,
Matija Hrovat
"C.M.G." <cmg@xxxxxxxxxxxxxxxx> wrote in message
news:eARse44$GHA.3536@xxxxxxxxxxxxxxxxxxxxxxx
To clarify my question below: I am looking for a command or
script to log off another specific user at a specific time,
rather than shutting off the whole computer.
Thanks for your help.
Clem.
"C.M.G." <cmg@xxxxxxxxxxxxxxxx> wrote in message
news:ehx%23$5v%23GHA.1224@xxxxxxxxxxxxxxxxxxxxxxx
I use the following command in a batchfile to force
shutdown of my computer 60 minutes after issuing the
command, and to reboot the computer:
shutdown -r -f -t 3600
My question is: is there a command to log off another user
a certain time after the command is issued, and force
logoff of that user?
Thank you,
Clem.
.
- Follow-Ups:
- Re: log off command
- From: C.M.G.
- Re: log off command
- References:
- Re: log off command
- From: C.M.G.
- Re: log off command
- From: Matija Hrovat
- Re: log off command
- From: C.M.G.
- Re: log off command
- From: Matija Hrovat
- Re: log off command
- From: C.M.G.
- Re: log off command
- From: Matija Hrovat
- Re: log off command
- From: C.M.G.
- Re: log off command
- From: Matija Hrovat
- Re: log off command
- From: C.M.G.
- Re: log off command
- From: Matija Hrovat
- Re: log off command
- From: C.M.G.
- Re: log off command
- From: Matija Hrovat
- Re: log off command
- From: C.M.G.
- Re: log off command
- From: Matija Hrovat
- Re: log off command
- From: C.M.G.
- Re: log off command
- Prev by Date: Re: sound recorder
- Next by Date: Re: Why can't file name end in a period?
- Previous by thread: Re: log off command
- Next by thread: Re: log off command
- Index(es):
Relevant Pages
|