|
-
Mar 8th, 2007, 10:42 AM
#1
Thread Starter
Junior Member
shell problem
Hello,
I'm creating a little program that is uninstalling another program.
This is done by using the shell command like this:
shell ("c:\program files\myapp\uninst.exe")
Now, once the uninstaller finished (checked that using the process list), I have to delete the folder myapp which is in program files.
Therefor, I'm using fso.deletefolder ("c:\program files\myapp"), but I always receive a permission denied message.
When I try this command without running the shell command first, it works, so I figure that the shell command keeps blocking the directory. How can I prevent that?
Thanks.
-
Mar 8th, 2007, 11:18 AM
#2
Re: shell problem
Welcome to the forums. 
Is this the code you are using?
Code:
shell ("c:\program files\myapp\uninst.exe")
fso.deletefolder ("c:\program files\myapp")
-
Mar 8th, 2007, 11:26 AM
#3
Thread Starter
Junior Member
Re: shell problem
Thanks :-)
It's a little more complex ... Let me show ....
Code:
Shell "c:\program files\myapp\uninst.exe", vbNormalFocus
For Each process In GetObject("winmgmts:").execquery("Select Name from Win32_Process Where Name = 'uninst.exe' Or Name ='_iu14D2N.tmp'")
bfound = True
Next
While bfound
bfound = False
For Each process In GetObject("winmgmts:").execquery("Select Name from Win32_Process Where Name = 'uninst.exe' Or Name ='_iu14D2N.tmp'")
bfound = True
Next
Wend
If bfound = False Then
fso.DeleteFolder ("c:\Program Files\myapp")
End If
-
Mar 8th, 2007, 11:53 AM
#4
Re: shell problem
An uninstall should remove folders too unless there are custom user created files in it or an open process.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 8th, 2007, 12:16 PM
#5
Re: shell problem
It would depend on who made the uninstaller.
I'm thinking that the reason the error is occuring is because the uninstaller is still running when you are attempting to delete the folder.
As a test, make is two step process. Run your uninstaller, and then run the delete folder code from a button that you click after the uninstaller is done.
I'm almost willing to bet it will work.
-
Mar 8th, 2007, 12:20 PM
#6
Thread Starter
Junior Member
Re: shell problem
There are user created files in it, which are not deleted...
The goal is to perform a complete reinstall with auto backups of certain files.
Hack: I tried that already, and it does not solve the problem.
Example:
1) I open my program and run the uninstaller from button 1. The uninstaller has quit and I push button 2 to delete the folder: runtime error 70 access denied.
2) I open my program and run the uninstaller. I close my program.
I open my program again and push button 2: folder deleted.
How strange is that
-
Mar 8th, 2007, 12:22 PM
#7
Re: shell problem
Well it looks like the looping of processes is incorrect as that could be a reason why its trying to delete when its still running.
Looks like it will exit and bfound will always be True so it will bypass the delete line.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 8th, 2007, 12:24 PM
#8
Re: shell problem
 Originally Posted by KI2000
Hack: I tried that already, and it does not solve the problem.
Now you see why I'm not a betting man. 
 Originally Posted by KI2000
