Solved

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

Posted on 2015-01-05
18
188 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Synchronize a new Active Directory domain with an existing Office 365 tenant
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

21 Experts available now in Live!

Get 1:1 Help Now