Shell command with .bat file

dgorka

Well-known member
Joined
Dec 27, 2006
Messages
88
Programming Experience
5-10
Hi,

I'm making an app that creates a .bat file when a button is pushed. I use Shell() to get the bat file to run. Now when I'm using this is testing on my local machine it works perfectly, however, when I tried using it in production today across the server, it created the .bat file but didn't run it. Any ideas why it wont work? I'm using VB.NET 2005

Thanks

'Shell out and run the batch file.
Shell(My.Settings.gstrDirectory & "\run.bat", AppWinStyle.MinimizedFocus, False, -1)
gstrDirectory is the directory where run.bat is located.
 
Can you execute 'run.bat' from the network location through Explorer? I've seen this prevented because of OS security settings.
 
Well, kind of fine. there are 3 lines of code in the batch file. The first one changes the directory to gstrDirectory so its working where the PDFs are. The second line is this: "dir *.pdf /b/on > contents.txt" so it should get a directory listing of all the PDFs and put them into contents.txt. The final line deletes the batch file so it can't be run again by the user.

Now when I ran it from explorer it ran, but it created the text file in the directory i had open in explorer(happened to be My Documents and I wanted my mapped Z: drive), but it didn't delete the .bat file afterwards. So now aside from not working from my code, it's not changing directories or deleting it (I think this is because it's not changing directories so it can't find the .bat file to delete). My batch file code is as follows:

cd Z:\Scan\Batch_01_PDFs
dir *.pdf /b/on > contents.txt
del run.bat
 
"cd" doesn't change drive, only path of given drive. Issue for example command "z:" to change to that drive.
Why aren't you creating that filelisting from VB.Net?
 
Back
Top