Solved Open An Installer from a Shared Folder (1 Viewer)

abdullahkhan

Member
Local time
Tomorrow, 00:13
Joined
Apr 14, 2020
Messages
274
Hello,

I distribute my Frontend in the form of an installer. I am also creating a db that updates the program in case of update release (which will also be released as an executable installer. So how can I open an executable installer from a location (on LAN) by clicking on update button on my form. I tried
Code:
Dim sDBLink As String

sDBLink = "\\MY-PC\Backend\Updates\update.exe"

Shell (sDBLink, vbNormalFocus)

But it gives me error and installer don't start. How can I get it working.

Best Regards,
Abdullah
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:13
Joined
Sep 21, 2011
Messages
7,900
And the error is?

Seems it works if the path is mapped with a drive letter.?
 

abdullahkhan

Member
Local time
Tomorrow, 00:13
Joined
Apr 14, 2020
Messages
274
And the error is?

Seems it works if the path is mapped with a drive letter.?
Run-time Error 5
Invalid Procedure Call or Argument.

Sorry I could mentioned in my first post.
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:13
Joined
Sep 21, 2011
Messages
7,900
Well try
https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/shell-function
var=Shel(.... as shown, but I got 'file not found' error that way. I changed my UNC path to it's mapped drive letter and that started the exe no problem.

Found this at https://www.ozgrid.com/forum/index....-working-when-using-unc-path-for-saving-file/ so perhaps you could map and unmap the path.?

Code:
#If Win64 Then
Declare PtrSafe Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long
Declare PtrSafe Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETCONNECT, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
#Else
Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long
Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETCONNECT, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
#End If




Const CONNECT_UPDATE_PROFILE As Long = &H1
Const RESOURCE_CONNECTED As Long = &H1
Const RESOURCE_GLOBALNET As Long = &H2
Const RESOURCETYPE_DISK As Long = &H1
Const RESOURCEDISPLAYTYPE_SHARE As Long = &H3
Const RESOURCEUSAGE_CONNECTABLE As Long = &H1




Type NETCONNECT
dwScope As Long
dwType As Long
dwDisplayType As Long
dwUsage As Long
lpLocalName As String
lpRemoteName As String
lpComment As String
lpProvider As String
End Type




Function MapNetworkDrive(ByVal driveLetter As String, ByVal UNC As String) As Boolean
Dim dl As String * 1
Dim nc As NETCONNECT

dl = UCase$(driveLetter)

nc.dwScope = RESOURCE_GLOBALNET
nc.dwType = RESOURCETYPE_DISK
nc.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
nc.dwUsage = RESOURCEUSAGE_CONNECTABLE
nc.lpLocalName = driveLetter & ":"
nc.lpRemoteName = UNC

MapNetworkDrive = (WNetAddConnection2(nc, vbNullString, vbNullString, CONNECT_UPDATE_PROFILE))

End Function




Function DisconnectNetworkDrive(driveLetter As String) As Boolean
Dim dl As String * 1
Dim nc As NETCONNECT

nc.dwScope = RESOURCE_GLOBALNET
nc.dwType = RESOURCETYPE_DISK
nc.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
nc.dwUsage = RESOURCEUSAGE_CONNECTABLE
nc.lpLocalName = driveLetter & ":"
nc.lpRemoteName = vbNullString

DisconnectNetworkDrive = Not (WNetCancelConnection2(dl, CONNECT_UPDATE_PROFILE, False))
End Function
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:13
Joined
Sep 21, 2011
Messages
7,900
In fact I had my path incorrect?, missed off one level?
This works, in that is starts the exe.?
Code:
tt= Shell ("\\dlink323\usb250\Downloads\Everything-1.4.1.969.x86-Setup.exe", vbNormalFocus)
 

abdullahkhan

Member
Local time
Tomorrow, 00:13
Joined
Apr 14, 2020
Messages
274
In fact I had my path incorrect?, missed off one level?
This works, in that is starts the exe.?
Code:
tt= Shell ("\\dlink323\usb250\Downloads\Everything-1.4.1.969.x86-Setup.exe", vbNormalFocus)
Thanks for response. I ran the directly like shell (......) But it didn't work. Will try tt = shell(....) commands and post back here.
 

abdullahkhan

Member
Local time
Tomorrow, 00:13
Joined
Apr 14, 2020
Messages
274
I tried following:
Shell "\\MY-PC\Backend\Updates\update.exe", vbNormalFocus and received runtime error 5.

Shell ("\\MY-PC\Backend\Updates\update.exe", vbNormalFocus) and received syntax error.

tt= Shell "\\MY-PC\Backend\Updates\update.exe", vbNormalFocus and received variable not defined error.
 

abdullahkhan

Member
Local time
Tomorrow, 00:13
Joined
Apr 14, 2020
Messages
274
Issue is resolved. I found on some website that exe may be run with cmd. Following code worked.
Rich (BB code):
Dim sDBLink As String

sDBLink = "\\MY-PC\Backend\Updates\update.exe"

Shell (Shell "cmd /c """ & sDBLink & """", vbNormalFocus)

It opens cmd window alongwith the update.exe which closes on completion of installation.

Thanks for response.

Best Regards,
Abdullah
 

abdullahkhan

Member
Local time
Tomorrow, 00:13
Joined
Apr 14, 2020
Messages
274
In fact I had my path incorrect?, missed off one level?
This works, in that is starts the exe.?
Code:
tt= Shell ("\\dlink323\usb250\Downloads\Everything-1.4.1.969.x86-Setup.exe", vbNormalFocus)
Although my issue is resolved and exe can be run (but with a cmd window open along the installation) but I'm surprised why my exe don't run with command you mentioned in quoted post (i.e. without cmd, by just giving directly network link to file) and it is running fine with you. Any idea?
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:13
Joined
Sep 21, 2011
Messages
7,900
I am assigning to a variable as per the MS docs, you are not?
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:13
Joined
Sep 21, 2011
Messages
7,900
I tried that too. I declare ttvas variant and then tried tt = ...... But received the same runtime error
You might have, but then you did not use it as a function? Shell() ?
Try it from the immediate window, that is what I did to get the correct syntax.
 

Isaac

Lifelong Learner
Local time
Today, 12:13
Joined
Mar 14, 2017
Messages
4,382
Your original problem was using shell with parenthesis. Either run it as just
Code:
Shell ...
with no parenthesis, or else set a variable's value to the Function call, with parenthesis.
 

abdullahkhan

Member
Local time
Tomorrow, 00:13
Joined
Apr 14, 2020
Messages
274
You might have, but then you did not use it as a function? Shell() ?
Try it from the immediate window, that is what I did to get the correct syntax.

Thanks for reply. I tried the immediate window and it gives the same error. Can you look at the sample db and exe in the zip folder? Open the for frmStart and it has a button with a click event.

with no parenthesis, or else set a variable's value to the Function call, with parenthesis.
Thanks for reply. I tried with both with parenthesis and without. When I use it with variable, it gives syntax error if I don't use parenthesis and run-time error 5 if with parenthesis whereas it is vice versa if I use shell command directly i.e. without variable. Can you look at the attached db.

PS. The exe contained is the default test project which is present in the SSE setup. It do nothing with the PC. It just shows a message box that it is a test program and do nothing with the PC.
 

Attachments

  • RunExe.zip
    562.3 KB · Views: 28

Gasman

Enthusiastic Amateur
Local time
Today, 20:13
Joined
Sep 21, 2011
Messages
7,900
Sorry, but I am still not going to run an unknown exe.?

I amended your code to as below and it works fine, so no idea as to why you get a syntax error. my way does close the command window when finished. That is why I tried with a simple command file.

Code:
Private Sub cmdRun_Click()
Dim tt As Variant, sDBName As String, strDBPath As String

sDBName = "runexe.cmd"
strDBPath = Left(CurrentDb().Name, InStrRev(CurrentDb().Name, "\"))

'Shell sDBName, vbNormalFocus   'With parenthesis, it gives syntax error
'tt = Shell(sDBName, vbNormalFocus) 'Without parenthesis, it gives syntax error

'Shell "cmd /c" & sDBName, vbNormalFocus 'This command works but with a cmd window open. I want to get rid of cmd window too.
tt = Shell(strDBPath & sDBName, vbNormalFocus)
End Sub
 

abdullahkhan

Member
Local time
Tomorrow, 00:13
Joined
Apr 14, 2020
Messages
274
Sorry, but I am still not going to run an unknown exe.?
No worries, You could replace it with any exe file that you trust. I just wanted to find it where my code has any mistakes. Can you check that commands in my code works for you? I'll try using the code you provided too.
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:13
Joined
Sep 21, 2011
Messages
7,900
It runs any exe without any problems. You do not even need an exe, a bat or cmd file would do.
Check your path, though I would have expected 'file not found' error if that was incorrect.
Your path was no good to me, so I just used the DB path and copied and exe and created a cmd file to test.?
 

abdullahkhan

Member
Local time
Tomorrow, 00:13
Joined
Apr 14, 2020
Messages
274
Thanks for your time and responses. I'll check the new code that you provided and get back here.
 

abdullahkhan

Member
Local time
Tomorrow, 00:13
Joined
Apr 14, 2020
Messages
274
Sorry, but I am still not going to run an unknown exe.?

I amended your code to as below and it works fine, so no idea as to why you get a syntax error. my way does close the command window when finished. That is why I tried with a simple command file.

Code:
Private Sub cmdRun_Click()
Dim tt As Variant, sDBName As String, strDBPath As String

sDBName = "runexe.cmd"
strDBPath = Left(CurrentDb().Name, InStrRev(CurrentDb().Name, "\"))

'Shell sDBName, vbNormalFocus   'With parenthesis, it gives syntax error
'tt = Shell(sDBName, vbNormalFocus) 'Without parenthesis, it gives syntax error

'Shell "cmd /c" & sDBName, vbNormalFocus 'This command works but with a cmd window open. I want to get rid of cmd window too.
tt = Shell(strDBPath & sDBName, vbNormalFocus)
End Sub
It still gives me runtime error 5, Invalid procedure call. Anyway, Shell "cmd /c" & sDBName, vbNormalFocus will work for me. It doesn't seem nice to me to take your time any more just to avoid seeing cmd window :)

I just wanted to find out the reason why the same command is not working with me. The same code that is working for you is not working with me that may be because of some issue in my PC.

Thanks a lot again and best regards.
 

Users who are viewing this thread

Top Bottom