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:
Shell "C:\Program Files\mgamerz\my_mp3s\Update.bat", vbNormalFocus
cheers Rob
Re: bit more help please Access Denied??
Your XML file might have been be set as Read Only so check properties first.
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
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?
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"
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
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 :wave:
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
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
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
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:
Declare Sub Sleep Lib "kernel32.dll" ( _
ByVal dwMilliseconds As Long)
goes at the top under Option Expicit
VB Code:
Private Sub writexml()
Dim f1 As Integer, songpath As String, mp3path As String, f2 As Integer, i As Integer
mp3path = "C:\Documents and Settings\User1\My Documents\My Music\MP3\The Greatest Oldies (vol 1)\"
f2 = FreeFile
Open mp3path & "mp3.txt" For Output As #f2 ' if you don't need mp3.txt take out
f1 = FreeFile
Open mp3path & "audiolist.xml" For Output As #f1
Print #f1, "<?xml version=""1.0""?>"
Print #f1, "<songs>"
songname = Dir(mp3path & "\*.mp3") ' get first track
i = 1
While Not Len(songname) = 0
songpath = "<song path=""" & mp3path & songname & """ title=""" & songname & """/> "
Print #f1, songpath
Print #f2, songname ' for mp3.txt
Sleep 100 ' slight pause, needed
songname = Dir ' get next track
Wend
Print #f1, "</songs>"
Close
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.
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
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.
Re: bit more help please Access Denied??
VB Code:
Option Explicit
Declare Sub Sleep Lib "kernel32.dll" ( _
ByVal dwMilliseconds As Long)
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
Re: bit more help please Access Denied??
sorry change it to
VB Code:
Private Declare Sub Sleep Lib "kernel32.dll" ( _
ByVal dwMilliseconds As Long)
i had it in a module
p.
1 Attachment(s)
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
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.
1 Attachment(s)
Re: bit more help please Access Denied??
sorry here it is I appreciate this a lot.
Thanks
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.
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
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:
xmlpath = "C:\Program Files\mgamerz\"
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:
Filecopy mp3path & "audiolist.xml" "C:\Program Files\mgamerz\audiolist.xml"
p.
Re: bit more help please Access Denied??
I want to keep the original so do I just add
VB Code:
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