Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBS and FSutil Query

Status
Not open for further replies.

trevorh13

Instructor
Sep 18, 2000
132
GB
I am an IT Trainer and am preparing some disk images for our students to use in troubleshooting labs. I need a script that I can run that will query the freespace on c: save the result to a variable that is then passed to fsutil to create a file filling up the hard disk. (my students need to identify that the 'user' cannot save a file because the hard disk space is exhausted. I am not a programmer but have managed to stitch together the following script from various places.

Set objWMIService = GetObject("winmgmts:")
Set objLogicalDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='c:'")
FileSize = objLogicalDisk.FreeSpace
Wscript.Echo FileSize
Set fso = CreateObject("Scripting.FileSystemObject")
set shl = createobject("wscript.shell")
shl.run "fsutil file createnew C:\incredible.hlk" FileSize,0,true

The wscript.echo filesize is showing the freespace so I am confident that the problem lies in the last line.

Could anyone offer me any advice on where I am going wrong?

Kind regards

Trevor
 
Your FileSize needs to be part of the command string. Try
Code:
shl.run "fsutil file createnew C:\incredible.hlk" [b][red]&[/red][/b] FileSize, 0, true

Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
Hiya,

Thankyou for responding. I have amended the last line as you describe but the file is not made on c: and no error is reported.

Anybody got any ideas?

Kind regards

Trevor
 
shl.run "fsutil file createnew C:\incredible.hlk " & FileSize, 0, true

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
My bad. I second PHV. Please note the trailing space after .hlk.

Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
Many thanks to both of you for your invaluable assistance. I also found that I needed to include Wscript.Quit as the last line for the file to be created.

Once again ... many thanks

Kind regards

Trevor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top