?
Solved

logoff n shutdown

Posted on 2008-10-04
17
Medium Priority
?
973 Views
Last Modified: 2010-05-18
vbs code to logoff and shutdown pc without any user permission.
0
Comment
Question by:ankur3020
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
  • 3
17 Comments
 
LVL 20

Expert Comment

by:ltlbearand3
ID: 22642166
The below script will shutdown the PC.  It will give the user a one minute warning.  Just copy the code and paste into notepad.  Save the file as shutmedown.vbs and run it.

You can open a command prompt and type shutdown to see all the switches available.  This could also be done as a batch file --

Echo Off
shutdown /s

Dim objShell
Set objShell = CreateObject("Wscript.Shell")
objShell.run "shutdown /s"

Open in new window

0
 
LVL 5

Expert Comment

by:si_shamil
ID: 22642408
you don't need to use vbscript for that
just use a "shutdown.exe"  utility

Example: shutdown -s -t 0
and if you want to force it: shutdown -s -t 0 -f

or you can create a batch file:
@echo off
title Shutting down the system...
 
shutdown -s -t 0

Open in new window

0
 
LVL 20

Expert Comment

by:ltlbearand3
ID: 22642715
Please note that the switches are different on Vista.  Please use the switches as noted on my first post.  If you want to do the shutdown with no warning you can do shutdown /s /f /t 0

As both I and si_shamil state, this can be done in DOS or vb script.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ankur3020
ID: 22643365
i tried this on vista, but it is not doing anything.

Dim objShell
Set objShell = CreateObject("Wscript.Shell")
objShell.run "shutdown /s/f/t 0"

if i remove /f/t 0 then it is working but system shutdown after 1 min. i want force shutdown/logoff.
can shutdown be relpaced with logoff
please check
0
 
LVL 5

Expert Comment

by:si_shamil
ID: 22643534
I think you have typo in the command. use space after each parameter:

shutdown /s /f /t 0

all parameters separated - (/s)   (/f)  (/t 0)

0
 

Author Comment

by:ankur3020
ID: 22643817
i made a vbs file with following code. when i ran it , it did nothing. just a cmd flickered and hide.

Dim objShell
Set objShell = CreateObject("Wscript.Shell")
objShell.run "shutdown (/s) (/f) (/t 0)"


please make a vbs , test it in vista and attach. or email me at ankurjain30@gmail.com
0
 
LVL 5

Assisted Solution

by:si_shamil
si_shamil earned 200 total points
ID: 22643825
Copy and paste this code

Set objShell = CreateObject("Wscript.Shell")
objShell.run "shutdown /s /f /t 0"

Open in new window

0
 

Author Comment

by:ankur3020
ID: 22644924
i copied and run, nothing happened, again just cmd flicked for a second only. even this time i tried in xp.
0
 
LVL 5

Expert Comment

by:si_shamil
ID: 22644956
Can you provide more info:

1: how you running the script
2: which extension you use for the script file
3: can you post here the script you ran
0
 

Author Comment

by:ankur3020
ID: 22645140
i retried but it works this time. i think it afraid of u.  thanks

can u tell me if i have to call logoff then what i should write in place of shutdown?
0
 
LVL 5

Expert Comment

by:si_shamil
ID: 22645151
This wil do:
Set objShell = CreateObject("Wscript.Shell")
objShell.run "logoff"

Open in new window

0
 

Author Comment

by:ankur3020
ID: 22645173
without any /s /f and /t ?
0
 

Author Comment

by:ankur3020
ID: 22645183
i ran the following code in vista and got error
"system can not find the file specified"

Set objShell = CreateObject("Wscript.Shell")
objShell.run "logoff"

Open in new window

0
 
LVL 5

Assisted Solution

by:si_shamil
si_shamil earned 200 total points
ID: 22645494
try this then:
Set objShell = CreateObject("Wscript.Shell")
objShell.run "shutdown /l"

Open in new window

0
 
LVL 20

Expert Comment

by:ltlbearand3
ID: 22646861
I am sorry, I forgot in Vista the /f does not work when used with /t as /t forces the logoff.  Try the below as your script --

Dim objShell
Set objShell = CreateObject("Wscript.Shell")
objShell.run "shutdown /s /t0"

Open in new window

0
 

Accepted Solution

by:
ankur3020 earned 0 total points
ID: 22646862
it worked , thanks a lot
0
 
LVL 5

Expert Comment

by:si_shamil
ID: 22647294
You welcome!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

765 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