Solved

logoff n shutdown

Posted on 2008-10-04
17
966 Views
Last Modified: 2010-05-18
vbs code to logoff and shutdown pc without any user permission.
0
Comment
Question by:ankur3020
  • 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
 

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 50 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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 50 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now