2) I open my program and run the uninstaller. I close my program.
I open my program again and push button 2: folder deleted.
What cleanup are you doing when you close the program? What is in the Unload event?
-
Mar 8th, 2007, 12:29 PM
#9
Re: shell problem
Perhaps it would be better to test against the execquery results being 1 or more. If so then its still running. If not then its not and the delete can take place.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 8th, 2007, 01:22 PM
#10
Thread Starter
Junior Member
Re: shell problem
RobDog888: bfound is not always true, it tries to delete the folder after the uninstaller quits, that's the moment I receive that damn runtime error 70 ...
Hack: There's nothing in the unload event of that program at the moment ...
Maybe you guys could try my code yourself? 
BTW: is there another way to call the uninstaller of the program (next to the shell command)
-
Mar 8th, 2007, 01:25 PM
#11
Re: shell problem
vb Code:
While bfound
bfound = False
For Each process In GetObject("winmgmts:").execquery("Select Name from Win32_Process Where Name = 'uninst.exe' Or Name ='_iu14D2N.tmp'")
bfound = True 'ON LAST ITERATION IT WILL STILL BE TRUE
Next
Wend
'THEN IT WILL BYPASS BECAUSE ITS TRUE AND NOT FALSE
If bfound = False Then
fso.DeleteFolder ("c:\Program Files\myapp")
End If
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 8th, 2007, 01:27 PM
#12
Thread Starter
Junior Member
Re: shell problem
RobDogg: Explain that to me ... I'm putting bfound = false in the loop. So when the process is no longer there, bfound should stay false ... Of course, that's only my opinion and I'm not an expert
-
Mar 8th, 2007, 01:37 PM
#13
Re: shell problem
No, my mistake I think. Been really sick this week. 
If bfound is really false then when it deletes the folder it should unless its a timming issue where the os has not completely released the resources linked in the folder for a few seconds after the process has exited.
Try placing a delay and see if that helps or if like already suggested, run just the delete part separately to test for functionality.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 8th, 2007, 01:45 PM
#14
Thread Starter
Junior Member
Re: shell problem
No problem RobDogg ... Hope you get well soon ...
I already tried with a delay of 10 seconds ... Still same problem.
What I was thinking: Isn't it possible that the shell command somehow locks the directory?
-
Mar 8th, 2007, 01:50 PM
#15
Re: shell problem
Try
Code:
fso.deletefolder ("c:\program files\myapp"), True
-
Mar 8th, 2007, 01:55 PM
#16
Thread Starter
Junior Member
Re: shell problem
tried it, same problem
-
Mar 8th, 2007, 01:56 PM
#17
Re: shell problem
Dont you have to have a empty folder before you can delete it.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 8th, 2007, 02:00 PM
#18
Thread Starter
Junior Member
Re: shell problem
It's not necessary with the fso.deletefolder command imho.
The kill command however won't work until the folder is empty. That's why I chose to use fso.deletefolder.
Is there any way I can kill the shell command myself? Something is definitely happening when I close my program, because afterwards deleting the folder is not a problem.
-
Mar 8th, 2007, 02:02 PM
#19
Re: shell problem
I have seen the VB IDE hold a reference to a access db before. Could be doing the same with a ref on the folder. Can you test this out by compiling and running outside the ide with the ide closed?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 8th, 2007, 02:02 PM
#20
Re: shell problem
 Originally Posted by KI2000
tried it, same problem 
It was a shot in the dark. 
Anyway,
 Originally Posted by KI2000
