Click here to Skip to main content
15,896,730 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Firends,

Here is the command

takeown /F "path of file"

when I use it in cmd prompt which is running as administrators, this command works fine and takes the ownership of requested file.

But when I use same command from vb.net, it does not work here is my vb.net code.

VB
Dim ss As ProcessStartInfo = New ProcessStartInfo()

                   ss.UseShellExecute = True
                   ss.WorkingDirectory = "C:\Windows\System32"
                   ss.Verb = "runas"
                   Process.Start("C:\Windows\System32\cmd.exe", "/k takeown /F """ & filepath.Text & """")


cmd shows that command is processed successfully and ownership has been taken out. But when I check in the properties of requested file, it shows that it has the previous owner and no new changes to new owner.
Posted
Comments
Bernhard Hiller 6-Jun-14 8:48am    
Vista/Win7,8 with UAC enabled? Do you run your application "elevated"?

1 solution

try below
VB
Dim ss As ProcessStartInfo = New ProcessStartInfo()
ss.UseShellExecute = True
ss.Arguments = "/k takeown /F """ & filepath.Text & """"
ss.FileName = "c:\windows\system32\cmd.exe"
ss.WorkingDirectory = ""
ss.Verb = "runas"
Process.Start(ss)
 
Share this answer
 
Comments
zubair30 6-Jun-14 4:20am    
didn't work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900