PDA

View Full Version : WSH Help - Create File with input variables(W2K)



Dakhmes
03-25-2004, 06:36 AM
Hey Gurus,

Can anyone tell me why this script won't work? I'm just learning and have been tinkering for hours.
Any help would be greatly appreciated. The code follows:

'setting my objects
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")

'setting variables
Dim strpath, strname, strmessage

'getting variables
strname = InputBox ("Enter the name of the text file you want created")
strpath = InputBox ("Enter the location you want this file saved")
strmessage = InputBox ("Enter your text")

'Creat the file with input variables
Set File = fs.CreateTextFile(" & strpath" & strname, True)
strname.WriteLine(" & strmessage)
WScript.Echo "This location is about to be opened" & (" \\" & WshNetwork.ComputerName & " & strpath)
WshShell.Run (" & strpath)

unknown634
03-25-2004, 09:03 AM
(Yay, made it back here)

Your script had a lot of excess quote marks and wasn't running the correct thing. Also, why are you using UNC paths for the local computer? I left those there for whatever reason you might have, but you should use C:\Folder\File.txt format for a local computer

HEre's my modified code:

<font color=red>
'setting my objects
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")

'setting variables
Dim strpath, strname, strmessage, OpPath

'getting variables
strname = InputBox ("Enter the name of the text file you want created")
strpath = InputBox ("Enter the location you want this file saved")
strmessage = InputBox ("Enter your text")

'Creat the file with input variables
Set File = fs.CreateTextFile(strpath & strname, True)
strname.WriteLine(strmessage)
OpPath = "\\" & WshNetwork.ComputerName & "\" & strpath 'added an OpPath variable to hold file location
WScript.Echo "This location is about to be opened" & OpPath
WshShell.Run (OpPath)
</font color=red>


Well, lemme know if that helps any. I didn't explicitly show all the quote errors, but if you compare the scripts, you should notice them.

-Unknown

-----------------
C:\
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN

Dakhmes
03-26-2004, 02:03 AM
Hey that helps heaps! Thanks for your help.

The only problem I have now is it won't take the strname.WriteLine command. It throws error "object required - (file name you entered).

Do you have any ideas? I just guessed that you would be able to enter strname.WriteLine and get the strname variable. It appears I was wrong.

Grrrr so fustrating hahahahah

unknown634
03-26-2004, 01:47 PM
A minor oversight. it would be file.writeline (The procedure is in the textfile object you have in File)

<font color=red>
'setting my objects
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")

'setting variables
Dim strpath, strname, strmessage, OpPath

'getting variables
strname = InputBox ("Enter the name of the text file you want created")
strpath = InputBox ("Enter the location you want this file saved")
strmessage = InputBox ("Enter your text")

'Creat the file with input variables
Set File = fs.CreateTextFile(strpath & strname, True)
File.WriteLine(strmessage) 'Has to use the File object that has the Writeline procedure in it.
OpPath = "\\" & WshNetwork.ComputerName & "\" & strpath 'added an OpPath variable to hold file location
WScript.Echo "This location is about to be opened" & OpPath
WshShell.Run (OpPath)
</font color=red>

Anyway, lemme know if that fixed it for you.
-Unknown

-----------------
C:\
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN

Dakhmes
03-30-2004, 01:40 AM
Thanks heaps for all your help! Its been great.

I still have a few path not found errors but I think I can sort it from here.

Once again many thanks!