There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
antivirus audio avg avg 8 backup bios boot browser bsod computer cpu crash css desktop driver dvd email error excel explorer firefox firefox 3 freeze game graphics hard drive hardware help please hijackthis hjt install internet internet explorer itunes javascript keyboard lan laptop malware missing monitor msn network networking openoffice outlook outlook 2003 outlook express php popups problem router screen seo slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp wireless word
DOS/PDA/Other
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Operating Systems > DOS/PDA/Other >
how to do this batch file please help


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
saroosh2008's Avatar
Junior Member with 7 posts.
 
Join Date: Apr 2008
20-Apr-2008, 01:36 PM #1
how to do this batch file please help
This batch run at any time to check the number of partitions on a system and check and record the free space for each partition. This information is to be stored in a text file on the server using the computer name and data as the name of the file
TheOutcaste's Avatar
Computer Specs
Senior Member with 1,537 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
21-Apr-2008, 10:45 AM #2
What OS is running on the target systems?.
Makes a big difference if it's Win9x, Win2K, or XP/Vista
The following will work on XP or Vista, but not Win2K or Win9x

Code:
@echo off
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:The following may vary depending on your Regional settings
:This assumes US format, i.e. echo %date% gives Mon 04/01/2008
:_t1=Day (Mon), _t2=Month (04), _t3=Date (01), and _t4=Year (2008)
:_t5 is filename to use, ie, 2008-04-08-PCName.log
:_t6 should be set to the UNC path to the server where the file will be stored
:You must have write access to that share from the Target PC account that
:this batch file is run under
:Example, to store them on server 1 in the DriveInfo folder under the Logs share:
:set _t6=\\Server1\Logs\DriveInfo\
:Change the order on the Set _t5 line if you want the PC name first
:_t7 is the drive type to find
:2 Removable (floppy/Flash)
:3 Hard Drive
:4 Mapped Drive
:5 CD Rom
:If you want to list all drive types, comment the line
:with the find statement and un-comment the line
:without the find statement
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
for /f "tokens=1-4 delims=/ " %%I in ("%date%") do Set _t1=%%I& Set _t2=%%J& Set _t3=%%K& Set _t4=%%L
set _t5=%_t4%-%_t2%-%_t3%-%ComputerName%.log
set _t6=\\Server1\Logs\DriveInfo\
set _t7=3
>%_t6%%_t5% echo.Drive   Type         Free Space    Total Space 
:This lists all drives
:>>%_t6%%_t5% (wmic logicaldisk get DeviceID,DriveType,Size,FreeSpace
:This lists just the specified Drive Type
>>%_t6%%_t5% (wmic logicaldisk get DeviceID,DriveType,Size,FreeSpace |find /i " %_t7% ")
for /L %%I in (0,1,7) do set _t%%I=
HTH

Jerry
saroosh2008's Avatar
Junior Member with 7 posts.
 
Join Date: Apr 2008
22-Apr-2008, 01:09 AM #3
thank you for the answers it was very helpful but how to run this batch do i have to copy the code to notpad and how i can add CSV file to gave me the report
OS is running on my systems is XP
thank you
TheOutcaste's Avatar
Computer Specs
Senior Member with 1,537 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
22-Apr-2008, 12:14 PM #4
Yes, just copy the code into notepad, save as a .bat or .cmd file

If you need CSV output, we can add the /format:csv switch to the command. This causes the PC name to be included in the output for some reason, so I've changed the header line as well:

Code:
@echo off
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:The following may vary depending on your Regional settings
:This assumes US format, i.e. echo %date% gives Mon 04/01/2008
:_t1=Day (Mon), _t2=Month (04), _t3=Date (01), and _t4=Year (2008)
:_t5 is filename to use, ie, 2008-04-08-PCName.csv
:_t6 should be set to the UNC path to the server where the file will be stored
:You must have write access to that share from the Target PC account that
:this batch file is run under
:Example, to store them on server 1 in the DriveInfo folder under the Logs share:
:set _t6=\\Server1\Logs\DriveInfo\
:Change the order on the Set _t5 line if you want the PC name first
:_t7 is the drive type to find
:2 Removable (floppy/Flash)
:3 Hard Drive
:4 Mapped Drive
:5 CD Rom
:If you want to list all drive types, comment the line
:with the find statement and un-comment the line
:without the find statement
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
for /f "tokens=1-4 delims=/ " %%I in ("%date%") do Set _t1=%%I& Set _t2=%%J& Set _t3=%%K& Set _t4=%%L
set _t5=%_t4%-%_t2%-%_t3%-%ComputerName%.csv
set _t6=\\Server1\Logs\DriveInfo\
set _t7=3
>%_t6%%_t5% echo.PC Name,Drive,Type,Free Space,Total Space 
:This lists all drives
:>>%_t6%%_t5% (wmic logicaldisk get DeviceID,DriveType,Size,FreeSpace /format:csv
:This lists just the specified Drive Type
>>%_t6%%_t5% (wmic logicaldisk get DeviceID,DriveType,Size,FreeSpace /format:csv |find /i ",%_t7%,")
for /L %%I in (0,1,7) do set _t%%I=
Just copy the code into a .bat or .cmd file. You can then run this file on each PC when needed, or set it as a scheduled task.

A better option instead of running this on each PC is to run it from the server and have it access the systems over the network. This also has the advantage of working with Win2K systems.
This will create a single file listing the info for each PC. If you need separate files for each PC, a simple for statement can read this single file and create individual files.
First, create a list in notepad of the PC names you want to check, one name per line.
Save this as pcnames.txt on the server and note the path
Then use this code, which will create a file named currentdateDriveinfo.csv

Code:
@echo off
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:The following may vary depending on your Regional settings
:This assumes US format, i.e. echo %date% gives Mon 04/01/2008
:_t1=Day (Mon), _t2=Month (04), _t3=Date (01), and _t4=Year (2008)
:_t5 is filename to use, ie, 2008-04-08-DriveInfo.csv
:_t6 should be set to the folder on the server where the file will be stored
:the pcnames.txt file should be in this same folder
:Example, to store them on server 1 in the DriveInfo folder under c:\Logs
:set _t6=c:\Logs\DriveInfo\
:Change the order on the Set _t5 line if you want the PC name first
:_t7 is the drive type to find
:2 Removable (floppy/Flash)
:3 Hard Drive
:4 Mapped Drive
:5 CD Rom
:If you want to list all drive types, comment the line
:with the find statement and un-comment the line
:without the find statement
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
for /f "tokens=1-4 delims=/ " %%I in ("%date%") do Set _t1=%%I& Set _t2=%%J& Set _t3=%%K& Set _t4=%%L
set _t5=%_t4%-%_t2%-%_t3%-DriveInfo.csv
set _t6=C:\Logs\DriveInfo\
set _t7=3
>%_t6%%_t5% echo.PC Name,Drive,Type,Free Space,Total Space 
:This lists all drives
:>>%_t6%%_t5% (wmic /failfast:on /node:@%_t6%pcnames.txt logicaldisk get DeviceID,DriveType,Size,FreeSpace /format:csv
:This lists just the specified Drive Type
>>%_t6%%_t5% (wmic /failfast:on /node:@%_t6%pcnames.txt logicaldisk get DeviceID,DriveType,Size,FreeSpace /format:csv |find /i ",%_t7%,")
for /L %%I in (0,1,7) do set _t%%I=
If you have firewalls enabled on the PCs, you may get the following error:
  • Node - [i]pcname[\i]
  • ERROR:
  • Code = 0x800706ba
  • Description = The RPC server is unavailable.
  • Facility = Win32

This means you'll need to allow Remote Administration through the firewall.
For the Windows firewall, goto the system named on the above Node line.
For Vista, enable Remote Administration on the Exceptions tab in Control Panel | Windows Firewall
For XP enter this at a command prompt:
netsh firewall set service remoteadmin enable subnet
or, to limit access to just the one server
netsh firewall set service remoteadmin enable custom 192.168.1.1

You can also set this from the Group Policy Editor (XP Pro/Vista)
Start | Run type gpedit.msc press enter
Navigate to Computer Configuration\Administrative Templates\Network\Network Connections\Windows Firewall folder.
If the computer is on a domain, then open the Domain Profile, otherwise, open the Standard Profile folder.
Double click Windows Firewall: Allow remote administration exception and set to enabled. Add the server address if you want to restrict address to one machine, or you can enter a subnet or the localsubnet (instructions on the properties page)

You can get help on any of these batch commands from the command prompt, just type the command name followed by /?, ie for /? will explain the for command.
Google can find tons of info as well.

HTH

Jerry
__________________
Of course I know all the answers ; I just don't always match the answers to the right questions

Warning -- Windows spoken here. (Rated R for Strong Language and Violence -- When your Windows PC flies through a window, that's violent, right?)

Last edited by TheOutcaste : 23-Apr-2008 04:28 AM. Reason: change file extension on frist section of code from .log to .csv
saroosh2008's Avatar
Junior Member with 7 posts.
 
Join Date: Apr 2008
22-Apr-2008, 01:04 PM #5
thank you for this help++++
batch file to be run at startup to list the following details configuration about the computer to the following:
i- Hot fixes applied
ii- programs that will start for all users when they loge on
iii- Windows XP product ID
iv- CSD Version
v- Build Number
vi- Product name
vii- System Bios Version

The batch file should also enter an event in the system registry to indicate this detailed information has been collected and the data
Squashman's Avatar
Distinguished Member with 12,216 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
22-Apr-2008, 06:46 PM #6
You know there is existing software out there that does this.
TheOutcaste's Avatar
Computer Specs
Senior Member with 1,537 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
22-Apr-2008, 10:53 PM #7
Quote:
Originally Posted by saroosh2008 View Post
batch file to be run at startup to list the following details configuration about the computer to the following:
i- Hot fixes applied
ii- programs that will start for all users when they loge on
iii- Windows XP product ID
iv- CSD Version
v- Build Number
vi- Product name
vii- System Bios Version

The batch file should also enter an event in the system registry to indicate this detailed information has been collected and the data
As Squashman points out there is a lot of software already out there for this, just search for PC Inventory, PC Audit, Network Inventory, or Network Audit.

If you want to do it yourself, the best way to learn how to write these types of scripts is to dive in and write some.

This info can be gotten using wmic, systeminfo (using find or findstr to pick out data you want), reg, and ver.
The For command can be a powerful tool, especially useful for parsing data using the tokens= and delims= options.
You can also parse a string of data by assigning it to an environment variable then extracting substrings using the :~start,length feature as explained in help for the SET command.

For the info you've listed above:
  1. wmic qfe, systeminfo, or the qfecheck tool
  2. reg query to read run keys, dir for starup folders, or wmic startup
  3. reg query to read it from registry, systeminfo piped to Find
  4. reg query to read it from registry, systeminfo piped to Find
  5. Ver, systeminfo piped to Find
  6. Ver, systeminfo
  7. wmic bios, systeminfo piped to Find
The Description you get from wmic bios may be more useful than the version number
On my Dell Dimension, version is DELL - 6, but the Description shows Phoenix ROM BIOS PLUS Version 1.10 A01
Help on these commands can be had by entering them into a command prompt and adding /? after the command.
Sysinternals has several tools that can be useful. Psinfo (under System Information link) will return disk size and space in MB or GB rather than bytes, as well as a free space percentage.

I don't know if there is a batch file command to write an entry into an event log, but that can be done with a simple VBscript. All of the above info can be gotten with a VBscript as well.
The Script Center is a good place to start, and you may find ready made scripts to do a lot of what you are looking for.

HTH

Jerry
__________________
Of course I know all the answers ; I just don't always match the answers to the right questions

Warning -- Windows spoken here. (Rated R for Strong Language and Violence -- When your Windows PC flies through a window, that's violent, right?)
saroosh2008's Avatar
Junior Member with 7 posts.
 
Join Date: Apr 2008
23-Apr-2008, 04:16 AM #8
I know there is software out there does this But i have to use the batch
thank you jerry you are a great man but i did the batch it didn't gave me the CSV format thanx
TheOutcaste's Avatar
Computer Specs
Senior Member with 1,537 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
23-Apr-2008, 04:33 AM #9
Which file did you use, the one to run on each PC, or the one from the server?
What format did you get? The first example should give the CSV format, but the file will have a .log extension instead of .csv, as I forgot to change it (just edited it now).
When I run the first one on this PC I get the following:
File name 2008-04-23-BAMMBAMM.log

PC Name,Drive,Type,Free Space,Total Space
BAMMBAMM,C:,3,68992507904,395043745792
BAMMBAMM,D:,3,123490516992,400085811200



Would help if you copy and paste the actual batch file you used and a couple of lines of the output file-- be sure to edit out any personal info you don't want shared such as pc/usernames that include the users last name.


Jerry
__________________
Of course I know all the answers ; I just don't always match the answers to the right questions

Warning -- Windows spoken here. (Rated R for Strong Language and Violence -- When your Windows PC flies through a window, that's violent, right?)
saroosh2008's Avatar
Junior Member with 7 posts.
 
Join Date: Apr 2008
24-Apr-2008, 11:16 AM #10
jerry i try it didn't work i need the batch in Simple way
To be run at startup to list the following details in csv configuration about the computer to the following:
i- Hot fixes applied
ii- programs that will start for all users when they loge on
iii- Windows XP product ID
iv- CSD Version
v- Build Number
vi- Product name
vii- System Bios Version

The batch file should also enter an event in the system registry to indicate this detailed information has been collected and the data

what is the command to find the programs that will start for all users when they loge on
thank you to you help
TheOutcaste's Avatar
Computer Specs
Senior Member with 1,537 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
24-Apr-2008, 11:58 PM #11
wmic startup as shown above

wmic startup /? will explain the options
wmic startup get /? will show the properties if you don't want all of them

You can add the line to any of the examples shown above.
Copy the line for one of the wmic commands and paste it in just below an existing line.
Change the filename if needed (the %_t6%%_t5% part)
change logicaldisk to startup
Change get to list and remove the DeviceID,DriveType,Size,FreeSpace properties, or
change the list of properties from DeviceID,DriveType,Size,FreeSpace to the properties you want
Change the Find command to find /i "all users"
__________________
Of course I know all the answers ; I just don't always match the answers to the right questions

Warning -- Windows spoken here. (Rated R for Strong Language and Violence -- When your Windows PC flies through a window, that's violent, right?)
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 06:26 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.