Solved

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

Posted on 2015-01-05
18
190 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
  • 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
 

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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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 500 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now