[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Automated Logoff Remote PC's in batch or vbscript

Posted on 2013-05-28
12
Medium Priority
?
511 Views
Last Modified: 2013-05-31
I have about 50 PC's that I need to logoff the users in order to perform a backup of their profiles. I have a TXT file that contains OS - IP - Computername (WIN_7 - 10.10.10.10 - MYPC) in that format. I'm still in the process of learning VB and batch scripts. I need to be able to log off the remote PC's before launching the backup so I can get a clean backup of their PST files.  I'm looking for either VB or batch file to

1) Read the txt file to populate "computername" variable
2) pass the variable to process to logoff the remote PC
3) Loop until EOF


I have tried successfully with psshutdown with my XP systems, but this command seems to not work with Windows 7 computers. I can use shutdown to restart the computer, but I would rather just log the user off.
Can someone help me with some code to make this happen.
0
Comment
Question by:rraymond1130
[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
  • 5
  • 4
  • 3
12 Comments
 
LVL 15

Assisted Solution

by:ZabagaR
ZabagaR earned 750 total points
ID: 39202703
I just tried this and it worked for me.  I auto-logged off 3 remote machines.
My text file of computers is c:\servers.txt (change to your liking below).
You need to edit the username & password too so you have the right credentials in your domain/workgroup to do it.

mytest.vbs
-----------------------------------------------------------------

Const ForReading = 1
sUser = "username"
sPassword = "password"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\servers.txt", ForReading)

Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    arrServiceList = Split(strNextLine , ",")
    sClient= arrServiceList(0)
 Set oLocator = CreateObject("WbemScripting.SWbemLocator")
 On error resume next
 Set oConnection = oLocator.ConnectServer(sClient, _
   "root\cimv2", sUser, sPassword)
 Set oWindows = oConnection.ExecQuery("Select " & _
   "Name From Win32_OperatingSystem")
 For Each oSys In oWindows
   oSys.Win32ShutDown(4)
 Next
Loop
ObjTS.Close
0
 
LVL 15

Expert Comment

by:ZabagaR
ID: 39202721
forgot to say : my text file c:\servers.txt just had a list of IP addresses of the machine's I wanted to log off. Is that okay?
0
 
LVL 25

Expert Comment

by:Lionel MM
ID: 39204212
If you goal is to copy their profiles then if you only do a logoff some of the files will not be copied and will show up as in use. As such you will be better served with doing a reboot. All you will need is a list of all your PC names (system names--works on servers too) and then run this
for /F "skip=1 tokens=1 delims=," %%i in (C:\Utils\PC-Names.Txt) do shutdown -f -r -t 240 -m %%i
As long as the user that runs this has the required privileges this is all that is needed. I run this from my server once a week (for a different reason) and it works--has for years. This will cause a reboot in 2 minutes (-t 240) if you want it to happen immediately change that to -t 0. You can also add -c "and any comment you want to show up on their pc" (enclose in quotes).
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:rraymond1130
ID: 39204441
ZabagaR I tried you code this morning on a workstation running Windows 7 64Bit. It doesn't log off the computer. I have several Win 7 64bit systems. I will run this test on a Win XP system which we have a majority of.

 Lionelmm thanks for your input. Ultimately I would like to just logoff the user. But if I can't get ZabagaR's solution to work I may have to go your route. I will check back later.
0
 
LVL 15

Expert Comment

by:ZabagaR
ID: 39204449
Do the credentials you're using apply to the Windows 7 64-bit machine(s)?
I tested with three Windows 2008 64-bit servers, running the command from my desktop PC. I think as long as you have the proper rights on those systems it will log you off.
0
 

Author Comment

by:rraymond1130
ID: 39204652
OK Update ZaBagaR your code worked logging off a Windows XP workstation but not a Windows 7 64bit workstations. If there is something that has to be tweaked to make it work with Windows 7 64bit systems that will be a great help.

Lionelmm your code works with both XP and 7, I figured out that you had to add \\ to the system name or IP Address for your code to work. I ultimately would like to Logoff the systems not restart them. The restart code would help to restart the systems once a week, but restarting them every night to run a backup is a little much.
0
 
LVL 25

Accepted Solution

by:
Lionel MM earned 750 total points
ID: 39204840
You can just as easy use a batch file to create a one-time or a daily scheduled task. You can run this from any system  and setup a scheduled task on a  remote system.
http://www.robvanderwoude.com/schtasks.php (see options and examples)

 for /F "skip=1 tokens=1 delims=," %%i in (C:\Utils\PC-Names.Txt) do SCHTASKS /Create /S %%i /U username /P password /SC once /TN Logoff PCs /ST time SD Start date /TR C:\Windows\System32\shutdown.exe -l

This will run once so you can run the batch file whenever or you can run this once and setup the scheduled task to run wherever you want it to.k
0
 

Author Comment

by:rraymond1130
ID: 39205180
Lionelmm Your above solution works Windows 7 64bit computers but I get access denied running it on a Windows XP PC and I'm using the domain admin information.
0
 

Author Comment

by:rraymond1130
ID: 39205188
I'm even running this from a CMD prompt with elevated privileges and still access denied on WinXP. Windows 7 64bit goes straight through. This is crazy..
0
 
LVL 25

Expert Comment

by:Lionel MM
ID: 39205255
try /ru and /rp on XP instead of /u  and /p. and try using /U Domain-Name\username instead of just /U username
0
 
LVL 25

Expert Comment

by:Lionel MM
ID: 39205272
this shows you that these commands should work on XP--these are for XP options
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/schtasks.mspx?mfr=true
0
 

Author Closing Comment

by:rraymond1130
ID: 39211335
Ok, I'm going to have to split this one because I was able to use both solutions. Thanks for the help guys.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This is a little timesaver I have been using for setting up Microsoft Small Business Server (SBS) in the simplest possible way. It may not be appropriate for every customer. However, when you get a situation where the person who owns the server is i…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

656 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