VBScript Permission Denied

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



VBScript Permission Denied



I'm trying to do some automation on SecureCRT using VBScript. My issue right now is that around ~30% of the time I try to run my script (sometimes in meetings for presenting...) I get a "permission denied" error.



A lot of the time, the quick solution is that I copy & paste my script into a new .txt file. Eventually the old one works again, but it's incredibly finicky. Today, my script worked. 5 minutes later I got the permission denied. I created a revision, which worked. 5 minutes later that one errored out and the original version stopped giving me the error. It's hard to keep track of, and I'm not sure what's causing it.



Edit:
Error occurs on this line.


Set pso = CreateObject("Scripting.FileSystemObject")

Set Pile = pso.OpentextFile("Alarm_logs.txt",8, True)



It's very near the top of the script.

Anyone had a similar experience?





For help with your code: show your code. Show the error too.
– Ansgar Wiechers
Aug 10 at 14:37





Error occurs on this line. Set pso = CreateObject("Scripting.FileSystemObject") Set Pile = pso.OpentextFile("Alarm_logs.txt",8, True) It's very near the top of the script.
– KuboMD
Aug 10 at 14:47



Set pso = CreateObject("Scripting.FileSystemObject")


Set Pile = pso.OpentextFile("Alarm_logs.txt",8, True)





@KuboMD include code in the original question. You can do this using the edit option. Code in comments is not clear and comments won't necessarily stay around forever.
– Lankymart
Aug 14 at 17:19




1 Answer
1



The issue is that you don't specify a full path, so the actual path of the file you are trying to write depends on how you run the script.



if you double click on the vbs it will be launched from %windir% where your user doesn't have permissions to write.



If you open a cmd, cd to a folder where you can write and run


wscript pathtoyourvbsyourfile.vbs



then your file will be created in the current folder with no permission denied error.



If you want to be sure where your file is created, you have to provide an absolute path, not a relative one.



You can use environment vars for that or maybe start by getting the folder where the vbs is located in and use it to build your path and get your created file next to the .vbs :


scriptdir = replace(WScript.ScriptFullName,WScript.ScriptName,"")
Set pso = CreateObject("Scripting.FileSystemObject")
Set Pile = pso.OpentextFile(scriptdir+"Alarm_logs.txt",8, True)





I'll give this a try, thanks!
– KuboMD
Aug 10 at 15:45






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS