Running a batch file from VB with shell - Techist - Tech Forum

Go Back   Techist - Tech Forum > Computer Software > Programming
Click Here to Login
Closed Thread
 
Thread Tools Display Modes
 
Old 01-15-2011, 05:34 PM   #1 (permalink)
Ultra Techie
 
QuaziBee's Avatar
 
Join Date: Jun 2007
Location: Calgary, AB
Posts: 661
Default Running a batch file from VB with shell

Trying to use:
Shell("command.com /c G:\Whyland\PullFromBack1.bat")

It just flashes the cmd window for a second and does not run. Googling this, people just say to use Shell("[batch path and name]") but most of those posts are from like 2000 and it doesn't work.

What do?
__________________

__________________
Network Administrator /
Project Coordinator
Moli Industries LTD.
www.rapidts.com
QuaziBee is offline  
Old 01-15-2011, 05:38 PM   #2 (permalink)
It's all just 1s and 0s
 
office politics's Avatar
 
Join Date: Jan 2004
Location: in the lab
Posts: 6,555
Send a message via MSN to office politics
Default Re: Running a batch file from VB with shell

what happens when you remove command.com /c ? just tell the shell to run the batch file

im also not sure why you tried command.com instead of cmd.exe
__________________

office politics is offline  
Old 01-15-2011, 06:12 PM   #3 (permalink)
Ultra Techie
 
QuaziBee's Avatar
 
Join Date: Jun 2007
Location: Calgary, AB
Posts: 661
Default Re: Running a batch file from VB with shell

I have tried
Shell("G:\Whyland\PullFromBack1.bat")
Shell("cmd /c G:\Whyland\PullFromBack1.bat")
Shell("C:\Windows\system32\cmd.exe G:\Whyland\PullFromBack1.bat")
Shell("C:\Windows\system32\cmd.exe /c G:\Whyland\PullFromBack1.bat")
Shell("cmd /c" & " G:\Whyland\PullFromBack1.bat")


command.com was just the last in that line that I tried.
__________________
Network Administrator /
Project Coordinator
Moli Industries LTD.
www.rapidts.com
QuaziBee is offline  
Old 01-15-2011, 06:29 PM   #4 (permalink)
It's all just 1s and 0s
 
office politics's Avatar
 
Join Date: Jan 2004
Location: in the lab
Posts: 6,555
Send a message via MSN to office politics
Default Re: Running a batch file from VB with shell

copy paste?

Run a .bat file from VB

Code:
Dim wshThisShell As WshShell
Dim lngRet as Long
Dim strShellCommand As String
Dim strBatchPath as String

Set wshThisShell = New WshShell
strBatchPath = "C:\Program Files\Batch Path\Batch.bat"
'the path for the batch file you're using 
strShellCommand = """" & strBatchPath & """"
'the ridiculous number of quotation marks is necessary
'when there is a space in one or more of the folder names
lngRet = wshThisShell.Run(strShellCommand, vbNormalFocus, vbTrue)
'set 3rd argument above to vbFalse for asynchronous
'execution of the batch file.


edit - from ms forums, more specific to your exact problem

http://social.msdn.microsoft.com/for...7-2D1A4E35F127

Code:
Dim p As New Process
        p.StartInfo.FileName = "test.bat"
        p.StartInfo.WorkingDirectory = "c:\"
        p.Start()
office politics is offline  
Old 01-16-2011, 07:57 AM   #5 (permalink)
Seg Fault'n
 
Join Date: Jul 2005
Location: The dried husk where America came from
Posts: 5,801
Default Re: Running a batch file from VB with shell

Shell probably doesn't hold the command window open so what you're seeing is the batch file running and then closing down straight away. To see whether this is the case (since you almost certainly won't be able to debug into the batch?) make the batch write some output (maybe the time) into a file. If the file is present and has the expected time after running your application then you know that the batch is being called.
__________________


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page
"Get your money and let's go to court!" - Craig Mudie, MS
kmote is offline  
Old 01-16-2011, 04:32 PM   #6 (permalink)
Ultra Techie
 
QuaziBee's Avatar
 
Join Date: Jun 2007
Location: Calgary, AB
Posts: 661
Default Re: Running a batch file from VB with shell

I put a Pause at the end of the batch file and it stayed open after launching it from within the VB script. Turns out the command I was calling in the script was not registered with windows. Dropped the .exe into system32 and it now works like a charm.

Final code looks like

Shell("cmd /c G:\Whyland\PullFromBack1.bat", AppWinStyle.NormalFocus)


------

New question.
I'm trying to determine if a file exists on remote computers. I decided to use:

Quote:
If Dir("\\OBS" & TextBox1.Text & "T1\C$\SC\File.ini") <> "" Then
MsgBox("Totally there!")
Else
MsgBox("More work for me!")
End If
The naming convention of the computers looks like OBSXXXXT1 so I just put in the XXXX number for each computer.
This works fine on any computer that I either map a network drive to or am currently browsing because it requires credentials.

My question is where and how to amend this command to include the admin username and pw?
__________________
Network Administrator /
Project Coordinator
Moli Industries LTD.
www.rapidts.com
QuaziBee is offline  
Old 01-16-2011, 07:46 PM   #7 (permalink)
It's all just 1s and 0s
 
office politics's Avatar
 
Join Date: Jan 2004
Location: in the lab
Posts: 6,555
Send a message via MSN to office politics
Default Re: Running a batch file from VB with shell

wsh has a function named mapnetworkdrive

Microsoft Windows 2000 Scripting Guide - Managing Network Drives
__________________

office politics is offline  
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to: output to a txt file the results of a copy command from a batch file QuaziBee Programming 4 01-12-2011 02:24 PM
Creating a password protected batch file with a batch file MattPwns Programming 2 07-03-2010 04:04 PM
Batch scripting: Startup applications and close batch file LincolnX Microsoft Windows and Software 7 01-17-2008 07:50 PM
Batch-file - File compare question Spitwolf Microsoft Windows and Software 8 02-28-2006 09:53 AM
running batch file (Java) baloon Programming 3 05-13-2004 09:23 AM



Copyright 2002- Social Knowledge, LLC All Rights Reserved.

All times are GMT -5. The time now is 06:33 AM.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2018, vBulletin Solutions, Inc.