?
Solved

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

Posted on 2003-03-04
3
Medium Priority
?
162 Views
Last Modified: 2010-04-07
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!
      vbsExec.Terminate
    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.
0
Comment
Question by:redshift_1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 28

Accepted Solution

by:
sybe earned 160 total points
ID: 8064357
You could read the code into a variable using FileSystemObject. Then use ExecuteGlobal on that variable.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9024174
Moderator, my recommended disposition is:

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

DanRollins -- EE database cleanup volunteer
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question