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?
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 pathtoyourvbs\yourfile.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)