|
-
Oct 3rd, 2005, 12:12 PM
#1
Thread Starter
Junior Member
[RESOLVED] VBA Shell Problem
I'm working on a program written in VBA that uses the Shell() function to call a command line executable. The problem is that this code never outputs to the file "checksum"
VB Code:
Call Shell("C:\instagram\md5sum\fciv.exe C:\instagram\replicated\" & ThisWorkbook.user & "_binlog.txt > C:\instagram\replicated\checksum")
Does anyone know why this code might not be working correctly?
I've run this from cmd shell and it goes off without an hitches.
Thanks in advance,
Ross
-
Oct 3rd, 2005, 12:18 PM
#2
-
Oct 3rd, 2005, 12:58 PM
#3
Re: VBA Shell Problem
I think I attempted such things before, and came to the conclusion that you can't use Shell to pass a command line argument. As I recall, you can do a workaround in terms of running cmd.exe and then sending it keys, but I don't think you can do it directly like that.
But I'm prepared to be wrong.
zaza
-
Oct 3rd, 2005, 01:07 PM
#4
Re: VBA Shell Problem
Here you go zaza. I added the parameters how I think you need them. Not sure if the working directory is the right one either. Also, ThisWorkbook.user does not show for me so I assume its a custom property or function.
VB Code:
Option Explicit
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
Private Const SW_HIDE As Long = 0
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMINIMIZED As Long = 2
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Sub CommandButton1_Click()
ShellExecute Application.hwnd, "Open", "C:\instagram\md5sum\fciv.exe", "C:\instagram\replicated\" & ThisWorkbook.user & "_binlog.txt > C:\instagram\replicated\checksum", "C:\instagram\replicated", SW_SHOWNORMAL
End Sub
I also have written code to shell the CMD.exe and output to a file if you need it.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 3rd, 2005, 02:32 PM
#5
Re: VBA Shell Problem
Aha, the old "ShellExecute" trick.
Nice one RD.
But I still don't think you can do it just by passing the whole string to Shell().
zaza
-
Oct 3rd, 2005, 02:42 PM
#6
Re: VBA Shell Problem
Did it work though? Also shouldnt checksum be a file and not a directory?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 3rd, 2005, 02:50 PM
#7
Re: VBA Shell Problem
Actually, the code isn't for me...
I'm sure he appreciates it, though.
-
Oct 9th, 2005, 11:54 AM
#8
Thread Starter
Junior Member
Re: VBA Shell Problem
Actually I found a near identical code snippet on the net elsewhere and still doesn't seem to work.
However, I found another workaround to accomplish the task I needed.
I wanted to make sure that in between programmatic writes to the binary log someone did not enter in their own statements. As the bin log will be used as publisher to a database this could be disasterous.
Anyway, if anyone cares, instead of writing the binlog to a file everytime, it writes to a BLOB field in a table. Only when the binlog is finally being used is the contents of the BLOB written to the file, thereby ensuring no tampering in the meantime.
Even better, and MD5 in mySQL of the BLOB before the write, then a re-read of the binlog file back into the BLOB and an md5 after (before committing a transaction) provides yet another check
Anyway, I think zaza is correct.
Thanks anyway.
R
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|