11 Replies - 1007 Views - Last Post: 04 June 2015 - 08:30 PM Rate Topic: -----

#1 xilith117   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 99
  • Joined: 13-August 11

I can't seem to open files using shell

Posted 19 May 2015 - 06:30 PM

Hello,
I usually program in vb.net but I had to take a few steps back for my current project. I cant for the life of me get my program to call another exe and open a file with it. in .net you could use
Process.Start(insert program here, insert file here)

in vb6, this does not work. I have two variables: X and Y. X contains the full path of my exe, and Y contains the full path of the file I want it to open. Can I do something like
Shell(x,y)
? Thanks guys.

Is This A Good Question/Topic? 0
  • +

Replies To: I can't seem to open files using shell

#2 djjeavons   User is offline

  • D.I.C Regular
  • member icon

Reputation: 114
  • View blog
  • Posts: 417
  • Joined: 09-January 09

Re: I can't seem to open files using shell

Posted 20 May 2015 - 12:26 AM

Hi

The Shell function only takes two arguments, path and window style so you will need to combine your file name to the end of the path. For example, if I wanted to open Word with a file name I could use:

Shell "C:\Program Files\Microsoft Office 15\root\office15\winword.exe c:\temp\test.docx"




HTH
Was This Post Helpful? 1
  • +
  • -

#3 xilith117   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 99
  • Joined: 13-August 11

Re: I can't seem to open files using shell

Posted 20 May 2015 - 02:08 PM

This seems fine and dandy but I still cant figure out how to use string variables to hold the paths.
something like "shell X Y" after setting X to one path and Y to another. I hope I was clear enough.

This post has been edited by andrewsw: 20 May 2015 - 02:11 PM
Reason for edit:: Removed previous quote, just press REPLY

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • blow up my boots
  • member icon

Reputation: 6551
  • View blog
  • Posts: 26,559
  • Joined: 12-December 12

Re: I can't seem to open files using shell

Posted 20 May 2015 - 02:12 PM

djjeavons 's example demonstrates this, concatenating the two paths with a space between them.
Was This Post Helpful? 0
  • +
  • -

#5 xilith117   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 99
  • Joined: 13-August 11

Re: I can't seem to open files using shell

Posted 20 May 2015 - 02:17 PM

View Postandrewsw, on 20 May 2015 - 02:12 PM, said:

djjeavons 's example demonstrates this, concatenating the two paths with a space between them.


Then shouldn't "Shell X Y" Work?
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw   User is offline

  • blow up my boots
  • member icon

Reputation: 6551
  • View blog
  • Posts: 26,559
  • Joined: 12-December 12

Re: I can't seem to open files using shell

Posted 20 May 2015 - 02:22 PM

No, it's Shell "X Y". Shell is the function you are calling.
Was This Post Helpful? 0
  • +
  • -

#7 xilith117   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 99
  • Joined: 13-August 11

Re: I can't seem to open files using shell

Posted 25 May 2015 - 08:02 PM

Shell "X Y" always says the file doesn't exist, no matter what X and Y are.
Was This Post Helpful? 0
  • +
  • -

#8 maj3091   User is offline

  • D.I.C Lover
  • member icon

Reputation: 330
  • View blog
  • Posts: 1,998
  • Joined: 26-March 09

Re: I can't seem to open files using shell

Posted 25 May 2015 - 11:58 PM

Then you need to post what your current code is now that you're concatenating your string for your call.

Would be worth printing out your string with the full call to the debug window (debug.print) just to verify it yourself that it's correct.
Was This Post Helpful? 0
  • +
  • -

#9 xilith117   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 99
  • Joined: 13-August 11

Re: I can't seem to open files using shell

Posted 26 May 2015 - 01:52 PM

View Postmaj3091, on 25 May 2015 - 11:58 PM, said:

Then you need to post what your current code is now that you're concatenating your string for your call.

Would be worth printing out your string with the full call to the debug window (debug.print) just to verify it yourself that it's correct.


Here is what I have:
 x = App.Path & "\snes9x.exe"
 y = App.Path & "\moo.smc"
If Dir(App.Path & "\snes9x.exe") <> "" Then
  MsgBox "xFile exists"
Else
  MsgBox "xFile does not exist"
End If

If Dir(App.Path & "\moo.smc") <> "" Then
  MsgBox "yFile exists"
Else
  MsgBox "yFile does not exist"
End If

Debug.Print (x)
Debug.Print (y)
 MsgBox x
 MsgBox y


 Shell "x y", vbNormalFocus
       
End Sub


With the current path I have my application in, the Debug.print returns "C:\Program Files (x86)\Microsoft Visual Studio\VB98\snes9x.exe" and "C:\Program Files (x86)\Microsoft Visual Studio\VB98\moo.smc" for X and Y. Pasting either of these addresses into my adress bar in windows explorer brings me to the correct file but running the program always says "file not found".
Was This Post Helpful? 0
  • +
  • -

#10 andrewsw   User is offline

  • blow up my boots
  • member icon

Reputation: 6551
  • View blog
  • Posts: 26,559
  • Joined: 12-December 12

Re: I can't seem to open files using shell

Posted 26 May 2015 - 02:00 PM

Shell "x y" has no connection to your variables x and y, "x y" is just a string.

You need to construct the argument for Shell using your x and y variables. You need to concatenate them. x & " " & y
Was This Post Helpful? 1
  • +
  • -

#11 xilith117   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 99
  • Joined: 13-August 11

Re: I can't seem to open files using shell

Posted 26 May 2015 - 02:28 PM

View Postandrewsw, on 26 May 2015 - 02:00 PM, said:

Shell "x y" has no connection to your variables x and y, "x y" is just a string.

You need to construct the argument for Shell using your x and y variables. You need to concatenate them. x & " " & y


Damn it. I thought that was what was happening but I couldn't get the concatenation to work right.

Thanks for the help! :bananaman:

This post has been edited by xilith117: 26 May 2015 - 02:33 PM

Was This Post Helpful? 0
  • +
  • -

#12 BobRodes   User is offline

  • Lovable Curmudgeon
  • member icon

Reputation: 600
  • View blog
  • Posts: 3,071
  • Joined: 19-May 09

Re: I can't seem to open files using shell

Posted 04 June 2015 - 08:30 PM

Here is the doc for Shell. Of particular interest is this quote:

Quote

Security Note
If you do not enclose the path and file specification in quotes, there is a security risk if the file name or a path node contains spaces. If the path node specification is not inside quotes, for example \Program Files and a program named Program.exe had been installed in C:\, for example by illicit tampering, Windows would execute it instead of MyFile.exe.


To add literal quotation marks, double them or use Chr$(34). For example, x = App.Path might be rendered x = "C:\""Program Files (x86)""\""Microsoft Visual Studio""\""VB98". The Replace function works as it does in VB.Net; if this is a concern to you I'll leave you to work out the details of fixing up your App.Path value.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1