|
-
Sep 4th, 2005, 08:42 PM
#1
Thread Starter
Admodistrator
Shellexecute not working?
If im right here, using shellexecute with parameters is just like creating a shortcut and adding it right there?
so using this code:
VB Code:
ShellExecute me.hwnd, vbNullString, app.path & "\yay.exe", " -time 12", vbNullString, 1
is the same as right clicking yay.exe and adding into the properties bar -time 12?
Well ive never had a problem until now, and the exe i have is crashing. I cant post it because of copyright etc etc...Hoping someone here knows a resolution to it?
-
Sep 4th, 2005, 08:47 PM
#2
Re: Shellexecute not working?
I don't know if vbNullString works for an action, but you are right about the command line arguments. They are the same as they would be if you added them to the properties of the icon or shortcut to the icon. I always used OPEN, EDIT, or PRINT, which I suppose are actions based on the file type.
-
Sep 4th, 2005, 08:58 PM
#3
Thread Starter
Admodistrator
Re: Shellexecute not working?
on other shellexecute's ive used it, so i guess it would work. What other paramater should i pass instead?
-
Sep 4th, 2005, 09:04 PM
#4
Re: Shellexecute not working?
I always used OPEN, EDIT, or PRINT, which I suppose are actions based on the file type.
I added that after I posted.
-
Sep 4th, 2005, 11:29 PM
#5
Thread Starter
Admodistrator
Re: Shellexecute not working?
So any other ideas? i cant use shell because the path has spaces in it.. : (
-
Sep 4th, 2005, 11:33 PM
#6
Re: Shellexecute not working?
Shellexecute is a good option but try your parameters from the run dialog box. It may be the space between the items for you params - " -time 12".
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 4th, 2005, 11:36 PM
#7
Thread Starter
Admodistrator
Re: Shellexecute not working?
if i even try it without paramaters it crashes?? i dont get it!
-
Sep 4th, 2005, 11:37 PM
#8
Re: Shellexecute not working?
You could use GetShortPathName API, but I have used things like this:
VB Code:
Option Explicit
Private Sub Form_Load()
Dim Netshare$, DirectoryName$
Netshare = "David"
DirectoryName = "d:\david"
Shell ("C:\Windows\System32\cmd.exe /c C:\Windows\System32\net share " & Netshare & "=" & DirectoryName), vbNormalFocus
End Sub
and this:
VB Code:
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 Const SW_SHOWNORMAL As Long = 1
Private Const SW_HIDE As Long = 0
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Dim sSave As String, Ret As Long
Private Sub Form_Load()
'KPD-Team 1998
'URL: [url]http://www.allapi.net/[/url]
Dim sSave As String, Ret As Long
'Create a buffer
sSave = Space(255)
'Get the system directory
Ret = GetSystemDirectory(sSave, 255)
'Remove all unnecessary chr$(0)'s
sSave = Left$(sSave, Ret)
End Sub
Private Sub Command1_Click()
ShellExecute Me.hwnd, "Open", sSave & "CMD.exe", " /c dir c: > D:\Myfile.txt", "D:\", SW_SHOWNORMAL
End Sub
-
Sep 4th, 2005, 11:39 PM
#9
Re: Shellexecute not working?
Then its your exe and not the parameters? Post your code for the Startup procedure.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 4th, 2005, 11:41 PM
#10
Thread Starter
Admodistrator
Re: Shellexecute not working?
i can run the exe normally and i can run a shortcut with the parameters i want. What do you mean the code for my startup procedure rd?
-
Sep 4th, 2005, 11:45 PM
#11
Re: Shellexecute not working?
The exe's Form_Load code or Sub Main.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 4th, 2005, 11:47 PM
#12
Thread Starter
Admodistrator
Re: Shellexecute not working?
It isnt my .exe, so i dont have any of that stuff mate 
I just dont get why shellexecute is causing errors. Can i wrap the shell() command with quotes for use with spaces? shell("""c:\yay ay\yay.exe""") ?
-
Sep 4th, 2005, 11:49 PM
#13
Re: Shellexecute not working?
Correct. 
I do think it has something to do with the space inbetween your argument though.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 5th, 2005, 12:00 AM
#14
Thread Starter
Admodistrator
Re: Shellexecute not working?
right rob, but if i take out the arguments it still has errors as i said before
Code:
ShellExecute me.hwnd, vbNullString, app.path & "\yay.exe", vbnullstring, vbNullString, 1
i think that will clarify better
-
Sep 5th, 2005, 12:02 AM
#15
Re: Shellexecute not working?
Maybe it needs to start in that directory? Pass the app.path as the last argument. I've seen that happen when you want to read a file in.
-
Sep 5th, 2005, 12:04 AM
#16
Re: Shellexecute not working?
You need to specify the verb and other parameters as they are important.
VB Code:
ShellExecute me.hwnd, "Open", app.path & "\yay.exe", vbnullstring, "C:\", 1
The "C:\" is your working directory which is very important. If your working dir is not matching what the exe needs then that could cause it to fail depending on your exe. Change it to what the shortcut properties specify as the working dir.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 5th, 2005, 12:05 AM
#17
Re: Shellexecute not working?
Also, if your running in the IDE the app.path is the path to VB6.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 5th, 2005, 12:09 AM
#18
Re: Shellexecute not working?
Not if you open a vbp file that has been saved in a different folder. Then app.path works fine in the IDE.
-
Sep 5th, 2005, 12:11 AM
#19
Thread Starter
Admodistrator
Re: Shellexecute not working?
 Originally Posted by RobDog888
You need to specify the verb and other parameters as they are important.
VB Code:
ShellExecute me.hwnd, "Open", app.path & "\yay.exe", vbnullstring, "C:\", 1
The "C:\" is your working directory which is very important. If your working dir is not matching what the exe needs then that could cause it to fail depending on your exe. Change it to what the shortcut properties specify as the working dir.
i wish i had known about "Open" before, ill try it before. Also, i thought i could leave out C:\ because it will always be different, i thought this was the advantage of shellexecute?
-
Sep 5th, 2005, 12:11 AM
#20
Re: Shellexecute not working?
Maybe I should be more clear. Make sure your exe is in the expected directory.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 5th, 2005, 12:15 AM
#21
Thread Starter
Admodistrator
Re: Shellexecute not working?
VB Code:
ShellExecute Servers.hwnd, "Open", app.path & "\yay.exe", vbNullString, "C:\", 1
still getting the same error! i dont understand this stupid thing
-
Sep 5th, 2005, 12:18 AM
#22
Re: Shellexecute not working?
Ok, is "C:\" the directory where your exe resides?
Try it with a different exe?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 5th, 2005, 12:20 AM
#23
Re: Shellexecute not working?
I meant something like this:
VB Code:
ShellExecute Servers.hwnd, "Open", app.path & "\yay.exe", vbNullString, app.path, 1
-
Sep 5th, 2005, 12:23 AM
#24
Thread Starter
Admodistrator
Re: Shellexecute not working?
app.path is just an example, its dynamic depending on user input
-
Sep 5th, 2005, 12:28 AM
#25
Re: Shellexecute not working?
Well, change the second example to the actual folder, and see if it works.
-
Sep 5th, 2005, 12:32 AM
#26
Thread Starter
Admodistrator
Re: Shellexecute not working?
yeah that works..i guess ill just have to figure a way to get the path from the .exe path..i dont get why we need that 2nd path though
-
Sep 5th, 2005, 12:46 AM
#27
Re: Shellexecute not working?
You'll like the second one 
VB Code:
Option Explicit
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long
Private Declare Function GetFullPathName Lib "kernel32" Alias "GetFullPathNameA" (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal lpFilePart As String) As Long
Public Function GetShortPath(strFileName As String) As String
'KPD-Team 1999
'URL: [url]http://www.allapi.net/[/url]
Dim lngRes As Long, strPath As String
'Create a buffer
strPath = String$(165, 0)
'retrieve the short pathname
lngRes = GetShortPathName(strFileName, strPath, 164)
'remove all unnecessary chr$(0)'s
GetShortPath = Left$(strPath, lngRes)
End Function
Function GetFullPath() As String
'KPD-Team 2000
'URL: [url]http://www.allapi.net/[/url]
Dim Buffer As String, Ret As Long
'create a buffer
Buffer = Space(255)
'copy the current directory to the buffer and append "Project1.vbp"
Ret = GetFullPathName("Project1.vbp", 255, Buffer, "")
'remove the unnecessary chr$(0)'s
GetFullPath = Left(Buffer, Ret)
Oops. that may not work if it's not your app. The second one is the start-in folder that is needed so Windows knows were to read ini files, and the like.
-
Sep 5th, 2005, 12:50 AM
#28
Thread Starter
Admodistrator
Re: Shellexecute not working?
all i did was use instrrev and find \ and then used mid to get the rest of it. Thanks alot guys, i would never have gotten that!
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
|