Solved

launch exe on remote server

Posted on 2006-11-27
7
512 Views
Last Modified: 2012-06-21
Hi,

I am trying to launch an .EXE from a remote server using VB 6. I am using a UNC path. This application runs fine if logged in to the local workstatiion as administrator. The whole purpose of this is to allow students to an application on a windows 2003 server. I have created an  account called "students" on the server. The idea is that when my VB app is launched it should log in to the server using the 'students' account and then in turn run the .EXE.

Any help will be much appreciated.

Neil
0
Comment
Question by:neoice
7 Comments
 
LVL 15

Expert Comment

by:JackOfPH
Comment Utility
shell "\\servername\c\test.exe"
0
 
LVL 12

Expert Comment

by:jkaios
Comment Utility
In addition to Jack's comment, you must "share" the folder on the server that houses the .EXE and allow the "students" account to be one of the users that can access that folder.  Then with you VB app, you can execute that program on the server using the Shell function.
0
 
LVL 11

Expert Comment

by:Dany Balian
Comment Utility
the permission to the shared folder is calculated based on the user account logged on on the local machine... however what you need to do (as i understood) is to use administrator privileges to run the program... so u have to use different logon username/password on the server, just for ur application.

here's the full code to authenticate and then run a program.. i've tried it and it works!!

dim computername as string, username as string, password as string, exepath as string
computername="server448"
username="administrator"
password="helloworld"
exepath="\shared\myexe.exe"

On Error Resume Next
Dim objwbemLocator, objWMIService
Set objwbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objwbemLocator.ConnectServer _
    (computername, "root\cimv2", username, password)
Select Case Err.Number
Case 0: Call Shell("\\" & computername & exepath, vbNormalFocus)
Case -2147024891: MsgBox "You do not have enough permissions to access this remote computer", vbCritical, "Error"
Case -2147217308: MsgBox "You cannot use this function on the local machine", vbCritical, "Error"
Case Else: MsgBox "An error occured, please retry", vbCritical, "Error"
End Select

hope this helps...

cheers

dan
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:neoice
Comment Utility
Hi,

Thanks for the reply. However, I get this message when I launch it:

"An error occured, please retry" -what have i done wrong?



Private Sub Form_Load()
Dim computername As String, username As String, password As String, exepath As String
computername = "back-up"
username = "administrator"
password = "password"
exepath = "\software\english\senior.exe"

On Error Resume Next
Dim objwbemLocator, objWMIService
Set objwbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objwbemLocator.ConnectServer(computername, "root\cimv2", username, password)
Select Case Err.Number
Case 0: Call Shell("\\" & computername & exepath, vbNormalFocus)
Case -2147024891: MsgBox "You do not have enough permissions to access this remote computer", vbCritical, "Error"
Case -2147217308: MsgBox "You cannot use this function on the local machine", vbCritical, "Error"
Case Else: MsgBox "An error occured, please retry", vbCritical, "Error"
End Select
End Sub

===============================================

I have used the following code to successfully launch the program but this only works if administrator is logged into the workstation.

Cheers,

Neil,


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 Sub Form_Load()

Dim sfile As String
sfile = "\\back-up\software\english\senior.exe"
Dim lngresult As String
On Error GoTo eed
lngresult = ShellExecute(0, "Open", sfile, 0&, 0&, vbMinimized): GoTo eeend
eed: MsgBox "error"
eeend:
Unload Me


End Sub
0
 
LVL 11

Accepted Solution

by:
Dany Balian earned 500 total points
Comment Utility
u changed the password of administrator with the correct administrator password right??

computername = "back-up"
username = "administrator"
password = "password"   '<<< this one should be the administrator password
exepath = "\software\english\senior.exe"


modify the last part of my code plz to this...

Select Case Err.Number
Case 0: Call Shell("\\" & computername & exepath, vbNormalFocus)
Case -2147024891: MsgBox "You do not have enough permissions to access this remote computer", vbCritical, "Error"
Case -2147217308: MsgBox "You cannot use this function on the local machine", vbCritical, "Error"
Case Else: MsgBox "Err: " & err.number  & vbcrlf & Err.description
end select

and give me the error number...
waiting for ur comments

Dan
0
 

Author Comment

by:neoice
Comment Utility
Hi,

I am using the administrator user name and password on the remote server.

error number is 2147217407

thanks in advance

Neil
0
 
LVL 23

Expert Comment

by:gecko_au2003
Comment Utility
check here :

http://www.computerperformance.co.uk/vbscript/wmi_process_start.htm#Scenario_-_Why_you_need_to_Launch_a_Processes_on_a_Remote_Machine_

using wmi to launch the process remotely

You can alter the vbscript to get rid of the InputBox etc and hard code the name of the machine and such.

Also porting this into vb 6 isnt that hard :)

That or you can add a reference to the scripting runtime in project --> references.

Hope this helps
0

Featured Post

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.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 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

10 Experts available now in Live!

Get 1:1 Help Now