• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

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

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
100questions
Asked:
100questions
  • 7
  • 7
  • 4
1 Solution
 
plusone3055Commented:
put this line in the batch script
start "c:\windows\folder" CONTROL.EXE
0
 
plusone3055Commented:
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
 
sirbountyCommented:
powershell version should simply be:

c:\programs\folder1\folder 2\CONTROL.EXE SHUTDOWN
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

 
100questionsAuthor Commented:
Thanks.  Powershell version seems incomplete.  Is there some way of providing a complete sample script?
0
 
sirbountyCommented:
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
 
plusone3055Commented:
the vbs script above works fine :)
0
 
100questionsAuthor Commented:
Thanks plusone3055 I will try it.   Does it incorporate the SHUTDOWN command?
0
 
100questionsAuthor Commented:
Thanks sirbounty, can you show me a sample script which will run this?
0
 
sirbountyCommented:
Drop that into any file name with a .ps1 extension and you have your script. ;^)
0
 
plusone3055Commented:
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
 
sirbountyCommented:
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
 
100questionsAuthor Commented:
This VBS Script causes problems when the program is running.
0
 
sirbountyCommented:
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
 
100questionsAuthor Commented:
'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
 
sirbountyCommented:
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
 
100questionsAuthor Commented:
Thanks.  Is this a powershell script or a batch script?
0
 
sirbountyCommented:
well, technically it could be either - depends on the extension (ps1 = powershell, bat/cmd = batch)
0
 
100questionsAuthor Commented:
Unsure if this works, since I no longer require it.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 7
  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now