Not able to create a text file using FSO

Hi,

I have written a program as part of our intranet aplication that helps users to print reports from our web site. Basically, the page shows a list of files under a folder and a small printer icon infront of it. If the user wants to print that file, he clicks on the printer icon which brings up a small window with a dropdown list of the printers available to him. He selects a printer and clicks on "print" button. The form submits to another page of code with the "printer name" and "file name" and all the work is done in the second page.

I am getting error in this page. Basically, I am creating an object of Shell and sending the print job to command prompt programmatically. Before the requested file is sent to comand prompt, it is recreated in another folder, "temporary". Error is being pointed to this line of code where the temporary file is created.

set tempfile = fso.createtextfile(tempfolder & "\" & tempfilename & cstr(tempfilenum))

The actual code is in some other folder, let's say "A" and the temporary file is being created in completely different folder, let's say "B" which is out of "A".

Any help or suggestions to fix this please? This has to be fixed very urgently.

Thanks,
arsmed840Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
And the error message is?
also, what is the value of
tempfolder & "\" & tempfilename & cstr(tempfilenum)
arsmed840Author Commented:
The error message is

Microsoft VBScript runtime error '800a0046'

Permission denied

The value of tempfolder & "\" & tempfilename & cstr(tempfilenum) is as following.

tempfolder - is "temporary" as I told you earlier which is already existing, that means the program need not create.
tempfilename - is fixed, "print-temp."
tempfilenum - is a number that gets incremented in a loop every time a new file is requested to print. it starts with a value of "0".

I want to be more clear on the last thing, tempfilenum. Each time a file is requested to print, a temporary file is created. The name of the file is varied only with the number in the last. Rest of the filename is same for every file. Once the file is created it stays there till we delete them manually.
So, I browse through the files created taking the filenum as "0" initially, and incrementing it by one, and do loop is as follows.
    tempfilenum = "0"    
    do while fso.fileexists(tempfolder & "\" & tempfilename & cstr(tempfilenum))
        tempfilenum = tempfilenum+1
    loop
    set tempfile = fso.createtextfile(tempfolder & "\" & tempfilename & cstr(tempfilenum))

Please let me know if you need more information.

Thanks,
WelkinMazeCommented:
Hi,
Are you sure that the error comes from this line? Could you check if the program really stops there or go through it and the error comes from some of the next rows? It happens sometimes for different reasons the line shown for an error to be incorrect.

Also you can look here for some info:
http://computerperformance.co.uk/Logon/code/code_800A0046.htm
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

arsmed840Author Commented:
Hi WelkinMaze,

I checked the code and the error was right at the line I told as above. I added "everyone" also in the user names of temporary folder. Luckily it started working. I mean, it is able to create the file in that file with proper increments.
And now the problem is showing up at a different place.

After creating the file I am sending that to print using WScript.shell's run method. Now the error is showing up at this line.
txtreturn=WShell.Run(runstring, 1, true)

I tried to print the runstring to the screen. It is grabbing the right value. I called parameter runstring's value directly at the command prompt of the server. It printed the file perfectly. But, when I call the program through IIS(as the code is in an .asp file), it is throwing up the same error I said above.

Microsoft VBScript runtime error '800a0046'

Permission denied

Thanks so much,

WelkinMazeCommented:
are the permissions for the printer ok?
or is runstring has the full paths in it?
arsmed840Author Commented:
Hi WelkinMaze,

I am not sure of the permissions for the printer. Please tell me what and how to check. I will do it.

And runstring is really fine. Because, I tried to write it to page. It printed the string value correctly. And I typed the same string value it returned at the command prompt to print the file. It printed perfectly.

The only thing I am wondering is why it is stopping at the same line when I call it in the code. Is IIS not able to use "run" method of shell object or not able access? Or are there any permissions need to be checked on the shell object's dll also?

Thanks,

WelkinMazeCommented:
you also need permissions on wscript.dll and any dll's your executable requires to run.

and this one is taken from the link below:
"I use IIS6 , the only thing I had to do was to assign another working process to my application.
That working process ha to start as a Local System not as Network Service."

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21046917.html?qid=21046917
WelkinMazeCommented:
And these are the solutions from the initial link I've posted (http://computerperformance.co.uk/Logon/code/code_800A0046.htm):
The Solutions
If its Exchange, then check the MailRoot and Pickup folder permissions.  If its IIS check the permissions to run scripts.  If its SQL check the execute permissions on the services.  

The solution in the printer problem below would be to change the share permissions on the HP6L printer share.
tone28Commented:

Are you using ASP? You will need to use Server.MapPath

set tempfile = fso.createtextfile(Server.MapPath(tempfolder & "\" & tempfilename & cstr(tempfilenum)))
arsmed840Author Commented:
In this scenario, what permissions should I add or check on dlls. I mean other than wscript.dll, do I need to change permissions on any other dll. And also, what kind of permissions should I check, please tell me.

Here, I am just trying to print the file by instantiating the shell object and by passing the run command through an asp file. So, it should be IIS. Not Exchange or SQL. But, I already granted permission for that application to run scripts. So, that is fine.

>The solution in the printer problem below would be to change the share permissions on the HP6L printer share.
Where should I check for this? I am sorry. I am not a network person, so, I don't have too vast idea on all these permissions and dependencies.

Thank you so much,
adam_pedleyCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.