Solved

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

Posted on 2015-01-05
18
194 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
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.

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

772 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