Hack: There's nothing in the unload event of that program at the moment ...
I asked that question because you said that if you run your uninstall, close the program, open it again, then your delete works.
Closing the program has an affect and I was hoping it was because of some clean up that you were doing that could be done without closing the program.
So, the question becomes what gets freed up when the program closes?
I put a text file in a folder, programmatically opened it by shelling notepad, closed it, and then deleted the file and the folder with no problem so I am not convinced Shell is blocking anything.
-
Mar 8th, 2007, 02:06 PM
#21
Thread Starter
Junior Member
Re: shell problem
Hope I got this right ... I compiled the program and saved it on another partition of my drive.
I closed down Visual Basic 6 and ran my program; the same happened: runtime error 70 ... I'm starting to lose it
-
Mar 8th, 2007, 02:08 PM
#22
Re: shell problem
Do you always run the uninstall from the same folder?
-
Mar 8th, 2007, 02:10 PM
#23
Re: shell problem
Hmm, ok then it has to be like Hack posted. Something in your program is still holding a resource ink to the folder preventing it from being deleted. Check in the taskmanager if your app is still running, test for a manual delete, and if either of the two fail then thats the area to research.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 8th, 2007, 02:12 PM
#24
Thread Starter
Junior Member
Re: shell problem
That's the default location of that file.
I'm going to try (just a test) to put the uninstaller in another folder ... I bet it will work then.
Just tested something else:
- I ran my vb app
- Got the error 70
- Tried to delete the myapp folder myself
- Didn't work, got a message telling me that another program is still using the folder
I'm pretty sure it's the shell command that's doing this weird trick ...
**** edit ****
Just tested it by running the uninst file from my c:\ root. Guess what? It worked ... But that doesn't solve the problem of course ... maybe a step closer to the solution ...
Last edited by KI2000; Mar 8th, 2007 at 02:15 PM.
-
Mar 8th, 2007, 02:14 PM
#25
Re: shell problem
The shell command wont hold the reference but if there is an error uninstalling it may. Manually run the uninstaller and see if you can manually delete the folder. If you cant then the error is in there.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 8th, 2007, 02:17 PM
#26
Thread Starter
Junior Member
Re: shell problem
RobDogg: Tried that too ... didn't have a problem deleting the folder after uninstalling manually.
BTW:
Addition to my previous comment ...
All I did was change the path in the shell command to c:\uninst.exe.
Then it worked ...
***edit***
tried again, now it didn't work ... argh!!
BTW, did I already tell that you guys are great?
Last edited by KI2000; Mar 8th, 2007 at 02:26 PM.
-
Mar 8th, 2007, 02:26 PM
#27
Re: shell problem
Is it that your original path has space(s) in it as Shell has issues with spaces in paths. You need to wrap the path with an extra set of double quotes.
Since it runs correctly and deletes properly manually then there is definately a reference holding a lock on the folder.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 8th, 2007, 02:35 PM
#28
Re: shell problem
Question: How does the folder get created in the first place if you delete it after running your install?
-
Mar 8th, 2007, 02:40 PM
#29
Thread Starter
Junior Member
Re: shell problem
Hack ... I lost you ...
I'm trying to uninstall a program after it has been installed.
So the folder is present when the application is installed, and even when the program is deleted using it's default uninstaller.
-
Mar 8th, 2007, 02:49 PM
#30
Thread Starter
Junior Member
Re: shell problem
I think I pinpointed the problem to this:
Code:
spath = "c:\program files\myapp\afolder\"
sfilename = Dir(spath & "*.dat")
Do While sfilename <> "" And sfilename <> "template.dat" And sfilename <> "initial.dat"
FileCopy spath & sfilename, "C:\Documents and Settings\David\Desktop\" & sfilename
sfilename = Dir
Loop
-
Mar 8th, 2007, 03:02 PM
#31
Re: shell problem
How? Is there an error or something? Is that part of the installation process?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 8th, 2007, 03:04 PM
#32
Thread Starter
Junior Member
Re: shell problem
uninstall process ... The vb program uninstalls another program but makes backups before uninstalling.
This is part of the backup process used in the vb application that is uninstalling another program ...
If I outcomment these lines, the myapp folder gets deleted, if I use these lines of code, I get error 70.
It seems to be to hard without the full code, so here it goes:
Code:
Dim fso As FileSystemObject
Private Sub cmdUninstall_Click()
On Error GoTo err_handler
Dim process As Object
Dim bfound As Boolean
Set fso = New FileSystemObject
bfound = False
'Text1.Text = "Uninstall started"
spath = "c:\program files\myapp\folder1"
sfilename = Dir(spath & "*.txt")
Do While sfilename <> "" And sfilename <> "generate.txt"
FileCopy spath & sfilename, "C:\Documents and Settings\David\Desktop\" & sfilename
sfilename = Dir
Loop
'Text1.Text = Text1.Text & vbCrLf & "Backup of userdata succeeded"
spath = "c:\program files\myapp\folder2"
sfilename = Dir(spath & "*.ewi")
Do While sfilename <> "" And sfilename <> "template.ewi" And sfilename <> "initial.ewi"
FileCopy spath & sfilename, "C:\Documents and Settings\David\Desktop\" & sfilename
sfilename = Dir
Loop
'Text1.Text = Text1.Text & vbCrLf & "Backup of security files succeeded"
'Text1.Text = Text1.Text & vbCrLf & "Starting uninstaller program"
Shell "c:\program files\myapp\unins000.exe", vbNormalFocus
'spath = ""
'sfilename = ""
For Each process In GetObject("winmgmts:").execquery("Select Name from Win32_Process Where Name = 'unins000.exe' Or Name ='_iu14D2N.tmp'")
bfound = True
Next
While bfound
bfound = False
For Each process In GetObject("winmgmts:").execquery("Select Name from Win32_Process Where Name = 'unins000.exe' Or Name ='_iu14D2N.tmp'")
bfound = True
Next
Wend
If bfound = False Then
Text1.Text = Text1.Text & vbCrLf & "Uninstaller terminated"
fso.DeleteFolder ("c:\Program Files\myapp"), True
Text1.Text = "folder deleted"
End If
err_handler:
Select Case Err.Number
Case 53: MsgBox "file not found"
Case 70: MsgBox "Permission denied"
End Select
End Sub
Last edited by KI2000; Mar 8th, 2007 at 03:09 PM.
-
Mar 9th, 2007, 11:22 AM
#33
Thread Starter
Junior Member
Re: shell problem
Still can't figure out what's wrong with my code ... anyone else who can help?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|