Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: How to Create a Batch file for last logged on for a remote use

02 Sep 2014   #1
Zealous637

Win 7 Pro
 
 
How to Create a Batch file for last logged on for a remote use

So I am looking to create some kind of batch file or script where I can click on it....it asks for the machine name, I enter it and then it displays the last logged on user. The following command
" wmic /NODE:"computername" computersystem get Username" gives me the desired results but I am trying to automate the process. I appreciate any help


My System SpecsSystem Spec
.
02 Sep 2014   #2
Tookeri

Windows 7 Pro 32
 
 

Like this?
Code:
@ECHO OFF
SET MACHINENAME=%1
IF [%1]==[] GOTO SETNAME
GOTO END
:SETNAME
ECHO Type the machine name, press ENTER, Ctrl+Z, ENTER
FOR /F "tokens=*" %%A IN ('TYPE CON') DO SET INPUT=%%A
SET MACHINENAME=%INPUT%
:END
rem ECHO "%MACHINENAME%"
wmic /NODE:"%MACHINENAME%" computersystem get Username | find "\"
pause
Put that in a bat file and run it and it will ask for a machine name. The tricky thing is it needs a 3 step ENTER + Ctrl+Z + ENTER to exit the input mode. (that's the best I could do for a quick solution)

I made it so you can also call it with a parameter, then it won't ask for a machine name. Example:
C:\>GetLastUser.bat SERVER12
SERVER12\JOHN
My System SpecsSystem Spec
02 Sep 2014   #3
Zealous637

Win 7 Pro
 
 

Perfect!!!...thanks for your help Tookeri
My System SpecsSystem Spec
.

02 Sep 2014   #4
Tookeri

Windows 7 Pro 32
 
 

You're welcome! It's always fun to write some code
My System SpecsSystem Spec
02 Sep 2014   #5
Layback Bear

Windows 7 Pro. 64/SP-1
 
 

Just curious.
Is this secure?
If anybody new the machines name they could work without a password off the previous users account. Or I'm I crazy.
My System SpecsSystem Spec
02 Sep 2014   #6
Zealous637

Win 7 Pro
 
 

you arent looking up the password. You are just looking up the username of a person who was last logged onto that machine. So yes its secure.
My System SpecsSystem Spec
02 Sep 2014   #7
Layback Bear

Windows 7 Pro. 64/SP-1
 
 

I think I understand now.
All you get is the last person logged in and no password.
Your also not able to use the computer under the last person log in without the password.
So after retrieving the last logged in person nothing can be done on this computer until someone logs in with a password.

My thought were if someone left the computer and forgot to log out once the bat file was run anybody could use the computer under the other person log in.

What makes me think of such things??
My System SpecsSystem Spec
02 Sep 2014   #8
Tookeri

Windows 7 Pro 32
 
 

Quote   Quote: Originally Posted by Layback Bear View Post
What makes me think of such things??
Paranoia?! The script only tells who logged in last. Nothing more nothing less. It's like going that machine and looking at the locked screen information, assuming the screen is locked. That will also tell you who is logged in. It's not much to abuse by that information.
My System SpecsSystem Spec
02 Sep 2014   #9
Layback Bear

Windows 7 Pro. 64/SP-1
 
 

Thanks for the information. I use paranoia as another layer of security protection.
My System SpecsSystem Spec
Reply

 How to Create a Batch file for last logged on for a remote use




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
create a popup reminder using batch file
Hi there, In XP I used 2 batch files to create a popup reminder in a cmd window. I don't want to use a program like task manager as it requires to much input for the type of reminder I want. With these batch files I would run one of them, enter a time, enter a description and that was it. A cmd...
General Discussion
Need help to create batch file for IE with following settings
I am new here and wanted some help. I wanted to know if I can do some internet explorer setting using batch file. Settings would be like this A - Home page - about:blank A.1 - Browsing history - marked on delete browsing history on exit. A.1.1 - Settings - enables radio button (Every time...
Chillout Room
Run Batch File On Remote Computer Without PsExec
Ok imma give a full rundown of the situation. Currently on the network we are on because of the way it is setup wake on lan doesn't work, so SCCM has at best a 70 success rate for patching. So I am currently spending a couple days a week remoting into computers and running a batch file to manually...
Installation & Setup
Is it possible to create a windows batch file to do this?
I generally run windows aero theme across all four monitors which i am happy with. However when i run a music app called cubase 5, i hear all sorts of squeaks and glitches when i simply move my cursor around the screen. The problem resolves itself when i switch to the standard windows classic...
General Discussion
Batch file to create a folder with name of the time.
I'm trying to write a batch file that when run creates a folder named "Backup" followed by the time it was created, and then copies files to that folder. When I run md "C:\Users\MasterControlProgram\Documents\MC Server With Backup\Backups\Backup %DATE%\" xcopy /e /v /y...
Backup and Restore
How to create a batch file that will move files based on the file type
How to create a batch file that will move files based on the file type? My Requirement : I need a batch file to copy all .doc files in all my HardDisk to a removable disk say (Z: drive) . Can anyone make it possible using a batch file?Please...Its urgent...
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 11:42.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App