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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WScript.Run does not work

Status
Not open for further replies.

Obsolet

Technical User
Jun 28, 2007
6
NL
Hi!

I am very new in scripting so please don't blame me for my question.
I just want to script a very simple thing and when I did the web research I found many examples using Wscript.Run to run certain EXEs, like Notepad e.g.

The way it should work:

wscript.run("C:\windows\notepad.exe")

Here it does not work. It reports a WSH runtime error 800A01B6
"Object doesn't support this property or method: 'wscript.run'"

Everyone seems to be able to run this script command but me.
WScript.exe has version 5.6. and I am using XP Professional SP2 incl. patches.

wscript.echo ("Test") works fine, so my understanding of this error is, that wscript.run is not a recognized script command on my system...

Any help is very welcome!

Thanks!

Obsolet
 
Your problem is that you misread the line "everyone" seems using. It is not wscript.run, it is some other object of type IWshShell3's run method.
[tt]
set wshshell=createobject("wscript.shell")
wshshell.run "C:\windows\notepad.exe"
[/tt]
 
Try This:

Code:
Set WshShell = CreateObject("Wscript.Shell")
wshShell.run("c:\windows\notepad.exe")[\code]
 
I meant this:

Code:
Set WshShell = CreateObject("Wscript.Shell")
wshShell.run("c:\windows\notepad.exe")
 
Thanks to all!

This works fine now, even I remeber that I tried it that way also before. Well, maybe I misstyped a line or so.

So it seems to me that Wscript.Run is not a script command?
Just wondering because I found it very often in example scripts.

So far I go ahead with your solution and try my best with the further code

Very happy!

Obsolet
 
I found it very often in example scripts
Really ?
 
Well, yes...I'd better do a research for an example ;-)

Here BTW is the script I built. I needed a simple tool to create files with a specified size for migration testing.

Set WshShell = CreateObject("Wscript.Shell")
x = InputBox("How many Files do you want to be created?")
y = InputBox("Please enter the size of each file in kbytes:")

for num = 1 to x step +1
WshShell.run("fsutil.exe file createnew test" & num & ".txt " & y*1024)
next

I know that it is very simple and may not meet coding "rules" (no error handling etc.) but for the moment I am happy with it.

I saw that there is also another way to creat files directly with script (fso?) but so far I could not find a way to define the size of a file.

I will try myself first and come back with questions I'd presume ;-)

Regards,
Obsolet
 
The two lines of code don't have to be together:

Code:
[b]Set WshShell = CreateObject("Wscript.Shell")[/b]
x = InputBox("How many Files do you want to be created?")
y = InputBox("Please enter the size of each file in kbytes:")

for num = 1 to x step +1
[b]WshShell.run("fsutil.exe file createnew test" & num & ".txt " & y*1024)[/b]
next
 
Hm, okay.
But why not? I thought it has to be defined like that in every script (at least with WshShell.run).
Without the first line the script won't work here.
So what's wrong with that?

Thanks!

Obsolet
 
Something else which causes problems with my little scirpt.
Generating a hug amount of files takes really long (talking about 250.000 and more!)

Compared with this method:

for i=1 to x step +1
Path = i & ".txt"

set fso = CreateObject("Scripting.FileSystemObject")
set fsoFile = fso.CreateTextFile(Path, true)

fsoFile.WriteLine("My Text here")

fsoFile.close
set fsoFile = nothing
set fso = nothing

This way works very fast but I could not find a way (documentation) how to define a file size like fsutil is able to...
Is there a way to use "CreateTextFile" with further "options" to define the desired file size of the opject?

 
I misread your post thinking you were posting an example...nothing wrong with your production script.
 
Write a buffer of the desired size:
fsoFile.Write String(y*1024, "?")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV,

thank you! This helps a little, indeed.
But it is of course limited in use for big values...
I made this script:

Code:
Dim fso, fsoFile, Path

x = InputBox("How many files do you want to create?")
y = InputBox("Please enter now the size for each file in Kbytes:")

for i=1 to x step +1
	Path = i & ".txt"

	'Objekte erstellen
	set fso = CreateObject("Scripting.FileSystemObject")
	set fsoFile = fso.CreateTextFile(Path, true)


	fsoFile.Write String(y*1024, "?")
	'TextDatei schliessen und Objekte terminieren
	fsoFile.close
	set fsoFile = nothing
	set fso = nothing
next

By entering more than 5 digits (e.g. 1234567) it generates an overflow. So I assume that the file type or the Write command is not capable of writing such long strings.

But it helps anyway. Now I can use 2 scripts, one for generating thousands of small files in a very fast way, the other one using FSUTIL to generate a few files of a very big size.

Thanks!

Obsolet
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top