Page 1 of 1
Creating a batch file that displays workstation information
Posted: 16 Jul 2012 13:13
by mr_wizard
Hey folks, another DOS Batch inquiry, our help desk analysts often need to retrieve certain data from XP machines on our network. This typically involves remoting into the machine (using a third party remote control app) and navigating throughout the windows GUI to gather the information. I'd like to create a batch that uses the current analysts logged in credentials(a way of authenticating) to remotely retrieve a users information by supplying the target IP address (were all on the same WAN) and user profile name. It can either output this information to a text file or as a dialog prompt with an "Ok" button(preferred). Here are some of the things I'd like to get:
-Workstation Name
-Computer Model (i.e. Dell Optiplex 755)
-Domain
-Mapped network drives
-PC Serial Number
-Check for various softwares installed
-Overlay** (Listed in c:\Options\Updates\overlay.log)
If the batch fails to retrieve a said piece of info, it would simply output, "Unable to retrieve info" for the line. So the output log/dialog would look something like this:
-------------------------------------------------------------
Currently Logged in:
John.Smith
Workstation name:
DWS-DO-W--4LGDCF1
Computer Model:
Dell Optiplex 755
Domain:
North
Connected Network Drives:
M: \\mukgapd2p091.north.net\install
P: \\mukgapd2p091.north.net\shared
D: \\mukgapd2p091.north.net\userdata
PC Serial:
4LGDCG1
"Zerocool" installed:
No
"Investment Portfolio" installed:
Yes
"Outlook" installed:
Yes
----------------------------------------------------------
I am pretty familiar with batches (like nbtstat), but I'm very rough in taking found remote info and putting it all into a log file to display "like" the context above. Thanks for the help folks!
Re: Creating a batch file that displays workstation informat
Posted: 16 Jul 2012 15:50
by abc0502
Hi, Few Questions:
1> Do you want the analysts to input the ip one by one or use a list of ip or the batch has both options?
2> Is there too many programs installed on this remote computers?
3> If there is output file what type would you prefer txt, htm?
Re: Creating a batch file that displays workstation informat
Posted: 17 Jul 2012 06:52
by abc0502
When Accessing these remote Computers does the analysts input a username and password ?
Re: Creating a batch file that displays workstation informat
Posted: 17 Jul 2012 07:19
by mr_wizard
abc, thank you for the response! The Analysts require a domain/username and password. We primarily use c$ for any ftp, and they have admin rights to these machines.
The reason we need to find out if "certain" software is installed, is usually for imaging purposes. If the HDD needs to be replaced, there's certain info we need to gather for the imaging team to put together a new hdd image for them.
It would preferably be in a .txt format.
Re: Creating a batch file that displays workstation informat
Posted: 17 Jul 2012 08:31
by abc0502
sorry for asking too much question, i don't have much experince in server and remote connection with other pc but when you say
The Analysts require a domain/username and password. We primarily use c$ for any ftp
do you mean the same way that when i try for example accessing a shared folder over a network a pop up winodw comes and ask for a username and password to gain access?
And using C$ does that mean u have complete access to this drive?
I'm almost finished but making final adjustments
Re: Creating a batch file that displays workstation informat
Posted: 17 Jul 2012 08:56
by mr_wizard
Not a problem abc! Thanks for taking your time to help with this.
With c$ I mean:
example:
\\10.167.2.126\c$
or
example
\\10.167.2.126\c$\Program Files\Internet Explorer
Running that ^ at the Run prompt. Windows automatically uses the domain/username and password credentials that are currently logged into the analysts machine to authenticate permissions and access said IP address' C:/ directory in a folder. It was sort of irrelevant to what you were asking, but hoped it may clarify the setup we have here. Everyone here is on the same WAN.
When we issue commands remotely, we primarily use prompt / dos / cmd with their IP address in context. Telnet, netview, net send, copy, etc...
Here's a snippet of a batch I wrote for remotely refreshing a users XP Profile:
@echo off
set /p ip= Enter the computers IP:
echo The ip is %ip%
set /p username= Enter the users Windows logon ID:
echo The username is %USERNAME%
set mydate=%date:~4,2%%date:~7,2%%date:~10,4%
@echo off
setLocal EnableDelayedExpansion
echo Please properly shut down Smartstation at this time then wait for the batch to complete.
@echo off
copy "C:\Documents and Settings\x77577.ad-ent\Desktop\Delete_Restore.bat" "\\%ip%\c$\Delete_Restore.bat"
copy "C:\Documents and Settings\x77577.ad-ent\Desktop\restore.bat" "\\%ip%\c$\Documents and Settings\All Users\Start Menu\Programs\Startup\restore.bat"
:loop3
@echo Waiting...
@echo off
tasklist /s %ip% | find /i /c "thomsonone.exe"
sleep 1
if errorlevel 0 goto :loop3
echo Smartstation shut down, now restarting users PC...
@echo off
shutdown -r -m \\%ip% -f
@echo off
:loop
ping -n 1 %ip% | find /i "reply"
sleep 1
if errorlevel 1 goto :loop
sleep 3
echo PC is now off, now waiting for ping response...
@echo off
:loop2
ping -n 1 %ip% | find /i "reply"
sleep 1
if errorlevel 1 goto :loop2
sleep 2
echo Refreshing profile...
rename "\\%ip%\c$\Documents and Settings\%USERNAME%" %USERNAME%.%mydate%
echo Complete.
sleep 1
echo Please have the user log in and wait until this batch completes.
sleep 30
@echo off
:loop4
tasklist /s %ip% | find /i /c "thomsonone.exe"
sleep 2
if errorlevel 0 goto :loop4
if errorlevel 1 goto :delrestore
:delrestore
@echo off
del "\\%ip%\c$\Documents and Settings\All Users\Start Menu\Programs\Startup\restore.bat"
echo Completed. Verify that Desktop, Favorites, My Documents, Outlook, and Workspaces have all been restored.
pause
Basically it renames the users profile, then copies a separate Batch file to the Admin startup folder that copies over important files from their old profile after restarting.
These are typically the methods we use
Thanks again abc!
Re: Creating a batch file that displays workstation informat
Posted: 18 Jul 2012 11:08
by abc0502
Very Important Note Added
/I switch in the If statement in Outlook Search Code
Hi, I finally finished sorry if it took too much time but i didn't have a remote system to test on.
,So I made it to collect data locally then added the remote switches and in theory it sould work.
Important Notes:> when prompting to enter user name it should be on that formate
Domain\username.
> The logo and name you can change it i just made it for fun so find a suitable one
> I added explanation almost for every command so modifying it should be easy.
> If it didn't work i had a nother idea found it when i was working onb this batch, i will explain it after this batch.
Hope it work
Code: Select all
@echo off
Cls
MODE 74,32
Color 0A
Title Remote Systems Information Gathering :)
:: The Following is a Batch Logo { Just for Example, change if needed or remove }.
echo.&echo.&echo.&echo.&echo.&echo.
SET /P ".= "<nul &Call :Color 0E "###### ##### ### ##### " end&echo.
SET /P ".= "<nul &Call :Color 0E "# # # # # # # " end&echo.
SET /P ".= "<nul &Call :Color 0E "# # # # # " end&echo.
SET /P ".= "<nul &Call :Color 0E "###### ##### # # #### " end&echo.
SET /P ".= "<nul &Call :Color 0E "# # # # # # " end&echo.
SET /P ".= "<nul &Call :Color 0E "# # ### # # ### # ### # # " end&echo.
SET /P ".= "<nul &Call :Color 0E "# # ### ##### ### ### ### ##### " end&echo.
echo.
SET /P ".= "<nul &Call :Color 09 "========================================" end&echo.
SET /P ".= "<nul &Call :Color 09 "=" &Call :Color 0C " R" &Call :Color 0f "emote" &Call :Color 0C " S" &Call :Color 0f "ystems" &Call :Color 0C " I" &Call :Color 0f "nformation" &Call :Color 0C " G" &Call :Color 0f "atharing" &Call :Color 09 " =" end&echo.
SET /P ".= "<nul &Call :Color 09 "========================================" end&echo.&echo.&echo.
:: The Following Code is for the Analysts to Input IP, Username and Passwords.
SET /P ".= "<nul &Call :Color 0C "Enter Computer IP " &SET /P ".= "<nul end
set /p "TIP= "
set "IP=%TIP%"
echo.
SET /P ".= "<nul &Call :Color 0C "Remote PC Username " &SET /P ".= "<nul end
set /p "uname= "
set "User=%uname%"
echo.
SET /P ".= "<nul &Call :Color 0C "Remote PC Password " &SET /P ".= "<nul end
set /p "upass= "
set "Pass=%upass%"
cls
Echo.&Call :Color 05 "Please wait,..." end&echo.
:: The Following Command check to see if there was a previous info in the same day for an IP
:: if so, it delete all files in that folder and write the new one into it.
IF Exist "%userProfile%\Desktop\%IP%_Info %date:/=%" ( Del /f /Q "%userProfile%\Desktop\%IP%_Info %date:/=%\*.*" >nul
) Else ( MD "%userProfile%\Desktop\%IP%_Info %date:/=%" >nul )
:: The Following is the main locations
set "folder=%userProfile%\Desktop\%IP%_Info %date:/=%"
set "list=%folder%\list.txt"
set "Report=%folder%\Report.txt"
set "Overlay=%folder%\overlay.log"
:: The following is temporary files that will be deleted at the end
set "f1=%folder%\1.txt"
set "f2=%folder%\2.txt"
set "f3=%folder%\3_1.txt"
set "f4=%folder%\3_2.txt"
set "f5=%folder%\4.txt"
set "f6=%folder%\5.txt"
set "f7=%folder%\6.txt"
:: The Following Codes are sent to the temporary files.
:: This is for the current logged-in user.
WMIC /user:"%User%" /password:"%Pass%" /NODE:%IP% /output:"%f1%" COMPUTERSYSTEM GET UserName /value
:: This is for the workstation name.
WMIC /user:"%User%" /password:"%Pass%" /NODE:%IP% /output:"%f2%" COMPUTERSYSTEM GET Name /value
:: This is for the PC model, the 1st for Manufacture name and the 2nd for model number.
WMIC /user:"%User%" /password:"%Pass%" /NODE:%IP% /output:"%f3%" COMPUTERSYSTEM GET Manufacturer /value
WMIC /user:"%User%" /password:"%Pass%" /NODE:%IP% /output:"%f4%" COMPUTERSYSTEM GET Model /value
:: This is for the domain name.
WMIC /user:"%User%" /password:"%Pass%" /NODE:%IP% /output:"%f5%" COMPUTERSYSTEM GET Domain /value
:: This is for the mapped network drives.
WMIC /user:"%User%" /password:"%Pass%" /NODE:%IP% /output:"%f6%" logicaldisk get caption, providername
:: This is for the PC serial number [ Note that It doesn't appear in my PC ]
WMIC /user:"%User%" /password:"%Pass%" /NODE:%IP% /output:"%f7%" BIOS GET SerialNumber /value
:: This is for getting a list of all installed programs in the remote PC.
IF Exist "%list%" Del /F /Q "%list%"
WMIC /user:"%User%" /password:"%Pass%" /NODE:%IP% /output:"%list%" product get name
:: Zerocool [ check to see if this software installed or not ].
For /f "skip=2 tokens=* delims= " %%c in ('find "Zerocool" "%list%"') Do (
If %errorlevel%==0 Set "Zerocool=Installed" &goto skip1
)
Set "Zerocool= Not Installed"
:skip1
:: The Following will map to \\%IP%\C$ on the remote PC.
NET USE \\%IP%\C$ "%Pass%" /USER:%User%
:: This will copy the Overlay log file
Pushd "\\%IP%\C$\Options\Updates"
Copy /Y "overlay.log" "%Overlay%"
:: Outlook [ Check to see if this software installed or not ].
For /f %%a in ('Dir /B /A:-D /S ""') do (
If /I %%~na==outlook.exe ( Set "Outlook=Installed"
) Else ( Set "Outlook=Not Installed" )
)
Popd
NET USE \\%IP%\C$ /delete
:: Investment Portfolio [ Check to see if this software installed or not ].
For /f "skip=2 tokens=* delims= " %%d in ('find "Portfolio" "%list%"') Do (
If %errorlevel%==0 Set "Portfolio=Installed" &goto skip2
)
Set "Portfolio=Not Installed"
:skip2
::The Following is the semi-final stage before listing the required information.
:: Collect required data from the temporary files and set it's value to variables.
:: The Zerocool, Portfolio and Outlook will be used as it from the previous codes.
For /f "skip=2 tokens=2 delims==" %%A in ('find "=" "%f1%"') Do set logged_name=%%A
For /f "skip=2 tokens=2 delims==" %%B in ('find "=" "%f2%"') Do set workstation_name=%%B
For /f "skip=2 tokens=2* delims==" %%C in ('find "=" "%f3%"') Do set model1_name=%%C
For /f "skip=2 tokens=2* delims==" %%D in ('find "=" "%f4%"') Do set model2_name=%%D
For /f "skip=2 tokens=2 delims==" %%E in ('find "=" "%f5%"') Do set domain_name=%%E
For /f "skip=2 tokens=2 delims==" %%G in ('find "=" "%f7%"') Do set pc_serial=%%G
:: The Following is the information seen by the analysts after collecting required data.
CLS
echo.
SET /P ".= "<nul &Call :Color 0F "===============================" end&echo.
SET /P ".= "<nul &Call :Color 0F "=" &Call :Color 0E " PC - %IP% Report" &Call :Color 0F " =" end&echo.
SET /P ".= "<nul &Call :Color 0F "===============================" end&echo.&echo.
Call :Color 0C " Currently Logged User" &SET /P ".= %logged_name%" <nul end&echo.&echo.
Call :Color 0C " Workstation Name" &SET /P ".= %workstation_name%" <nul end&echo.&echo.
Call :Color 0C " Computer Model" &SET /P ".= %model1_name% %model2_name%" <nul end&echo.&echo.
Call :Color 0C " Domain" &SET /P ".= %domain_name%" <nul end&echo.&echo.
Call :Color 0C " Connected Network Drives " end&echo.
:: This command search using a "word" based on the first 4 charachters of the network IP.
For /f "skip=2 tokens=* delims= " %%F in ('find "%IP:~0,4%" "%f6%"') Do echo %%F
echo.
Call :Color 0C " PC serial" &SET /P ".= %pc_serial%" <nul end&echo.&echo.
Call :Color 0C " Zerocool" &SET /P ".= %Zerocool%" <nul end&echo.&echo.
Call :Color 0C " Investment Portfolio" &SET /P ".= %Portfolio%" <nul end&echo.&echo.
Call :Color 0C " Outlook" &SET /P ".= %Outlook%" <nul end&echo.&echo.
Call :Color 08 "Press any key to continue " end
pause >nul
CLS
:: The Following Code will remoe any old reports and then create the final report file.
IF Exist "%Report%" Del /F /Q "%Report%"
(
Echo.
Echo. ===============================
Echo. = PC - %IP% Report =
Echo. ===============================
Echo. Currently Logged User : %logged_name%
Echo. Workstation Name : %workstation_name%
Echo. Computer Model : %model1_name% %model2_name%
Echo. Domain : %domain_name%
Echo. Connected Network Drives :
For /f "skip=2 tokens=* delims= " %%F in ('find "%IP:~0,4%" "%f6%"') Do echo %%F
Echo.
Echo. PC serial : %pc_serial%
Echo. Zerocool : %Zerocool%
Echo. Investment Portfolio : %Portfolio%
Echo. Outlook : %Outlook%
)>>"%Report%"
:: This code delete temporary files "f1:f7".
Del /F /Q "%f1%" "%f2%" "%f3%" "%f4%" "%f5%" "%f6%" "%f7%" >nul
:: The Following will display a message to tell the analysts where Report.txt, Overlay.txt and list.txt exist.
CLS
Echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.
SET /P ".= "<nul &Call :Color 0C "All Data saved in" end&echo.&echo.
Echo %folder%
Echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.
SET /P ".= "<nul &Call :Color 08 "Press any Key to" &Call :Color 0F " Exit" end
pause >nul
Goto EOF
:: The Following is the color function
:Color
set /p ".= " > "%~2" <nul
findstr /v /a:%1 /R "^$" "%~2" nul 2>nul
set /p ".=" <nul
if "%3" == "end" set /p ".= " <nul
del "%~2" >nul 2>nul
exit /b
::Resources:
:: http://www.techrepublic.com/forum/questions/101-307918/determine-what-user-is-logged-in-remotely-command-line
:: http://www.techrepublic.com/forum/questions/101-215911/dos-command-to-list-all-installed-programs
:: http://www.robvanderwoude.com/batchcommands.php
:: http://www.codeproject.com/Questions/265459/HOW-TO-ACCESS-A-SHARED-FOLDER-VIA-COMMAND-LINE
:: http://community.spiceworks.com/how_to/show/
:: http://stackoverflow.com/questions/3716422/how-can-i-map-a-network-drive-without-hardcoding-a-drive-letter-as-a-batch-file
:: http://www.google.com
All Resources are at the end of the batch.
Re: Creating a batch file that displays workstation informat
Posted: 18 Jul 2012 11:22
by abc0502
The Other Idea is as follow:
1> Create a Gmail Account for example:
InfoCenter@gmail.com2> Create two batch Files, (1) Trigger & (2) Feedback
The Trigger will be in the Analysts Computers it's main job is to take IP address and username and password and an e-mail to send the data to, then it connect to the C$ using NET USE command and run the "Feedback".
The Feedback main job is collecting data that has been design to collect, make a Report and send the Reports to the e-mail the analysts provided when he run the Trigger batch.
By that you reduce the errors of the remote collecting data that might happen and the time will be less.
You can use that if you ended with a dead end batch
Re: Creating a batch file that displays workstation informat
Posted: 23 Jul 2012 11:44
by mr_wizard
ABC, this is fantastic. I will report back with how it turns out in our environment.
You rock.