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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

NEED URGENT HELP How to Set 'Start In:' Directory on icons in Listview!!

Hello,

I hope you understand my question so here it goes:

The following code is loading icons in a listview.
When i double click on an icon For Example a MS Word Icon, it starts the program.

My question is: How can i set the 'start in:' (Working directory) for each icon in the listview???
I've got some programs that needs to have their working directory beeing set to a specific path for example 'c:\workdir'.

Dim oLI     As ListItem
Dim nIcon   As Integer
Dim szLine  As String

Open szFile For Input As #1
nIcon = 1

Do Until EOF(1)
    Line Input #1, szLine
        If InStr(1, szLine, "=") > 0 Then
            ImageList1.ListImages.Add nIcon, , _
                LoadPicture(ServerName & "Icon\" & Split(Replace(Split(szLine, _
                "=")(1), Chr(34), ""), ",")(0))
            Set oLI = ListView1.ListItems.Add(, , Split(szLine, "=")(0), nIcon, _
                nIcon)
            oLI.Tag = Split(Replace(Split(szLine, "=")(1), Chr(34), ""), ",")(1)
            Set oLI = Nothing
            nIcon = nIcon + 1
        End If
    Loop
Close #1



Regards,

Paul
0
Sector10
Asked:
Sector10
  • 5
  • 2
  • 2
1 Solution
 
Ryan ChongCommented:
>>I've got some programs that needs to have their working directory beeing set to a specific path for example 'c:\workdir'.
You can save the specified path of 'c:\workdir' into registry, ini file, database etc, so that you can retrieve that value when necessary not only within your application but also for other applications.

Hope this make sense to you, ask if you need further helps, regards
0
 
Sector10Author Commented:
Hello Ryan!

The programs that are shown on the listview are pulled from an ini file like this:

[ICON]
MS Word=Word.jpg,C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE
MS Excel=Excel.jpg,C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE

As you can see from the code above this line is split:

MS Word                                                                            -  This text is desplayed under the Icon
Word.jpg                                                                            -  Is the actual icon to be displayed
C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE   - Is the program to start

So how can i bind different startup dir's to each icon?

Regards,

Paul
0
 
Sector10Author Commented:
JimBobMcGee has help me out A LOT but this is one thing i am still strugglin with.

Take a look at the following link for the history on this issue:

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21289260.html

Regards,


Paul
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Ryan ChongCommented:
It's hard to determine the location of a program installed. Yet the urls below may give you some useful info on how to determine the installed path (working path?):

Determining the Name of the Executable Associated with a Specific File
http://vbnet.mvps.org/index.html?code/system/findexecutable.htm

Windows Uninstaller
http://www.freevbcode.com/ShowCode.Asp?ID=4742
0
 
ArkCommented:
Just add working directories to your ini file, then add it to oLI.Tag, separated with some non-printable character (Chr(0), for example), like:
   oLI.Tag = Split(Replace(Split(szLine, "=")(1), Chr(34), ""), ",")(1) & Chr(0) & strWorkingDir(i)

Then, at Dbl_Click event, split tag into 2 parts:
s=Split(Listview1.SelectedItem.Tag,Chr(0))
0
 
Sector10Author Commented:
Hello Ark!

This is the current Dbl_Click event:

Private Sub ListView1_DblClick()
Dim RetVal

Me.WindowState = vbMinimized
RetVal = Shell(ListView1.SelectedItem.Tag, 1)

End Sub

How must i implement: s=Split(Listview1.SelectedItem.Tag,Chr(0))

Regards,

Paul
0
 
ArkCommented:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

s=Split(Listview1.SelectedItem.Tag,Chr(0))
RetVal = ShellExecute(hwnd,"open",s(0),vbNullString,s(1),1)
0
 
Sector10Author Commented:
Hello Ark!

Let me thank you all for your time and effort on this one, you all have been such great help to me!

So i am almost there, if i hardcode the working dir al works fine so the line reads:
oLI.Tag = Split(Replace(Split(szLine, "=")(1), Chr(34), ""), ",")(1) & Chr(0) & "c:\Temp"

Now this is my ini file:
[ICON]
MS Word=Word.jpg,C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE
MS Excel=Excel.jpg,C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE

I added a working dir for example:
[ICON]
MS Word=Word.jpg,C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE,C:\Word
MS Excel=Excel.jpg,C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE,C:\Excel

How can i read this line using your piece of code, i asume that i have to alter the split?
oLI.Tag = Split(Replace(Split(szLine, "=")(1), Chr(34), ""), ",")(1) & Chr(0) & strWorkingDir(i)

Regards,

Paul

0
 
Sector10Author Commented:
Solved it Ark!

I used a different split character "|" to seperate the working dir from the application. I also could have used Chr(0) offcourse ;o)
Now i know why you told me to use chr(0) .....

Thank you all once again, without you guys i was still struglin with this one!


Regards,

Paul
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now