I need to access a file that is stored on a local machine.
What is the code to say open "C:\RunThis.bat" when clicking cmdRun button? Forgive me if this is a simple question, but then it shouldnt take too long to answer.
Printable View
I need to access a file that is stored on a local machine.
What is the code to say open "C:\RunThis.bat" when clicking cmdRun button? Forgive me if this is a simple question, but then it shouldnt take too long to answer.
Also I might add another thing...
Is there a way to copy a local file to say make a backup?
For instance click cmdBackup and "C:\Runthis.bat" creates "C:\RunthisBackup.bat"
use the SHELL command to execute a batch file, and SHELLEXECUTE to open the file. SHELL (filename,0) will hide the window, 1 will run it with normal focus.
using FileSystemObject.CopyFile source,destination,overwrite
will copy a file. overwrite can be True or False.
Don't know if you are using a FSO, though.
there is also FileCopy source, destination
if you aren't
Hope this helps.
:D
You can use the Shell command which opens a program. To open a text file in notepad, for example:
ShellExecute is an API function (one which you must set a reference too) which will run a file in the default program.VB Code:
Shell "notepad ""C:\testfile.txt"""
That will run the bat file in the default program, which is, Command Prompt. Other examples are HTML files in the defualt browser, IE, Netscape, or others..VB Code:
'Example Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long ShellExecute 0, "Open", "C:\RunThis.bat", "", "C:\", 1
Phreak