How to run bat file with shell function in VB.NET without showing command - vb.net

I need to run exe file on command prompt to pass some parameters and in the code of exe file i have run a bat file using VB.NET built-in shell method, but when run exe file on command prompt the shell method seems printed the entire code of the bat file out into cmd, this is not allowed.
Example:
Shell("any code and path to file", AppWinStyle.Hide)
Note: I have to run this bat file with shell method of VB.NET

Related

How to execute a .exe file using PsExec in Finalbuilder

I need to be able to run a .exe file on a remote VM using Finalbuilder. I'm currently using PsExec, which I can get to run .msi files, but not .exe files. On a .exe file, here's what I'm trying:
Under Program file I have
msiexec
These are my parameters
/i C:\[filepath].exe INSTALLDIR=C:\[path] INSTALLMETHOD=silent
INSTALLALIAS=LIVE INSTALLREBOOTMETHOD=0 /qn /l*v C:\[log path].txt
Can PsExec not run .exe files, or is there an alternative to PsExec that works better?

How to launch a .bat file in VB without associating the file with the program that launched it?

Ok, the the question looks freakish, but this is sort of a continuation of the question I posted
here.
So, I create a .bat file in Visual Studio with certain lines and launch it, but it basically doesn't find the files it needs, but if I launch the .bat file it created manually, it works.
The problem, as far as I see it, is that the .bat file the program launches isn't the same as the one that is created in the folder?
The .bat files use the command line interface of Asesprite found here, e.g. :
#set ASEPRITE="C:\Program Files\Aseprite\aseprite.exe"
%ASEPRITE% --batch animation.ase --scale 2 --save-as animation-x2.gif
I'm not sure which part of the VB code I'd need to share, so ask if needed.
The error in .bat goes something like:
C:\Users\User\Desktop\aseConverter\aseConverter\bin\Debug>"E\Asesprite\asesprite.exe" --batch skeleton2_gib3.ase --scale 1 --save-as skeleton2_gib3.gif
File not found: "skeleton2_gib3.ase"
Error loading file "skeleton2_gib3.ase"
A document is needed before --save-as arguement
The first line should not be the Debug folder, but the location the .bat file was created in. I've no idea how to fix it.
It SHOULD be
C:\Users\User\Desktop\skeleton>"E\Asesprite\asesprite.exe" --batch skeleton2_gib3.ase --scale 1 --save-as skeleton2_gib3.gif
The problem here is that the batch file references files without path. Therefore the files must be in current working directory of the batch file.
But the batch file respectively command line interpreter cmd.exe is called by the VB.net without setting the working directory. Therefore the current working directory set by Windows for the batch file is the same as of the starting VB.net application.
But the starting application creates the batch file and the other files in a different directory, not in its own current working directory.
One solution is changing current working directory inside batch file to the directory the batch file is stored. This can be done by referencing argument 0 of the batch file which contains name of batch file with complete path.
What does %~dp0 mean, and how does it work? explains how to get drive and path of batch file.
Therefore one solution is to use a batch file like below:
#echo off
cd /D "%~dp0"
set "ASEPRITE=%ProgramFiles%\Aseprite\aseprite.exe"
"%ASEPRITE%" --batch animation.ase --scale 2 --save-as animation-x2.gif
See help output after executing cd /? in a command prompt window for meaning of parameter /D (change also drive if necessary).
An explanation for %~dp0 can be read on running call /? or for /? in a command prompt window.
Another possibility would be the usage of following batch code:
#echo off
pushd "%~dp0"
set "ASEPRITE=%ProgramFiles%\Aseprite\aseprite.exe"
"%ASEPRITE%" --batch animation.ase --scale 2 --save-as animation-x2.gif
popd
The difference to command cd is explained in help which is output in a command prompt window after executing pushd /?.
Best would be to create the batch file with all files referencing with complete path, name and file extension.

how to use command line to execute exe file in vb vs2010

i have a exe file , which must be opened with a command line
start a.exe /stext d:/alpha.txt
to save a file in d drive. I tried creating a batch file and calling it in vb but the batch dosent executes the exe file, so is there any direct method to add command line in vb to run the exe file to generate the alpha text.
Use this:
System.Diagnostics.Process.Start(Process Name)

How to create a .exe file for running command prompt commands

I wish to put the following steps in a .exe file so that manual intervention is avoided and everything is automated. All the user needs to do is double click this .exe file.
Following are the steps which I wish to automate.
Open command prompt.
Go to desired folder location Eg. cd Desktop\Automation\
Run the command ruby xyz.rb
Thanks!
Abhishek

Input Error when running WSH script

I'm trying to run WSH script using cscript specifically
in cmd I got this Error
Input Error: There is no script file specified.
using this command
cscript c:\file.wsh
On windows 7 ultimate
My WSH script simply writes a registry entry
I don't want to use vbscript (.vbs) or wscript engine
so how can I make my WSH script work ?
.WSH
The Windows Script Host control file (.wsh) is a text document in which you can customize the execution of one or more of your scripts. It is created automatically when you set the properties for a supported script file.
The following example illustrates a typical .wsh file:
[ScriptFile]
Path=C:\WINNT\Samples\WSH\showprop.vbs
[Options]
Timeout=0
DisplayLogo=1
BatchMode=0
The path information in the [ScriptFile] section identifies the script file that is associated with the .wsh file. The keys in the [Options] section correspond to settings in the Script tab within the Properties dialog box.
Note:
You must have the original script file present when executing the .wsh file. If the .wsh file fails to run the script, check the Path= information in the .wsh file to ensure that it points to the script you are attempting to run.
When you double-click a .wsh file or run it from the command line, CScript.exe or WScript.exe reads the .wsh file to determine the specific settings that should be used to execute the script. CScript/WScript executes the original script, passing in the properties that are defined within the .wsh file.
It's not possible to specify script parameters with the .wsh file. You must run the script (either the script file or the .wsh file) from a command prompt to add the parameters.
Resource: Setting and Customizing Script Properties (.wsh)