I need a way of downloading a program through either visual basic or cmd. I have tried these, but the file after it's downloaded is only about 600 bytes and doesn't work. I own this website and have ftp access, if I download it through ftp it's fine. I'm using Visual Studio 2013 by the way. These are the methods I've tried:
CMD through VB:
Dim MyCmd, Ws, Ret
Ws = CreateObject("wscript.Shell")
MyCmd = "cmd /c Powershell.exe -ExecutionPolicy bypass -noprofile -WindowStyle Hidden (New-Object System.Net.WebClient).DownloadFile('http://minecraftmapmakerstool.16mb.com/downloads/The_Map_Makers_Tool.exe','C:\Users\user\Desktop\The_Map_Makers_Tool.exe'); Start-Process C:\Users\user\Desktop\The_Map_Makers_Tool.exe;"
Ret = Ws.run(MyCmd, 0, True)
VB:
My.Computer.Network.DownloadFile("http://minecraftmapmakerstool.16mb.com/downloads/The_Map_Makers_Tool.exe", "C:\Users\user\Desktop\The_Map_Makers_Tool.exe")
Thanks in advance :)
I think there is no built in tool in Windows that would do that for you. But there are plenty free programs on the web, that you can install and then call from your batch script. Here is one of them: CURL
Here is a basic example of how to use it (using your link)
#echo Off
Title
Pause
CD C:\Users\Jah\desktop
curl http://www.jah.com/ofac/downloads/t11sdn.pdf > download.pdf
This would download and save the file from the URL you have provided to download.pdf
Another possible alternative would be WGET.
Related
I want to install license for my PC. However, I can't add parameter for the method.
My code:
#echo off
for /r "%SystemRoot%\system32\spp\tokens" %%f in (*.xrm-ms) DO (
wmic path SoftwareLicensingService WHERE (Version is not null) call InstallLicense License='<%%f'
)
pause
Like I want to read all text in the files of "tokens" directory and send it to License parameter.
Here is VB code. I can do it in VB but not in .bat file (Batch)
Dim files As String() = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spp\tokens", "*.xrm-ms", SearchOption.AllDirectories)
wmic = New ManagementObjectSearcher("SELECT Version FROM SoftwareLicensingService").Get()
For Each i As String In files
For Each wmi As ManagementObject In wmic
wmi.InvokeMethod("InstallLicense", {File.ReadAllText(i)})
Next
Next
Thanks all. Sorry for my bad English because I'm Chinese :(
I have a .bat file that I am using to run a .Msi in silent mode. Now I wanna run that batch script command from vb.net. I tried using process.start(). Using process.start() opens the files, But the issue is the batch script is not executed and .Msi is not installed.I tried executing the same command directly from cmd and it worked.
Now, Can someone help me how I can execute that command form vb.net.(Can someone help me Write that command to the cmd window after starting the cmd process from vb.net). I tried using standardinput.Writeline(), It is opening the .txt files, But it is not working for executing the commands for installing the .Msi file.
Dim command As String="# echo off msiexec /i
""C:\Users\tparvathaneni\Documents\Visual Studio 2015\Projects\SetupProject1\SetupProject1\bin\Debug\SetupProject1.msi"" /qn REBOOT=ReallySuppress echo pause >NUL shutdown.exe /r/t 000"
Dim proc As New ProcessStartInfo
proc.FileName = "cmd.exe"
proc.RedirectStandardInput = True
proc.RedirectStandardOutput = True
proc.CreateNoWindow = True
proc.UseShellExecute = False
Dim pr As New Process
pr.StartInfo = proc
pr.Start()
pr.BeginOutputReadLine()
pr.StandardInput.WriteLine(command)
Throwing this into your VBS will launch the batch script without a window or tray icon. This may be an easier way than trying to send commands to your batch window.
Set WshShell = CreateObject("WScript.Shell" )
WshShell.Run chr(34) & "C:\Temp\YourFile.bat" & Chr(34), 0
I have a batch script which I am trying to open a file (powershell script on a network location). If I put the path as a local c:\test.ps1 it works fine but I cant seem to get it to work with the network file structure.
#echo off
(set/p adminuser=Enter Your Admin Account: )
runas /user:%userdomain%\%adminuser% "powershell "\\Server\share$\IT Support\Test\Test Share\test.ps1""
Any ideas?
Thanks.
Try this:
#echo off
(set/p adminuser=Enter Your Admin Account: )
runas /user:%userdomain%\%adminuser% "powershell -noexit & '\\Server\share$\IT Support\Test\Test Share\test.ps1'"
I'm creating an application that downloads some applications (like FireFox, WinRar, RealPlayer) and then install them silently using Shell command. This is the code:
My.Computer.Network.DownloadFile("URL", "path\file.exe")
Shell("path\file.exe /s")
The problem is that the shell command starts before Download Is completed, so I get a "file not found" error. So my questions are:
How can I execute Shell command after the download is completed?
Can I use process.start with S parameter instead of Shell command?
This should do the trick to download the file and wait until its over:
Dim wc As WebClient = New WebClient()
wc.DownloadFile(sURL, sFile)
I am shelling in the a few push d statements based on a list of users from the active directory. 2 for example are
java.exe -version
and
dir /s
The search actually seems to search the actual computer and output the files from their directory. However, the java.exe only outputs the actual output from the computer that it is being ran on.
Is this even possible to run a remote exe from the pushd statement? Any thoughts would be great.
Here is the code as of right now in a simplified version. Let me know if anyone would like more.
Dim sCommand as String = "pushd \\***\C$ && java.exe -version 2>>C:\Testfile.txt"
Dim sCommand2 as String = "pushd \\***\C$ && dir /s blah.blah>>C:\Testfile.txt"
For each SelectedItem in Listbx.SelectedItems
Dim ReplaceCommand as String = sCommand.Replace("***", SelectedItem)
Shell("cmd.exe /c" & ReplaceCommand, True)
Dim ReplaceCommand as String = sCommand2.Replace("***", SelectedItem)
Shell("cmd.exe /c" & ReplaceCommand2, True, -1)
Next
To me, you'll need to find on the remote computer first the location of the JAVA executable. Your commands you're executing on the shell will search your local defined paths, not the remote paths.
Consider this.
first execution is local > running java 1.6.0.23
then I pushd to another computer. I re-execute the same command.
Since i'm not in the remote directory containing the java.exe file, it'll process my path to find it. >same version is returned
I then change to the remote's Java container and re-execute the statement.
This time it's finding the remote Java.exe and processes the command.