0

I'm facing a strange problem with starting a file in Visual Basic 6. The point is that when I run the code in Visual Basic 6 without compiling it, the code runs without any problems. But when I compile and run, I get an error.

Link Work!

It doesn't work

I know the problem comes from this part of the code.

Dim RetVal



RetVal = Shell("C:\Windows \System32\ComputerDefaults.exe", 1)

And more precisely Windows \ If you notice there's space between Windows and slash, but this is intentional. It is this part that creates problems

Is there any chance, the file to be executed in this way, with space between Windows and slash?

user692942
  • 15,667
  • 7
  • 74
  • 164
  • 5
    Try `RetVal = Shell("""C:\Windows \System32\ComputerDefaults.exe""", 1)` – Tim Williams May 05 '22 at 17:49
  • 1
    As @TimWilliams points out paths with spaces require encapsulation with double quotes but double quotes in Visual Basic denote the start and end of a string which means literal double quotes in a string need to be escaped. You do this by doubling the literal quotes as in the example in the [comment above](https://stackoverflow.com/questions/72131477/weird-problem-with-running-file-in-visual-basic-6#comment127448814_72131477). – user692942 May 05 '22 at 20:13
  • Is the VB6 IDE running with administrator permissions? If so, your compiled app may not be, which is one possible reason for a difference. – StayOnTarget May 05 '22 at 20:50
  • BTW you should post your entire (relevant) code in the question, not just this small portion. – StayOnTarget May 05 '22 at 20:51
  • 2
    Thanks to everyone for the answers, I found that the error disappears when I run the file as an administrator. Тhat's why I started Visual basic 6 as an administrator, thinking that the problem would disappear after I compiled the file, unfortunately the problem remained. – NewUser May 06 '22 at 10:05

0 Answers0