CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2001
    Posts
    165

    Windows Scripting Host 8.3 File format?

    I am using the Windows Scripting Host to execute a VBScript file that my program makes at run-time.

    I am having a problem in that the WScript program will hang if I attempt to use a path that does not conform to the old 8.3 file format.

    The following Does NOT Work:
    Dim wshShell, sScript as string
    set wshShell = CreateObject("WScript.Shell")
    sScript = "wscript C:\Program Files\Project1\tmp001.vbs"
    wshShell.Run sScript, 0, true


    The following Does work:
    Dim wshShell, sScript as string
    set wshShell = CreateObject("WScript.Shell")
    sScript = "wscript C:\Progra~1\Project1\tmp001.vbs"
    wshShell.Run sScript, 0, true


    Is there another way I can do this? Is there a function or api call to retrieve a file path in the 8.3 format?

    This is the correct path my program uses but I will not hardcode it as such I will be using app.path to validate the location so I will need a way to retrieve this path with a 8.3 format.

    -K


  2. #2
    Join Date
    Jan 2001
    Posts
    165

    Re: Windows Scripting Host 8.3 File format?

    Still not sure why I must use 8.3 file format when running wscript in this manner but here is a method to retrieve the short path name.

    private Declare Function GetShortPathName Lib "kernel32" Alias _
    "GetShortPathNameA" (byval lpszLongPath as string, _
    byval lpszShortPath as string, byval cchBuffer as Long) as Long

    private Sub Command1_Click()
    Dim sShortPath as string*255
    Dim lBufLen as long
    dim sLongPath as string

    sLongPath = app.path 'In this case app.path = C:\Program Files\Project1

    lBufLen = 254
    lBufLen = GetShortPathName(sLongPath,sShortPath,lBufLen)

    MsgBox "Long Path: " & sLongPath & vbNewLine & _
    "Short Path: " & left(sShortPath,lBufLen)
    End Sub


    -K



  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Windows Scripting Host 8.3 File format?

    Good solution.
    Have I ever told you you 're smart?
    :-)
    Best regards,
    Cesare Imperiali

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  4. #4
    Join Date
    May 2001
    Posts
    3

    Re: Windows Scripting Host 8.3 File format?

    Sure your first solution won't work, as there is a blank in the path to the file to work with. So wscript tries to execute the file "C:\Program" with additional commandlineparameter "Files\Project1\tmp001.vbs". To solve this problem just wrap long filenames in quotes (i.e. "). E.g:
    sScript = "wscript " & chr$(34) & "C:\Program Files\Project1\tmp001.vbs" & Chr$(34).


    This should solve your problem.


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

Featured