0

I have a file (launch.vbs) on my memory stick which copies start.vbs (a file from my memory stick) into "C:\Docs\" when run. I then want launch.vbs to execute start.vbs when its in the C drive (i.e. execute "C:\Docs\start.vbs") and it does so, however start.vbs has a line inside it to create a txt ("C:\Docs\output.txt"). The line is

SET creator = fso.CreateTextFile(CurrentDirectory & "\\output.txt",True)"

However when start.vbs is launched from launch.vbs this line gives me error code 800a0046 (Permission Denied). the fso.FileExists function also returns -1 when checking for files at that location if launch.vbs executed start.vbs. I assume this is because when I run launch.vbs I am only giving it low-level permissions and so start.vbs is run with those permissions which prevents it editing the C drive (however this is strange as launch.vbs managed to copy start.vbs to the C drive fine).

As a side note when I run start.vbs from the C drive (i.e. if launch.vbs copies it and then I manually run it) it works fine, it only goes wrong when I try to automatically run it. So to fix it I assume I need to run launch.vbs with more permissions, however is there a way to get it to do that automatically or even prompt for permissions (I know I could probably do right-click>run as admin but I want it to be automated more)

I do not want any admin prompts to pop up, this occurs if I try to elevate it using runas , remember I do not need to elevate the second script to admin status, merely the same status as the first script.

Harrison Harris
  • 85
  • 2
  • 10
  • After doing some more quick investigation it seems that actually launch.vbs needs to pass permissions on to start.vbs as FileExists works fine from launch.vbs – Harrison Harris May 04 '15 at 18:24
  • 1
    possible duplicate of [How to run vbs as administrator from vbs?](http://stackoverflow.com/questions/17466681/how-to-run-vbs-as-administrator-from-vbs) – Ansgar Wiechers May 04 '15 at 18:26
  • Similar to that question, however that is a script elevating itself to admin instead of passing on current permission level, that also looks like it requires settings to be changed, I'd prefer it without settings changed. It also isn't answered yet – Harrison Harris May 04 '15 at 19:05
  • Instead of (re-)running itself with the "runas" verb you can simply run the second script that way. Also, just because the person asking the other question didn't bother accepting an answer doesn't mean the answers given are not valid. – Ansgar Wiechers May 04 '15 at 19:41
  • 1
    Are you sure it is a problem of rights and not of current directory being wrongly set? To me it just sounds as if the workingdir is different when you launch it directly – Syberdoor May 05 '15 at 06:36
  • Fairly certain the directory is correct, ill try to implement runas – Harrison Harris May 05 '15 at 12:30
  • runas brings up the admin password prompt which I don't want, on a side note if I click 'Open' when start.vbs is selected it gives the same error, it only works if I double-click. – Harrison Harris May 05 '15 at 12:43
  • 1
    What is the value of `CurrentDirectory` when you get the error? – aphoria May 05 '15 at 13:15
  • @aphoria ahhh, now that is interesting. When I run it manually it is "C:\Docs", which is correct. However the automated way it is coming out as "G:\" (the drive that my memory stick is in). However I'm not sure why this is happening as the file is only being run when its in the C drive (the line) "return = wshShell.Run("cmd /c C:\\Docs\\start.vbs", 0)" at the end of launch.vbs – Harrison Harris May 05 '15 at 15:16

1 Answers1

0

So the error in the end was the path was incorrect, however it appeared as bad permissions and the error message was bad permissions so I will leave the question title as it is incase anyone has a similar issue. The solution was to change this line:

CurrentDirectory = fso.GetAbsolutePathName(".")

to this line:

CurrentDirectory = WScript.ScriptFullName

I also changed this:

wshShell.Run("cmd /c C:\\Docs\\start.vbs", 0)

to this:

wshShell.Run("cmd /c CD C:\ & wscript C:\\Docs\\start.vbs", 0)

whether or not that second change had an effect idk.

Harrison Harris
  • 85
  • 2
  • 10