Results 1 to 22 of 22

Thread: bit more help please Access Denied?? "FINALLY RESOLVED" THANKS ALL!!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Resolved bit more help please Access Denied?? "FINALLY RESOLVED" THANKS ALL!!

    Hi I've been working on a small app that updates xml playlist through a batch file. I've been struggling to understand why it wont run from vb. I used this code tonight and in the dos output I got the message Access Denied - any suggestions/explanations???

    VB Code:
    1. Shell "C:\Program Files\mgamerz\my_mp3s\Update.bat", vbNormalFocus

    cheers Rob
    Last edited by robvr6; Jan 15th, 2005 at 11:11 AM. Reason: resolved

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: bit more help please Access Denied??

    Your XML file might have been be set as Read Only so check properties first.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: bit more help please Access Denied??

    I already checked that and if I run the batch not from vb it works fine - Just when I thought I was gettin somewhere lol

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: bit more help please Access Denied??

    post what's in your batch file. is there a file open in VB that you are writing to?

  5. #5
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: bit more help please Access Denied??

    do this:
    Code:
    Public 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
    
    Public Sub RunProgram(strProgram As String)
        Dim lRet As Long
        lRet = ShellExecute(vbNull, "", strProgram, "", "", SW_SHOWNORMAL)
    End Sub
    in a module

    and in your form put:
    Code:
    RunProgram "C:\Program Files\mgamerz\my_mp3s\Update.bat"

  6. #6
    Fanatic Member Armbruster's Avatar
    Join Date
    Sep 2002
    Location
    Maryland Heights, MO
    Posts
    857

    Re: bit more help please Access Denied??

    I have a feeling this is a "Start in" problem . . .

    |2eM!x (that is a wierd forum name), had the right idea, but he (or she) still left the lpDirectory parameter blank, so I suspect it would fail.

    Put a pause in your batch file, then run it by itself. The pause will cause the cmd window to display. Look in the window at the path.

    Now run your vb app. (Make sure you leave the pause in the batch file). Look in the cmd window this time. Notice the path? This time the path was the application path, not the batch files path.

    Windows 2000 and XP, by default, start batch files in directory they were run from, not the directory they are located in. When you double-click on the batch file you are starting the batch file in the directory it is located in. When you shell out to the batch file from your vb app, you are starting the batch file in your application path.

    That having been said, shell is very, very ugly at best. I would (and alway do) use the shellexecute api. Just be sure to specify the lpDirectory parameter so the batch file starts in that directory
    "Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!

    Resistance is futile, you will be compiled . . . Please!

  7. #7
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: bit more help please Access Denied??

    can you explain the lpDirectory to me? would it be like ipdirectory = (dir) or what?

    thanks

    oh and its remix

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: bit more help please Access Denied??

    could you explain how I would add that please? Any chance of a bit of an example thanks Rob

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: bit more help please Access Denied??

    Hi I have tried adding the module and changing the code on my command button but nothing happens. I add a pause in my batch file but cannot see the path. The most confusing aspect of this is that the batch file works perfectly when ran by itself.


    thanks

    Rob

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: bit more help please Access Denied??

    In Reply to dglienna here is my batch file

    @echo off
    pause
    SET filein=mp3.txt
    SET fileout=audiolist.xml
    SET filedir="%my_mp3s%"

    if NOT %filedir%=="" goto continue

    cd > %filein%

    for /f "tokens=*" %%i in ( %filein% ) do (
    SET filedir="%%i"
    )

    :continue

    dir %filedir%\*.mp3 /b > %filein%

    echo ^<?xml version="1.0"?^> > %fileout%
    echo ^<songs^> >> %fileout%

    for /f "tokens=*" %%i in ( %filein% ) do (
    echo ^<song path=%filedir\%"my_mp3s/%%i" title="%%i"/^> >> %fileout%
    )

    echo ^</songs^> >> %fileout%




    call c:

    cd PROGRA~1

    cd mgamerz

    cd my_mp3s

    copy audiolist.xml c:\PROGRA~1\mgamerz


    echo file: audiolist.xml is ready


    as Ive said this works fine when just double clicked but as soon as I call it from VB It aint having it

    ROb

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: bit more help please Access Denied??

    Rob,


    here is the code for you to create both the mp3.txt if you need it and audiolist.xml from within vb, no batch file required, the way it is set up at the moment it creates both file in the folder where the mp3s are located, but his is esay to change if you keep you audiolist elsewhere

    VB Code:
    1. Declare Sub Sleep Lib "kernel32.dll" ( _
    2.      ByVal dwMilliseconds As Long)
    goes at the top under Option Expicit

    VB Code:
    1. Private Sub writexml()
    2.  
    3.     Dim f1 As Integer, songpath As String, mp3path As String, f2 As Integer, i As Integer
    4.    
    5.    
    6.     mp3path = "C:\Documents and Settings\User1\My Documents\My Music\MP3\The Greatest Oldies (vol 1)\"
    7.    
    8.      f2 = FreeFile
    9.     Open mp3path & "mp3.txt" For Output As #f2       ' if you don't need mp3.txt take out
    10.      f1 = FreeFile
    11.      
    12.     Open mp3path & "audiolist.xml" For Output As #f1
    13.     Print #f1, "<?xml version=""1.0""?>"
    14.     Print #f1, "<songs>"
    15.     songname = Dir(mp3path & "\*.mp3")   ' get first track
    16.     i = 1
    17.     While Not Len(songname) = 0
    18.         songpath = "<song path=""" & mp3path & songname & """ title=""" & songname & """/> "
    19.         Print #f1, songpath
    20.         Print #f2, songname                  ' for mp3.txt
    21.         Sleep 100                                ' slight pause, needed
    22.         songname = Dir                         ' get next track
    23.    
    24.     Wend
    25.     Print #f1, "</songs>"
    26.  
    27.  
    28. Close
    29. End Sub
    you can put this code into a button click or cal it from a button click

    hope this helps to you to progress in VB

    rgds p.
    Last edited by westconn1; Jan 15th, 2005 at 08:45 AM.

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: bit more help please Access Denied??

    thanks but would this automatically add the mp3 files to the xml doc when they have been copied into the my_mp3 folder or will it have to be manually updated by users. The reason I was using the batch was it made it simple for users to add their own tracks without having to manually edit the xml doc therselves.

    eg user browses for a file and that is added to the my_mp3s folder and then ran the batch file and it was ready for playing

    Thanks again for your time
    Rob

  13. #13
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: bit more help please Access Denied??

    this code creates 2 files in the folder where mp3s are located,at present it is a folder on my hard drive, so you will need to change that. or select it from a common dialog setting mp3path to that.

    i didn't know if you needed mp3.txt or if it was just part of your process, it is not required for this code

    this code does not copy any files, it just creates the files with contents as your batch file did.

    if you wanted to copy files you would do that first, then run this code with the path set to where you have copied them to.

    if you just copy this into a new project and put a cmdbutton on the form you can test it quite easily

    p.

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: bit more help please Access Denied??

    VB Code:
    1. Option Explicit
    2. Declare Sub Sleep Lib "kernel32.dll" ( _
    3.      ByVal dwMilliseconds As Long)
    4.      
    5. Private Const FAVORITES_FOLDER = "C:\PROGRAM FILES\MGAMERZ\MY_MP3S\"

    I have this in my general declarations but I receive this error -
    compile error:
    constants,Fixed-length strings,arrays,user-defined types and Declare statements not allowed as public members of object modules.

    Any ideas what I've done wrong
    cheers
    Rob

  15. #15
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: bit more help please Access Denied??

    sorry change it to
    VB Code:
    1. Private Declare Sub Sleep Lib "kernel32.dll" ( _
    2.      ByVal dwMilliseconds As Long)

    i had it in a module
    p.

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: bit more help please Access Denied??

    I keep getting errors when trying to update the xml. when I click on the update xml button I get this

    Compile error.

    Varialble not defined.

    I have attached my file to see if you can see any blatant errors that I've missed.

    Thanks
    Rob
    Attached Files Attached Files

  17. #17
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: bit more help please Access Denied??

    sorry can't open your file, but the message is specific, one of the variables needs to be dimmed, i just checked my code, all the variable in it were declared,
    did you add any??

    if you want me to check your file attach it in a zip
    p.

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: bit more help please Access Denied??

    sorry here it is I appreciate this a lot.

    Thanks
    Attached Files Attached Files

  19. #19
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: bit more help please Access Denied??

    ok it is the variable songname in command2 so just add that to the list
    songname as string.

    also you have End Sub twice for command 2

    p.

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: bit more help please Access Denied??

    In a word Brilliant Brilliant Brilliant. Your an absolute diamond. Thans Very much.

    Just a small query now. Would I be able to copy a copy of the xml back to the folder C:\Program Files\mgamerz after it has updated because the flash player needs it to be there to play the files. (As is I've not asked enough) lol

    Thanks agoin
    Rob

  21. #21
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: bit more help please Access Denied??

    all you have to do is change the path to where the file is opened
    mp3path,
    you can add a new variable xmlpath and set it to

    VB Code:
    1. xmlpath = "C:\Program Files\mgamerz\"
    2. Open xmlpath & "audiolist.xml" For Output As #f1

    if you want to keep the original in the mp3 folder

    you can leave the original code
    and add
    VB Code:
    1. Filecopy  mp3path & "audiolist.xml"  "C:\Program Files\mgamerz\audiolist.xml"

    p.

  22. #22

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: bit more help please Access Denied??

    I want to keep the original so do I just add
    VB Code:
    1. Filecopy  mp3path & "audiolist.xml"  "C:\Program Files\mgamerz\audiolist.xml

    to the end of the code that you sent me? nearly there now
    Thanks Rob

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