[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How can I run an exe file from a vbs script or from powershell?

Posted on 2015-01-05
18
Medium Priority
?
213 Views
Last Modified: 2015-02-02
User is currently running a batch script, which contains something similar to this.

cd..
cd..
cd programs
cd folder1
cd folder 2
CONTROL.EXE SHUTDOWN

I would like to create a vbs or powershell script which will run this exe file, as opposed to including it in the script.
Is this possible?
0
Comment
Question by:100questions
[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
  • 7
  • 7
  • 4
18 Comments
 
LVL 22

Expert Comment

by:plusone3055
ID: 40531652
put this line in the batch script
start "c:\windows\folder" CONTROL.EXE
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 40531658
if you want to run it from VBScript

Set sh = CreateObject("WScript.Shell")
sh.Run "C:\Path\CONTROL.EXE

http://www.visualbasicscript.com/running-exe-from-vbscript-and-passing-parameters-m102094.aspx
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40531667
powershell version should simply be:

c:\programs\folder1\folder 2\CONTROL.EXE SHUTDOWN
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

Author Comment

by:100questions
ID: 40531694
Thanks.  Powershell version seems incomplete.  Is there some way of providing a complete sample script?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40531711
If the path does contain spaces, you'll need to enclose it in quotes.
"c:\programs\folder1\folder 2\CONTROL.EXE" SHUTDOWN
should work...
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 40531724
the vbs script above works fine :)
0
 

Author Comment

by:100questions
ID: 40531764
Thanks plusone3055 I will try it.   Does it incorporate the SHUTDOWN command?
0
 

Author Comment

by:100questions
ID: 40531767
Thanks sirbounty, can you show me a sample script which will run this?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40531782
Drop that into any file name with a .ps1 extension and you have your script. ;^)
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 40531813
here you go complete script VBS

Set sh = CreateObject("WScript.Shell")
sh.Run "C:\Path\CONTROL.EXE
Set sh2 = CreateObject("WScript.Shell")
        sh2.Run "C:\WINDOWS\system32\shutdown.exe -r -t 0"
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40531900
What is the goal of the current script?
I don't see the point of the directory changes, but the commands, native windows' commands, seem to read that you are attempting to launch the shutdown options in control panel.
If that's the case, and since these are native commands, you don't need to change the path, as they are part of the default path and can be launched from anywhere (though powershell does require a relative path).
So, simply executing a powershell script
.\control.exe shutdown
should accomplish the same thing, but then again, so should that very nearly same script in a batch file:
either start control.exe shutdown or simply control.exe shutdown
Not knowing what version you're working with, I can't give more than that, but the only shutdown related items I see in my version are power related.  You can use the control panel layer file to accomplish that by using
powercfg.cpl (from powershell - again may need to proceed with start in a batch file)
0
 

Author Comment

by:100questions
ID: 40532071
This VBS Script causes problems when the program is running.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40532134
What is the goal?  Native Control.exe only launches control panel.  Is this another app, outside of windows, that is NOT the control panel?  What do you want for end results?
0
 

Author Comment

by:100questions
ID: 40536463
'Control.exe' is a mock name for a program which is being run.  The program has various routines in it, which are scheduled, exe and batch files which run in succession.
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 2000 total points
ID: 40536483
So, shutdown is a parameter passed to control.exe?
The same commands should still work within a powershell script - there's nothing that should flag an error, although I think you could condense your directory changes to one statement, i.e.:

cd "c:\programs\folder1\folder 2"
CONTROL.EXE SHUTDOWN

Open in new window


Have you tried this approach and does it yield the results you're after?
0
 

Author Comment

by:100questions
ID: 40544117
Thanks.  Is this a powershell script or a batch script?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40544163
well, technically it could be either - depends on the extension (ps1 = powershell, bat/cmd = batch)
0
 

Author Closing Comment

by:100questions
ID: 40584657
Unsure if this works, since I no longer require it.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

656 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