Results 1 to 4 of 4

Thread: Batch

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    35

    Batch

    Hey guys/girls

    I have a problem. I made a program that runs batch files from a location on our network.



    When I press a button, the code looks like this:


    VB Code:
    1. Private Sub Arcadre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Arcadre.Click
    2.         txtCommand.Text = "acadre.bat"
    3.         startThread()
    4. End Sub

    txtComand is a hidden label that contains the network path.

    Some of them work, and some don't. I don't understand why some batch files won't run. (The batch files installs the program selected).

    One batch file that doesn't work is for example the above code:

    VB Code:
    1. txtCommand.text = "\\network\path\path\acadre.bat

    Acadre.bat contains this line:
    VB Code:
    1. \\network2\path\path\acadreinst\AcadreClient.bat

    The final batch file contains a small amount of code:
    VB Code:
    1. rd /s /q %temp%\acadrecache
    2. start /wait msiexec /x{490AFB76-A301-4BAB-8BD5-AE796C304F21} REBOOT=R /qn
    3. regedit /s \\network2\path\path\acadreinst\AcadreClient.reg
    4. regsvr32 /s c:\program files\lotus\notes\nlsxbe.dll
    5. start /wait msiexec /i \\network2\path\path\acadreinst\acadreclient.msi /qb! ADDLOCAL=CM,CM_Core,CM_Core_Shortcuts,CM_EI,CM_GIS,CM_KA,CM_LN,CM_Off2000,CM_Routing REMOVE=MM,MM_Client,MM_Client_Shortcuts,MM_OL,MM_Off2000

    I didn't code the batch files, I just need to get them to run via the interface.

    Am I doing something wrong or is it possible to code the last batch inside vb and drop the batch files?
    Visual Basic 2005 Express
    SQL Server 2005 Express
    WinXP Pro

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Batch

    I have a few issues with your code. I hate Hungarian notation personally, but if you're going to use it you should try to be consistent. "txt" implies a TextBox while "lbl" implies a Label. Also, you appear to not have used a prefix for what I assume is the Button Arcadre. Also, why would you use a hidden Label? Why would you not just use a String variable?

    As for your issue, how are you actually running the batch file?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    35

    Re: Batch

    Forgot about that. Sorry.

    VB Code:
    1. Private Sub startThread()
    2.         Dim CMDThread As New Threading.Thread(AddressOf CMDAutomate)
    3.         CMDThread.Start()
    4.     End Sub
    5.  
    6.     Private Sub CMDAutomate()
    7.         Control.CheckForIllegalCrossThreadCalls = False
    8.         Dim myprocess As New Process
    9.  
    10.         Dim StartInfo As New System.Diagnostics.ProcessStartInfo
    11.         StartInfo.FileName = "cmd" 'starts cmd window
    12.         StartInfo.RedirectStandardInput = True
    13.         StartInfo.RedirectStandardOutput = True
    14.         StartInfo.UseShellExecute = False 'required to redirect
    15.         myprocess.StartInfo = StartInfo
    16.         myprocess.Start()
    17.         Dim SR As System.IO.StreamReader = myprocess.StandardOutput
    18.         Dim SW As System.IO.StreamWriter = myprocess.StandardInput
    19.         SW.WriteLine(txtCommand.Text) 'the command you wish to run.....
    20.         SW.WriteLine("exit") 'exits command prompt window
    21.         txtResults.Text = SR.ReadToEnd
    22.         SW.Close()
    23.         SR.Close()
    24.     End Sub

    CMDAutomate writes the output of the cmd screen in the textbox. And I use a hidden textbox, not a label. Sorry again. But that isn't the important part

    What do you mean by hungarian code?
    Visual Basic 2005 Express
    SQL Server 2005 Express
    WinXP Pro

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2006
    Posts
    35

    Re: Batch

    No one?
    Visual Basic 2005 Express
    SQL Server 2005 Express
    WinXP Pro

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width