• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 168
  • Last Modified:

Executing a .vbs file rom within another .vbs file - Run Vs. Exec

Okaaay. I'm a crappy admin and can't be bothered to keep changing the various settings on each workstartion when a user screws them up.

I've wrote a little 2 part .vbs file to do this, and it's got a small routine to stop the bastards deleting it.

The original file (parent.vbs) moves itself into c:\windows\system and executes. It WriteLines a new .vbs file which runs on startup. That file contains something like the code below:

Function RestoreFile()
  Dim wsh,vbsExec
  Set wsh = wscript.createobject("wscript.shell")
  Set fso = CreateObject("Scripting.FileSystemObject")
    fso.MoveFile "blah.bak","blah.vbs"
      Set vbsExec = wsh.run("blah.vbs") '<-- PROBLEM!
    fso.MoveFile "blah.vbs","blah.bak"
  Set vbsExec = Nothing
  Set fso = Nothing
  Set wsh = Nothing
End Function

My problem (marked above) as far as i can tell is with the wsh.Exec vs Wsh.Run - .Run works but throws up an ugly error whilst .Exec just seems to hang. wtf?

Is the script triping over itself because it doesen't execute quick enough? have i just messed up big time?
This is definately worth more than 40 points, but i don't have any more. A good answer will get some sweets sent to the poster or 'something'. perhaps.
1 Solution
You could read the code into a variable using FileSystemObject. Then use ExecuteGlobal on that variable.
Moderator, my recommended disposition is:

    Accept sybe's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now