# how to do this batch file please help



## saroosh2008 (Apr 19, 2008)

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 (Aug 8, 2007)

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


```
@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 (Apr 19, 2008)

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 (Aug 8, 2007)

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:


```
@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 _currentdate_Driveinfo.csv


```
@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 - _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_


----------



## saroosh2008 (Apr 19, 2008)

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 (Apr 4, 2003)

You know there is existing software out there that does this.


----------



## TheOutcaste (Aug 8, 2007)

saroosh2008 said:


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


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:

*wmic qfe*, *systeminfo*, or the qfecheck tool
*reg query* to read run keys, *dir* for starup folders, or *wmic startup*
*reg query* to read it from registry, *systeminfo* piped to *Find*
*reg query* to read it from registry, *systeminfo* piped to *Find*
*Ver*, *systeminfo* piped to *Find*
*Ver*, *systeminfo*
*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


----------



## saroosh2008 (Apr 19, 2008)

thank you jerry you are a great man but i did the batch it didn't gave me the CSV format thanx


----------



## TheOutcaste (Aug 8, 2007)

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


----------



## saroosh2008 (Apr 19, 2008)

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 (Aug 8, 2007)

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"
*


----------

