Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling another program and providing a variable

Status
Not open for further replies.

GSMike

Programmer
Feb 7, 2001
143
US
We have this utility that allows you to take control of another user's machine. I want to automate that process to eliminate steps.
How do I call that program?
As is, I have to open a command window, change drives, change directories and then type in the executable name with the name of the target machine provided as a variable. This is the code I tried to automate, but it hangs on the "Shell...." line. Surprise, I knew it would. Any suggestions?

Code:
Sub Remote()
Dim machine As String
ChDir "C:\VNC"
machine = InputBox("What is the machine name?")
Shell "vnc " & machine
End Sub

Thank you!
 
Once you've collected the string for the application you want to open, you can use the StartDoc Function (below) which uses the Shell Execute Method.

Once you have collected a string for the application you want to open, you simply use the following:

Call StartDoc(Path String)

Call StartDoc("C:\My Documents\Spreadsheets\Test.xls") OR
Call StartDoc("C:\My Documents\Text Files\Test.txt") OR
for a network drive (unc path)
Call StartDoc("\\stcnov01\Data\users\jim\My Documents\spreadsheets\phonelist.xls")

Copy the following into a blank module and save it: Then you can use the StartDoc function to open other applications.

====================
Public 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 Declare Function GetDesktopWindow Lib "user32" () As Long

Public Const SW_SHOWNORMAL = 1
Public Const SE_ERR_FNF = 2&
Public Const SE_ERR_PNF = 3&
Public Const SE_ERR_ACCESSDENIED = 5&
Public Const SE_ERR_OOM = 8&
Public Const SE_ERR_DLLNOTFOUND = 32&
Public Const SE_ERR_SHARE = 26&
Public Const SE_ERR_ASSOCINCOMPLETE = 27&
Public Const SE_ERR_DDETIMEOUT = 28&
Public Const SE_ERR_DDEFAIL = 29&
Public Const SE_ERR_DDEBUSY = 30&
Public Const SE_ERR_NOASSOC = 31&
Public Const ERROR_BAD_FORMAT = 11&

Public Function StartDoc(DocName As String) As Long
' Example: Call StartDoc("C:\error.log")
Dim Scr_hDC As Long
Dim msg As String
Scr_hDC = GetDesktopWindow()
StartDoc = ShellExecute(Scr_hDC, "Open", DocName, "", "C:\", SW_SHOWNORMAL)

If StartDoc <= 32 Then
'There was an error
Select Case StartDoc
Case SE_ERR_FNF
msg = &quot;File not found&quot;
Case SE_ERR_PNF
msg = &quot;Path not found&quot;
Case SE_ERR_ACCESSDENIED
msg = &quot;Access denied&quot;
Case SE_ERR_OOM
msg = &quot;Out of memory&quot;
Case SE_ERR_DLLNOTFOUND
msg = &quot;DLL not found&quot;
Case SE_ERR_SHARE
msg = &quot;A sharing violation occurred&quot;
Case SE_ERR_ASSOCINCOMPLETE
msg = &quot;Incomplete or invalid file association&quot;
Case SE_ERR_DDETIMEOUT
msg = &quot;DDE Time out&quot;
Case SE_ERR_DDEFAIL
msg = &quot;DDE transaction failed&quot;
Case SE_ERR_DDEBUSY
msg = &quot;DDE busy&quot;
Case SE_ERR_NOASSOC
msg = &quot;No association for file extension&quot;
Case ERROR_BAD_FORMAT
msg = &quot;Invalid EXE file or error in EXE image&quot;
Case Else
msg = &quot;Unknown error&quot;
End Select
If msg <> &quot;Unknown error&quot; Then MsgBox msg
End If
End Function
==================== Jim Lunde
compugeeks@hotmail.com
Custom Application Development
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top