Results 1 to 5 of 5

Thread: How to use directory names with spaces with shell?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    How to use directory names with spaces with shell?

    I'm trying to use a directory with shell that has spaces in it.

    I tried setting the directory path to a string but that didn't help. To use quotes in the Windows Command Line I heard you have to use \ (as it's already inside quotes).

    Using "shell cmd blahblah\\"blah blah\"" won't work.

    Any help or ideas would be greatly appreciated. Also if I'm not making sense please just say

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: How to use directory names with spaces with shell?

    vb Code:
    1. Shell "explorer ""C:\Test Folder\"""
    edit: i.e. replace " with ""

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: How to use directory names with spaces with shell?

    /that gives me a syntax error. This is currently what I'm trying:

    Code:
    Shell ("cmd.exe /k "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\""Session Manager"" /v blahblah /t REG_MULTI_SZ /d " + meh + file), vbNormalFocus

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: How to use directory names with spaces with shell?

    Shell ("cmd.exe /k ""HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager"" /v blahblah /t REG_MULTI_SZ /d " + meh + file), vbNormalFocus
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to use directory names with spaces with shell?

    Try using ShellExecute instead as its more powerful and doesnt have th space issue.
    vb Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    4.                     ByVal hwnd As Long, _
    5.                     ByVal lpOperation As String, _
    6.                     ByVal lpFile As String, _
    7.                     ByVal lpParameters As String, _
    8.                     ByVal lpDirectory As String, _
    9.                     ByVal nShowCmd As Long) As Long
    10.  
    11. Private Const SW_HIDE As Long = 0
    12. Private Const SW_SHOWNORMAL As Long = 1
    13. Private Const SW_SHOWMAXIMIZED As Long = 3
    14. Private Const SW_SHOWMINIMIZED As Long = 2
    15.  
    16. Private Sub Command1_Click()
    17.     ShellExecute Me.hwnd, "Open", "cmd.exe", "/k HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager /v blahblah /t REG_MULTI_SZ /d " + meh + file, "C:\", SW_SHOWNORMAL
    18. End Sub
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width