|
-
Sep 7th, 2007, 04:59 PM
#1
Thread Starter
Member
Shell function - how do I do this?
Hey all,
I'm needing to run an .EXE outside the program and return a number for its result (the .EXE is a serial number validity checker); 1 if the serial number is valid, and anything else isn't.
Right now, i'm using the Shell command/function to shell out to the .EXE, then checking the return variable assigned to the Shell command to see if its 1. I need it to return to the program only after it completes running the outside .EXE; it states by default it runs things asynchronously; is there a way to change this? It doesn't seem to work properly...am I doing this correctly?
-
Sep 7th, 2007, 07:55 PM
#2
Re: Shell function - how do I do this?
' this will run the windows calculater
Dim ReturnValue
ReturnValue = Shell("calc.exe", 1) ' Run Calculator.
AppActivate ReturnValue ' Activate the Calculator.
Does this help
-
Sep 7th, 2007, 08:28 PM
#3
Thread Starter
Member
Re: Shell function - how do I do this?
 Originally Posted by wes4dbt
' this will run the windows calculater
Dim ReturnValue
ReturnValue = Shell("calc.exe", 1) ' Run Calculator.
AppActivate ReturnValue ' Activate the Calculator.
Does this help
I just had:
Code:
ReturnValue = Shell("hornetrez.exe", 1)
if ReturnValue<>1 then msgbox "Error: code " & ReturnValue &"."
Would this not work? Do I have to use the "AppActivate" thing for it to get a return value from the program, and not return to the program until its done executing?
-
Sep 7th, 2007, 08:42 PM
#4
Re: Shell function - how do I do this?
Search the forums for ShellWait (or ShellAndWait). Someone on these forums wrote a function a while ago that returned a value, only when the application that was run had finished executing.
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Sep 7th, 2007, 08:59 PM
#5
Re: Shell function - how do I do this?
try this
' this will run the windows calculater
Dim ReturnValue
ReturnValue = Shell("calc.exe", 1) ' Run Calculator.
msgbox returnvalue
ReturnValue equal the application ID not any results.
-
Sep 7th, 2007, 10:58 PM
#6
Re: Shell function - how do I do this?
That will execute straight away. What they are after is, calc runs.. and when it closes, the Messagebox pops up. Not all at once..
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Sep 7th, 2007, 11:15 PM
#7
Fanatic Member
Re: Shell function - how do I do this?
You might want to stay away from the Shell command. It doesn't work properly under Vista. You should use a system call to the ShellExecute function. It passes things along to Windows and lets the system handle it properly. Define Shell Execute like this:
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
Now that you have it defined you can call it. If you have a document you want to open like "mydoc.doc" or a file that has an extension registered with Windows like a .JPG file you can do it this way:
OpenThisFile$ = "MyDoc.Doc"
ShellExecute hWnd, "open", OpenThisFile$, vbNullString, vbNullString, SW_SHOW
If you have an EXE file you want to open you can do it this way:
OpenThisProg$ = "myprog.exe"
rc = ShellExecute(0&, vbNullString, OpenThisProg$, vbNullString, vbNullString, vbMaximizedFocus)
Hope that helps.
--DB
-
Sep 8th, 2007, 07:03 AM
#8
Thread Starter
Member
Re: Shell function - how do I do this?
 Originally Posted by Darkbob
You might want to stay away from the Shell command. It doesn't work properly under Vista. You should use a system call to the ShellExecute function. It passes things along to Windows and lets the system handle it properly. Define Shell Execute like this:
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
If you have an EXE file you want to open you can do it this way:
OpenThisProg$ = "myprog.exe"
rc = ShellExecute(0&, vbNullString, OpenThisProg$, vbNullString, vbNullString, vbMaximizedFocus)
--DB
Yes, my program should work under most modern versions of Windows (maybe NT through Vista?).
With your above example, how would I put the Error or Return Code (I guess that's what I need returned) of running the .EXE into a variable I can refer to later? Will this ShellExecute thing only return to the program once its done executing?
I need actual code in this case; i'm lost. .EXE name is hornetrez.exe, and I need to check to see if the code returned from this .EXE is 1 after execution is complete, if so, then the serial number is valid, otherwise display a message box error.
-
Sep 8th, 2007, 07:08 AM
#9
Re: Shell function - how do I do this?
If you ran this program, by itself, and it verified a serial number, what would it do to indicate that?
-
Sep 8th, 2007, 07:20 AM
#10
Thread Starter
Member
Re: Shell function - how do I do this?
 Originally Posted by Hack
If you ran this program, by itself, and it verified a serial number, what would it do to indicate that?
The .EXE itself is supposed to check two different locations to verify the serial number is present and valid (I think it connects to a database of some kind to do so) and then is designed to return a code: 1 if everything went ok, and then anything is else is supposed to be an error. I'm implementing it as part of a serial protection scheme for a product about to be released (company and product not given for obvious reasons ).
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
|