rkneal
asked on
process object locking up files
when i have the .createnowindow=True, whenever the copy command is done, it never releases the copied file. I try to delete d:\test.txt when done, and it says being used by another process.
when i put the createnowindow=False it does not do this, but i get a shell pop up window where can see copy going on.
Isn't there a property to keep the createnowindow=True, but hide the window itself?
Dim cmdFile As New Process
With cmdFile.StartInfo
.FileName = "cmd.exe"
.arguments ="/c copy c:\test.txt d:\test.txt"
.CreateNoWindow = True
.UseShellExecute = True
End With
cmdFile.Start()
cmdFile.WaitForExit(-1)
cmdFile.Dispose()
when i put the createnowindow=False it does not do this, but i get a shell pop up window where can see copy going on.
Isn't there a property to keep the createnowindow=True, but hide the window itself?
Dim cmdFile As New Process
With cmdFile.StartInfo
.FileName = "cmd.exe"
.arguments ="/c copy c:\test.txt d:\test.txt"
.CreateNoWindow = True
.UseShellExecute = True
End With
cmdFile.Start()
cmdFile.WaitForExit(-1)
cmdFile.Dispose()
ASKER
sorry, i should have said in last post, that we are really running a very detailed windows volume shadow copy, so the above filename is really a .bat file that gets run by the process command. It is copying about 1G of data over a network from a proprietary system. As stated above if i put the .createOnWindow=True it does not lock up the files, but i can see the window pop up.
Did you try calling the batch file only without cmd.exe it should work and do what you want
also use xcopy better.
Process.Start("xcopy", "c:\test.txt d:\test.txt")
also use xcopy better.
Process.Start("xcopy", "c:\test.txt d:\test.txt")
And try it with .createwindow = false it should be ok ...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
we can't use xcopy, it does not allow to copy open files.
if you look at the windows volume copy service, it allows you to copy open files so this is the mechanism we use to do this.
But, your answer above is allowing me to control the window state of the command window, so it works!
thanks
Bob
if you look at the windows volume copy service, it allows you to copy open files so this is the mechanism we use to do this.
But, your answer above is allowing me to control the window state of the command window, so it works!
thanks
Bob
Glad it helped :)
ASKER
followup comment, i had to still make the .useshellexecute = true to make this not lock up the files, :)
Dim cmdfile As New ProcessStartInfo
With cmdfile
.FileName = rFileStr
'.RedirectStandardOutput = True
.CreateNoWindow = True
.UseShellExecute = True
cmdfile.WindowStyle = ProcessWindowStyle.Hidden
End With
Process.Start(cmdfile)
Process.Start(cmdfile).Wai tForExit(1 000)
Process.Start(cmdfile).Dis pose()
Dim cmdfile As New ProcessStartInfo
With cmdfile
.FileName = rFileStr
'.RedirectStandardOutput = True
.CreateNoWindow = True
.UseShellExecute = True
cmdfile.WindowStyle = ProcessWindowStyle.Hidden
End With
Process.Start(cmdfile)
Process.Start(cmdfile).Wai
Process.Start(cmdfile).Dis
ASKER
thanks again!, at least not one can see the window popping up with your solution to control the processWindowStyle property.
These lines cause you to call the copy three times
Process.Start(cmdfile)
Process.Start(cmdfile).Wai tForExit(1 000)
Process.Start(cmdfile).Dis pose()
instead do this....
dim p as process = new process
p.start(cmdFile)
p.waitforexit(1000)
p.dispose
Process.Start(cmdfile)
Process.Start(cmdfile).Wai
Process.Start(cmdfile).Dis
instead do this....
dim p as process = new process
p.start(cmdFile)
p.waitforexit(1000)
p.dispose
you're welcome again .... :) but see the comment above ^^^
ASKER
i see! thanks
ASKER
just a last comment, i downloaded a free program called unlocker. This allowed me to see who was locking the files. Ends up being the vb.net app was not locking them, but McAfee antivirus!! This unlocker program allows you to see that, then tell it to unlock it. Pretty cool for free
Thanks for help.
Thanks for help.
System.IO.File.Copy("C:\te
Regards,
Wayne