Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Spaces not recognized during setup installation

Posted on 2004-12-01
Medium Priority
Last Modified: 2010-04-23

i have a problem while installing my setup . My default installation path is c:\program files\

There is space in between 'Program files' , my process stops. but it works fine when i install my setup in another spaceless location like c:\sample\
My project involves one sample.sta file. i have kept sample.sta in the project bin folder and i refer the file using Application.startuppath

very urgent

pls help
thanx in advance
Question by:lword
LVL 24

Expert Comment

by:Jeff Certain
ID: 12715281
Have you tried using the old DOS-Compatible folder name (C:\Progra~1) ?
LVL 48

Expert Comment

ID: 12716651
Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long
Public Function GetShortPath(strFileName As String) As String
    'KPD-Team 1999
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    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
Private Sub Form_Load()
    MsgBox GetShortPath("c:\Program Files\")
End Sub

Expert Comment

ID: 12719099
Are you using a setup project in Visual Studio?  If you are, you can designate the Program Files directory using the System Folder Property [ProgramFilesFolder].  You would then add the subdirectory name after this, also using a System Folder Property if desired.  

From what you had written, I don't think you're using a setup project to deploy your app, but rather, a reference of some sort to your file (a shortcut?).  Perhaps you can try using double quotes (" ") around the path, as this may help.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 12723463
It works with DOS-Compatible folder name (C:\Progra~1)

how do i check for spaces in the folder name of Application.Startuppath string and replace the same with DOS-Compatible names

For example my Application.Startuppath looks likes this

Application.Startuppath = "C:\Program Files\Local1 settings\sample.txt

Then  i need the replced string as

Application.Startuppath = " "C:\Progra~!\Local1~1\sample.txt

pls help


LVL 24

Expert Comment

by:Jeff Certain
ID: 12725269
Mikal613's code (see above) has an API call which retrieves the short file name for you....

Author Comment

ID: 12733674

In the Mikal613's code I didn't understand the following lines of code

    strPath = String$(165, 0)
    lngRes = GetShortPathName(strFileName, strPath, 164)
    GetShortPath = Left$(strPath, lngRes)

1) Is String$ and Left$ function works with vb.net ? I tried , doesn't work in vb.net?
2) I'm confused why he used 165 and 164 and what is the purpose of using it

LVL 24

Accepted Solution

Jeff Certain earned 2000 total points
ID: 12736245
Replace String$(165,0) etc with

strPath = new string("0",165) ' Create a 165-character buffer
lngRes = GetShortPathName(strFileName, strPath, 164) ' Retrieve up to 164 characters from the short path name
return strPath.Substring(0, lngRes) ' Trim excess characters from the buffer and return the result

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question