?
Solved

Use a vbscript to change default to cscript and back to wscript

Posted on 2005-05-02
9
Medium Priority
?
1,298 Views
Last Modified: 2012-08-13
Hello all,

I'm not a programmer but hoping to get a solution here. I have a vbscript that runs properly in cscript. So I want to apply a vbscript that sets default to cscript, then run my vbscript. After that I want to run another script that will change default back to wscript.

Is this possible. If so please, assist.

Thanks
0
Comment
Question by:danhilaire
  • 4
  • 2
  • 2
8 Comments
 
LVL 22

Expert Comment

by:JesterToo
ID: 13915406
Just embed this subroutine in your code and call it at the apporpriate times...

Sub Force(sScriptEng) ' Forces this script to be run under the desired scripting host.
                      ' Valid sScriptEng arguments are "wscript" or "cscript".
                      ' If you don't supply a valid name, Force will "toggle" hosts.

   If Lcase(Right(Wscript.FullName, 12)) = "\wscript.exe" Then
      'WScript.Echo "Running under WSCRIPT"
      If Instr(1, Wscript.FullName, sScriptEng, 1) = 0 Then
         'Need to switch to CSCRIPT
         CreateObject("Wscript.Shell").Run "cscript.exe " & Chr(34) & Wscript.ScriptFullName & Chr(34)
         Wscript.Quit
      End If
   Else
      'WScript.Echo "Running under CSCRIPT"
      If Instr(1, Wscript.FullName, sScriptEng, 1) = 0 Then
         'Need to switch to WSCRIPT
         CreateObject("Wscript.Shell").Run "wscript.exe " & Wscript.ScriptFullName
      Wscript.Quit
      End If
   End If
End Sub
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13915748
JesterToo and his in genius suggestions ! *YAY for JesterToo!!!*

I just wanted to say that his suggestion will most likely work and hopefully it helps, if not please post back ( which I doubt you will have to do ! )
0
 
LVL 22

Expert Comment

by:JesterToo
ID: 13918718
Thanks for the accolade, gecko, but I'm afraid I can't take credit for it... found it, or a variation of it, a couple years ago on the web.

Dan, I'm curious about what works correctly under Cscript but doesn't under Wscript.  Also, and you may already know this, you don't need to use this subroutine to cause your script to run in one mode or the other... just invoke your script with the desired interpreter... like this:

   cscript /nologo yourscript.vbs

or

   wscript yourscript.vbs

-- Lynn
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:danhilaire
ID: 13918874
Thanks Lynn,

I'm going crazy trying to get this script to run properly.

I am trying to get Micrsoft's xcacls.vbs script to run in cscript and pass the correct parameters to it. The only thing is I'm trying to get this to run in Group Policy. The default for Windows as I understand is wscript, and xcacls should be run in cscript. So, I got it working if I manually run it at a command prompt, but there's no way for me to tell Group Policy to run in cscript.

So do I just insert:

cscript /nologo yourscript.vbs (replacing "yourscript.vbs" to the path of the actual script I want to run)

in a text file and name it with a *.vbs extension and run it?
0
 
LVL 22

Expert Comment

by:JesterToo
ID: 13919866
Aaah, now I see why you need cscript...

No, the code I provided is intended to be added into whatever vbs script you're running and, additinally, you would need to invoke the FORCE subroutine from within that script (2 modifications to the origina vbs script).  You probably don't want to do this because the next time you download a new version of xcacls you'd have to remember to make those modifications again.

A better way (there are two of them) is to just specify  cscript /nologo xcacls.vbs /x /y /z  (where /x /y /z are whatever switches you need) for the GPO to run.

Another way is to wrap that command in a batch file and specify the batch file name for GPO to use.

Third way is to change the default interpreter from wscript to cscript, run what you already have, then switch the default interpreter back to wscript (this is basically what you originally asked for).  I'd wrap this process inside a batch file and specify the batch file name for GPO to execute.

More info is available here (specifically for xcacls.vbs):  http://support.microsoft.com/?id=825751

Let me know if you have any specific questions... I don't use xcacls but I think I can configure it's usage so you're not plagued with all the popups caused by Wscript.Echo statements being interpreted by Wscript.

-- Lynn
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13919992
One day when I'm Rich, any chance you can tutor me JesterToo :D * GRINS * lol
0
 

Author Comment

by:danhilaire
ID: 13935655
Lynn,

First off, I want to thank you for your assistance here.

I would like to ask you, is there anyway to get the script to run under the context of the system account? That would greatly reduce the impact on users. I would then be able to run this directly from the server instead of via a Group Policy. I would finally be able to complete this project.

If not, I'm going to have to stick with the Group Policy plan. I have been able to run the cscript xcacls command, but I an not succussful just running a script yet (without specifying the cscript in front of it). The issue is that Group Policy can't run batch files. GP only runs vbs scripts. I need a script that will run in cscript independantly without me having to type cscript in front of it. (This is only if I can't get it to run under the system account). Thanks again.
0
 
LVL 22

Accepted Solution

by:
JesterToo earned 1500 total points
ID: 13942767
I tried to merge the two scripts (as I cautioned against earlier).  However, that still didn't work.  This is the first script (xcacls) that seems resistant to that technique... I'll figure it out later.  In the meantime you can enter the following command to switch the default scripting engine (for the user who is logged in at the time it's executed... this might still not be the solution you need... if not, let me know and I'll see if I can come up with another method.

Here's the command...         cscript //h:cscript //noLogo //s

You can see all the CSCRIPT command options by issuing...    cscript /?

HTH,
Lynn
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Make the most of your online learning experience.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Six Sigma Control Plans

840 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