Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, January 10, 2014 2:43 AM
I am trying to run Batch Commands for a new program.
The main command I am using is XCOPY and DEL.
How do I tell Visual Basic to do the same thing, or use the batch commands?
It's easier for me to code Batch files.
All replies (9)
Friday, January 10, 2014 4:21 AM âś…Answered
Hi Chan,
I think this will work, but this is OLD code. + Also, work in MS environment.
So I recommend if you can find another solution, you would use it instead of below.
Try this:
Dim MyCommand As String = "xcopy ""%HOMEDRIVE%\Program Files (x86)\FOLDER"" ""FOLDER BACKUP\Program Files (x86)\FOLDER"" /s /i /f"
Shell("cmd.exe /c " & MYCOMMAND)
Friday, January 10, 2014 3:19 AM | 1 vote
Hi,
Try this code:
Dim bPathString As String
bPathString = "File path"
Using BatchFile As New IO.StreamWriter(bPathString)
BatchFile.WriteLine("Batch command")
End Using
Process.Start(bPathString)
Friday, January 10, 2014 3:42 AM
I am completely new to VS and C++/C#, so I'm a bit confused as to what I should put in "File Path", and also when I input the Batch Command, I use some variables to help the command locate the folder I want the program to copy.
The command I am trying to use is
"xcopy "%HOMEDRIVE%\Program Files (x86)\FOLDER" "FOLDER BACKUP\Program Files (x86)\FOLDER" /s /i /f"
VS automatically has an issue with the %HOMEDRIVE% variable, and I need to use that, as well as %APPDATA%, %LOCALAPPDATA%, and %USERPROFILE%, in order to tell the program to copy or delete the directories I need it to.
http://ss64.com/nt/syntax-variables.html
For the stuff at the end of the code. Those are some extra variables that are needed to make all of my copy/delete commands work as they should.
**/f : **Displays source and destination file names while copying.
**/i : If Source is a directory or contains wildcards and Destination does not exist, xcopy assumes destination specifies a directory name and creates a new directory. Then, xcopy copies all specified files into the new directory. By default, xcopy prompts you to specify whether Destination is a file or a directory.
**/s : **Copies directories and subdirectories, unless they are empty. If you omit /s, **xcopy **works within a single directory.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true
And, I guess I should have said it before, but... Win8.1x64bit VB2010 trial
Friday, January 10, 2014 3:50 AM
Hi,
You need to create batch file first, then if it existed, you trigger this code, giving you example like,
Dim bPathString As String
bPathString = "C:/Users/Desktop/batch.ini"
Using BatchFile As New IO.StreamWriter(bPathString) 'Your Command
BatchFile.WriteLine("xcopy "%HOMEDRIVE%\Program Files (x86)\FOLDER" "FOLDER BACKUP\Program Files (x86)\FOLDER" /s /i /f")
End Using
Process.Start(bPathString)
Friday, January 10, 2014 4:13 AM
Hmm, well it still doesn't seem to work when I input the code. The command code seems to break, so I'm not sure what to do at this point.
https://www.dropbox.com/sh/mk6sz0tvesejx5r/0ThGNKQTPh
Friday, January 10, 2014 4:17 AM
Oh wait, I didn't see the first part of your message, and I already have batch files made for all 3 functions, and the only way I'd want to include them in the main program is if I can somehow pack them into the application, so it's just a single .exe that is downloaded.
Friday, January 10, 2014 4:50 AM
Yes, thank you so much. It's working perfectly as I'd like the scripts to! ^^
Could you also tell me how to make it so the program can't be re-sized?
As well as when the command is finished, maybe make a pop up to notify the user? xD
Friday, January 10, 2014 5:58 AM
If you're using VB.NET,
Make "FormBorderstyle" of your main form "Fixed3D" or other fixed style.
Default setting may be "Sizable".
also, make "MaximizeBox" to False. then user cannot resize the windows form.
To make Pop-up, you should design another windows form and call that form with the
MyForm.ShowDialog command.
but if you just want to present a brief message then just use "MsgBox" command
Friday, January 10, 2014 7:32 AM
Thank's again. ^^
And, the pop-up thing doesn't seem to be functioning right when I try it.
If MsgBox("Would you like to create a backup of your Folder? If 'Yes', you will find your backup on the Desktop in the folder 'Folder Backup'. If 'No', then no action will be taken.", vbYesNo) = vbYes Then
Else : End If
Even if i select yes or no, it continues.