Building a Visual Basic script that uses a batch file - visual-studio

I've written a batch file script that takes an image sequence from a certain folder, converts it to quicktime using ffmpeg and then it moves the file to a certain folder.
I used variables at the beginning of the batch script for user input on which folder to take the files from.
And now for my question: The batch I've written works just fine but I want to make it into a simple visual basic script so it looks nice and clean instead of a command prompt interface.
Can anyone provide me with tips for the VB code?
How do I pass variables from VB to the batch file?
Any help on this would be much appriciated.

Use a HTML Application to program the GUI to gather the info needed from the user. Use WScript.Shell's .Run or .Exec method to start an external process (either the .bat or ffmpeg directly) and pass those info via the command line.

Related

Windows Task Scheduler - Copy file from URL to Desktop

I'm wanting to create an automated job in Windows (presumably using Task Scheduler) to copy a CSV file from a URL to my desktop. From what I can gather, a batch file cannot copy a file from an external location. Not familiar with Powershell, but it looks like it might have that capability.
What is the best way to create a script and automate the process to copy a file (http://example.com/file.csv) to my Desktop for instance? Would like to use features native to Windows without having to download a third-party application if possible.
Thanks for any and all help!
You can download a file using powershell using syntax like this:
$client = new-object System.Net.WebClient
$client.DownloadFile("http://example.com/file.csv","C:\tmp\file.txt")
Save this as a script (something.ps1). Then create a task in the Task Scheduler and add a new "Action" of the type Open Program. Use program PowerShell, and specify the path to the script (like C:\something.ps1) as the argument.
More info:
How to download files using powershell
Scheduling Powershell script execution
Windows Scripting Host does allow you to get files via HTTP.
See AnthonyWJones' answer at HTTP GET in VBS
Change code as appropriate, save as .vbs file, schedule same.
I know very little about powershell so I don't know if it can do it. I know you prefer not to use a third-party application, but you can easily do what you want with curl which comes as a single stand-alone exe: http://curl.haxx.se/dlwiz/

How to zip a file in windows shell without vb script and with Window default zip only

Is their a way to zip a file without VB Script.I got a lot of examples on web to zip file or folder using vbs but i want to do it in a single BAT file.
Yes and no. There is no built in way to do this inside windows. You can use a external application like vbscript, a exe file like 7zip, rar, lots of resources can do this. Since windows is application poor when it comes to command lines is not really surprising. But no you do not need the VB Script for anything.
Just not so easy out of the box. Maybe makecab could do it for you? As a general rule you have a hard constraint in your question. A single BAT file which in general can not do almost anything without the support of hundreds of preinstalled or commonly installed other applications.
Could you specify a the constraints a bit better. Tel WHY you need this particular constraint? And what does it mean as even most of the bat command you use require more than one file.

Batch file that runs upon accessing folder

I'm wondering if it's possible to have a batch file that automatically executes when I open a directory. I have no clue as to how this would be done.
I want it to do this whether it is accessed through cmd/.exe/.bat/mouse
No. This isn't possible using a batch file. (In fact, I don't think it's possible at all without writing a shell extension, which would require an actual programming language.)

Can XSLT execute a shell script at the OS level?

I have a production flow that combines XSLT and some shell scripts in about 4 steps before it reaches completion. I execute each step manually at the moment.
I'm using Saxon 9 from the command line in Linux. Can I have the xsl's execute shell scripts.. instead of me?
(I know I could achieve the desired result in another way with Ant or Make.. but prefer to stay in XSLT if it is not a huge effort to do so)
Update: I've minimized my shell scripts and sped things up using Xproc. I'm not entirely satisfied with the result, but Xproc has improved life. Kai's suggestion below looks good.. but I have not tried it yet.
I'm not Java savvy either, but I found with Michael Kay's tutorials on the Saxonica website it's doable.
Here's what I did and what's working well for me:
In the root element of the XSLT stylesheet I assigned a namespace for the function (in my case I'm using it for unzipping, so I named the prefix unzip, but that could certainly be anything):
xmlns:unzip="java:java.lang.Runtime"
I am defining a variable with a file path for a batch file to be called later. Then I am using
<xsl:result-document href="{$batchFile}" method="text"> ... </result document>
to create the batch file. (Unzipping could be certainly done with just a command, but I found the batch file version more handy as I needed to combine the unzip-command with some change directory command and other little stuff. And furthermore using a batch file opens up a world of more elaborate tasks that could be called from the XSLT sheet.)
When I need my batch file be executed, I insert an xsl:message like this:
<xsl:message>Executing <xsl:value-of select="unzip:exec(unzip:getRuntime(),concat('cmd /c /y start ',$batchFile))"/></xsl:message>
Hope that helps,
best regards,
Kai
You can call java.lang.Runtime.exec() in the same way as any other external Java function.

WiX running batch file, before file copy

I am Using WiX 3.5 for making installer, i need to copy many files and folder.
I used heat.exe to do that, and it is working fine.
But i need to call bat file during installation, and the bat file is present in those folders i mentioned above. That bat file is depended on some other files.
I am able to call the batch file but by that time the other files are not loaded.
Below is the custom action i am using for running bat file.
<Custom Action="InstallFeature" After="InstallFinalize"><![CDATA[
(&TypicalFeature=3) AND NOT(!TypicalFeature=3)
]]></Custom>
Need help, may be files are loading after i call the bat file.
Thanks
Ravi S
Calling a batch file from an MSI is a really really bad idea. MSI is declarative - you simply define what the system should look like on a successful installation, if something goes wrong, MSI can roll back the changes.
However by using a batch file, Windows Installer doesn't know what changes were made to the system and can't roll anything back.
I would look into what the batch file is doing, and implement what it is doing either in WiX, or via a custom action in C++/C# with corresponding rollback action. (Native code is best, but it's hard. Managed code is the next best thing and VBScript is a last resort - but still better than a batch file)

Resources