Solved

Execute cURL command using Visual Basic/vbScript

Posted on 2013-12-10
9
4,721 Views
Last Modified: 2013-12-11
Hello,

Can someone help me understand how to execute a cURL command using a Visual Basic code/vbScript? Basically, I am trying to develop a gui to execute some repetitive tasks in DataPower using SOMA scripts. In short, a cURL command to execute a SOMA script would look like this:

curl --insecure -u bji:datapower00 --data-binary @'C:\cygwin64\bin\AMP_getdomainlist.xml' https://24.172.189.104:4440/service/mgmt/amp/1.0

Right now, I am using Cygwin (UNIX simulator for Windows) to execute that command.

Thanks!
Jay
0
Comment
Question by:Jammerules
  • 5
  • 3
9 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 39710437
Is CURL in the path?  If so, you can Shell it from the VBA environment or use a wscript.shell object's RUN() method.

If you open a command prompt window, can you type that CURL command as you've written it an it will run, or do you need to change to a different drive or directory first?  If the command will run anywhere, you might use a tweaked version of my first comment, by prefacing the CURL command with a "cmd /c " string.
0
 

Author Comment

by:Jammerules
ID: 39710457
Here is the piece of code I came up with. For some reason when I execute it, I am unable to output into a local file.

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpszOp As String, ByVal lpszFile As String, ByVal lpszParams As String, ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
 
Public Function RunCMD(ByVal FileName As String) As String
   RunCMD = ShellExecute(0, "open", FileName, "", "", 1)
End Function
''
Private Sub cmdSubmit_Click()
Dim fname As String
fname = "c:\temp\Test.bat"
RunCMD fname
DoEvents
MsgBox "Done"
End
End Sub

Open in new window


On the other hand, if I just double clicked the Test.bat file, the result is outputted to a file. Here is the cURL command that I am using:
curl --insecure -u usrnm:pwd --data-binary @"C:\SOMA Scripts\getLogs.xml" https://24.172.189.99:4440/service/mgmt/2004 -o cURLOutputfile.txt 

Open in new window

0
 
LVL 45

Expert Comment

by:aikimark
ID: 39711339
1. have you done a file search on your hard drive for cURLOutputfile.txt?
2. I'm concerned about the END statement on line 13.  Why is it there?

Your batch file does not set a drive or directory prior to executing the CURL command. The output file will go to the default directory, usually c:\users\yourlogin\
0
 

Author Comment

by:Jammerules
ID: 39711640
1. I did search for the output file and to no avail.
2. The END is there to kill the program execution. I tried executing  without it and it still behaves the same way.

See attached picture for better understanding. I had to mask to user name and password after "-u"
Output.jpg
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:Jammerules
ID: 39711644
... by prefacing the CURL command with a "cmd /c " string.

Can you elaborate on this?
0
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points
ID: 39711707
I noticed two things:
1. the current directory is not the default directory
2. one of these two commands did not work
0
 

Author Comment

by:Jammerules
ID: 39712061
The difference I see between running the bat file via VB and stand alone is that, when I run from VB, the command prompt looks like this:

C:\Program Files (x86)\Microsoft Visual Studio\VB98

whereas running stand alone looks like:

C:\temp\

I have installed cURL files in VB98 separately. How can I make my vb code to cURL from the default Windows path?
Output.jpg
0
 

Author Comment

by:Jammerules
ID: 39712185
Success!

So, this is what I did.

1. First I made an "exe" of the program.
2. Next, I copied all the cURL.exe and its dlls to the same folder where I have my Visual Basic exe

That fixed it! :)

Thanks for your responses though.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now